Как использовать Tensorflow Serving restful API на модели оценщика с множественными именами входов? - PullRequest
0 голосов
/ 30 октября 2019

Версия Tensorflow : 1.14.0

Версия обслуживания Tensorflow : 1.14.0


Описание

Сохраненная модель оценки имеет несколько именованных входов, чьи ключи input_1, input_2 ... И эти входы - tf.feature_column. *, Я сохранил модель обслуживания, используя коды ниже, где feature_columns - список входов:

estimator.train(input_fn=lambda: train_input_fn(features, 1000), steps=100)
serving_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(
        tf.feature_column.make_parse_example_spec(feature_columns))
estimator.export_saved_model("from_estimator/", serving_input_fn)

После сохранения модели я использую saved_model_cli показывать входы и выходы этой модели:

saved_model_cli show --dir /from_estimator/1572335377/ --tag_set serve --signature_def serving_default

, которые печать :

The given SavedModel SignatureDef contains the following input(s):
  inputs['examples'] tensor_info:
      dtype: DT_STRING
      shape: (-1)
      name: input_example_tensor:0
The given SavedModel SignatureDef contains the following output(s):
  outputs['logits'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1, 100)
      name: MatMul_1:0
  outputs['probabilities'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1, 100)
      name: Softmax:0
Method name is: tensorflow/serving/predict

Обратите внимание , что входные данные - это не ожидаемые ключи input_1 и input_2, а examples. Запутавшись в этом !!

Как бы то ни было, я с помощью saved_model_cli запускаю модель локально:

saved_model_cli run --dir from_estimator/1572335377/ --tag_set serve --signature_def serving_default --input_examples "examples=[{'input_1': [1],'input_2': [1]}]"

И это дает правильные результаты.

Вопрос

Я развернул модель, используя образ докера обслуживания tenorflow, и попытался получить выходные данные из restful api. Я попробовал следующий формат запроса, но все они не сработали:

  1. curl -d '{"instances": [{"input_1": [1],"input_2": [1]}]}' -X POST http://localhost:8501/v1/models/from_estimator:predict, он выдал ошибку wrong key of input.
  2. curl -d '{"instances": [{"examples": {"input_1": [1],"input_2": [1]}}]}' -X POST http://localhost:8501/v1/models/from_estimator:predict, выдал Invalid argument: JSON Value: not formatted correctly for base64 data ошибка.
  3. curl -d '{"instances": [{"examples": "{\"input_1\": [1],\"input_2\": [1]}"}]}' -X POST http://localhost:8501/v1/models/from_estimator:predict, это дало couldn't parse ошибка.

Так как правильно настроить несколько именованных входов? спасибо ~

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...