python - TensorFlow:如何为 SavedModel 格式化 JSON,期望字符串格式为 3 个整数?
问题描述
我无法使用 Postman 将正确的预测 POST 请求发送到在 Docker 容器中使用 TensorFlow Serving 远距离运行的模型。
该模型响应 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]"]
}
推荐阅读
- ruby - 映射本身就是哈希值的哈希?
- python - 如何优化这个程序?(我有点初学者)
- ios - 如何在溢出屏幕的 SwiftUI 中制作无限宽度的视图?
- python - 尝试使用 django 运行服务器时如何修复错误?
- flutter - Dio 4.0.0 (Dart) 中奇怪的 BaseOptions 问题
- python - 获取属于特定类的数据子集
- java - 从动态字符串中获取运算符之前的子字符串
- python - 为什么 discord 不返回 COVID19 结果数据?
- amazon-web-services - 创建 AWS 弹性 Beanstalk Spring 实例并将其分配给 VPC
- hibernate - reddison hibernate 作为二级缓存的问题