gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 07:35:28 25 4
gpt4 key购买 nike

我在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com