Проблема с обслуживанием тензорного потока: Тензор: 0, указанный в feed_devices или fetch_devices, не был найден в Графике - PullRequest
0 голосов
/ 06 апреля 2020

У меня проблема с использованием тензорного потока, обслуживающего SparseTensor входами.

Я использую:

  • Tensorflow 2.1.0
  • последний тензор потока-обслуживания docker image

У меня есть следующий код для экспорта модели для обслуживания:

def serving_input_fn():
    """Input function for serving"""
    def _sparse_to_dense_features_tensor(feature_indices, features_values):
        indices = feature_indices.indices
        indices = tf.transpose(indices)
        indices = tf.stack([indices[0], feature_indices.values])
        indices = tf.transpose(indices)
        return tf.sparse.to_dense(tf.SparseTensor(indices=indices, values=features_values.values,
                               dense_shape=np.array([1, 2112])))

    feature_spec = {'features_indices' : tf.io.VarLenFeature(tf.int64),
                        'features_values' : tf.io.VarLenFeature(tf.float32)
                   }

    raw_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)
    raw_reatures = raw_input_fn().features
    feature_tensor = _sparse_to_dense_features_tensor(raw_reatures['features_indices'], raw_reatures['features_values'])
    return tf.estimator.export.ServingInputReceiver(feature_tensor, raw_reatures)

exported_model_dir = 'exported_model'

classifier.export_saved_model(exported_model_dir, serving_input_fn)

Когда я пытаюсь предсказать использование REST API, как показано ниже:

curl -d "{\"inputs\":{\"features_values\": [10.0, 12.0], \"features_indices\": [3, 4]}}" \
  -X POST http://localhost:8501/v1/models/my_model:predict

Я получаю эту проблему:

{ "error": "Tensor :0, specified in either feed_devices or fetch_devices was not found in the Graph" }

Я нашел здесь некоторые идеи: https://github.com/tensorflow/serving/issues/1100

Эта проблема, кажется, исходит от тот факт, что there is no name assigned to the SparseTensor, но нет четкого ответа для решения этой проблемы ...

Я не знаю, если я допустил ошибку, я был бы рад, если у кого-то есть решение!

Спасибо,

Максим

...