python - TensorFlow:如何为 SavedModel 格式化 JSON,期望字符串格式的 3 个整数?

标签 python tensorflow tensorflow-serving tensorflow-estimator

我在使用 Postman 向在 Docker 容器中使用 TensorFlow Serving 远距离运行的模型发送正确的预测 POST 请求时遇到问题。

模型响应 GET 请求,因此我知道它可以工作并且正在响应。该算法需要将 3 个 int ID 值作为类别进行处理才能发挥作用,但 SignatureDef 需要输入一个字符串,如下所示:

The given SavedModel SignatureDef contains the following input(s):
  inputs['inputs'] tensor_info:
      dtype: DT_STRING
      shape: (-1)
      name: input_example_tensor:0
The given SavedModel SignatureDef contains the following output(s):
  outputs['classes'] tensor_info:
      dtype: DT_STRING
      shape: (-1, 2166)
      name: linear/head/Tile:0
  outputs['scores'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1, 2166)
      name: linear/head/predictions/probabilities:0
Method name is: tensorflow/serving/classify

我尝试遵循 RESTful API 教程中显示的 JSON 格式:https://www.tensorflow.org/tfx/serving/api_rest#example 但是除了错误响应之外,无法得到任何东西给我发回任何东西,这些错误响应对我了解正确的语法没有太大帮助。无论如何,它都需要是这样的:

{
 "inputs": ['int1': 1, 'int2': 2, 'int3': 3]
}

我希望它能给我发回教程中所示的内容:

    "predictions": [3.5, 4.0, 5.5]

相反,我得到了“错误”:无论它不喜欢我这次发送的内容。任何帮助将不胜感激

最佳答案

在咨询了其他几个人后,我们设法找到了解决方案。它需要一个字符串列表,每个字符串包含相关的字典项,在标签需要时转义引号。

{
    "instances": 
        ["\"int1\": [1] , \"int2\" : [2], \"int3\":[3]"]

}

关于python - TensorFlow:如何为 SavedModel 格式化 JSON,期望字符串格式的 3 个整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57010053/

相关文章:

python - PCA的主要成分

python - Mongodb 引擎和 Django 创建自定义 ObjectId

python - 如何使用python的seaborn绘制CDF?

python - 恢复使用 tf.estimator 训练的模型并通过 feed_dict 提供输入

python - Tensorflow 与 contrib 操作一起服务

python - 记录由 tensorflow 服务模型服务的请求

python - 为什么范围对象是 "not an iterator"?

machine-learning - Tensorflow 训练和验证输入队列分离

tensorflow - 使用 TensorFlow 函数,如何将小于 0.05 的值设置为零?

tensorflow - 将tensorflow模型转换为pb tensorflow