首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TensorFlow Serving REST API - JSON解析错误

TensorFlow Serving REST API - JSON解析错误
EN

Stack Overflow用户
提问于 2020-01-03 14:41:44
回答 1查看 1.6K关注 0票数 0

我冻结并导出了一个SavedModel,它接受一批符合saved_model_cli格式的视频作为输入:

代码语言:javascript
复制
The given SavedModel SignatureDef contains the following input(s):
inputs['ims_ph'] tensor_info:
    dtype: DT_UINT8
    shape: (1, 248, 224, 224, 3)
    name: Placeholder:0
inputs['samples_ph'] tensor_info:
    dtype: DT_FLOAT
    shape: (1, 173774, 2)
    name: Placeholder_1:0
The given SavedModel SignatureDef contains the following output(s):
... << OUTPUTS >> ......
Method name is: tensorflow/serving/predict

我有一个TF服务(HTTP/REST)服务器在本地成功运行。在我的Python客户机代码中,我有两个填充的numpy.ndarray类型的对象,名为ims of shape (1,248,224,224,3)和samples of shape (1,173774,2)。

我正在尝试对TF模型服务器运行推理(请参阅下面的客户端代码),但收到以下错误:{u'error': u'JSON Parse error: Invalid value. at offset: 0'}

代码语言:javascript
复制
# I have tried the following combinations without success:
data = {"instances" : [{"ims_ph": ims.tolist()}, {"samples_ph": samples.tolist()} ]}
data = {"inputs" : { "ims_ph": ims, "samples_ph": samples} }

r = requests.post(url="http://localhost:9000/v1/models/multisensory:predict", data=data)

TF-Serving REST docs似乎并不表示这两个输入张量需要任何额外的转义/编码。因为这些不是二进制数据,所以我也不认为base64编码是正确的方法。任何指向这里的工作方法的建议都将不胜感激!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-03 15:01:10

你应该像这样发送你的请求,首先是json序列化请求主体。

代码语言:javascript
复制
r = requests.post(url="http://localhost:9000/v1/models/multisensory:predict", data=json.dumps(data))
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59574255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档