简体   繁体   English

TensorFlow 服务 REST API - JSON 解析错误

[英]TensorFlow Serving REST API - JSON Parse Error

I've frozen and exported a SavedModel , which takes as input a batch of videos that has the following format according to saved_model_cli :我已经冻结并导出了一个SavedModel ,它根据saved_model_cli将一批具有以下格式的视频作为输入:

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

I have a TF-Serving (HTTP/REST) server successfully running locally.我有一个在本地成功运行的 TF-Serving (HTTP/REST) 服务器。 From my Python client code, I have 2 populated objects of type numpy.ndarray , named ims of shape (1, 248, 224, 224, 3) -- and samples of shape (1, 173774, 2).从我的 Python 客户端代码中,我有 2 个numpy.ndarray类型的填充对象,命名为形状的ims (1, 248, 224, 224, 3) -- 和形状的samples (1, 173774, 2)。

I am trying to run an inference against my TF model server (see client code below) but am receiving the following error: {u'error': u'JSON Parse error: Invalid value. at offset: 0'}我正在尝试对我的 TF 模型服务器运行推理(请参阅下面的客户端代码),但收到以下错误: {u'error': u'JSON Parse error: Invalid value. at offset: 0'} {u'error': u'JSON Parse error: Invalid value. at offset: 0'}

# 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)

The TF-Serving REST docs don't seem to indicate that any extra escaping / encoding is required here for these two input tensors. TF-Serving REST 文档似乎并未表明这两个输入张量需要任何额外的转义/编码。 As these aren't binary data, I don't think base64 encoding is the right approach either.由于这些不是二进制数据,我认为 base64 编码也不是正确的方法。 Any pointers to a working approach here would be greatly appreciated!任何指向这里工作方法的指针将不胜感激!

您应该像这样发送您的请求,json 首先序列化请求正文。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM