英文:
TensorFlow Serving REST API - JSON Parse Error
问题
我已经冻结并导出了一个SavedModel
,它接受一个批量视频作为输入,根据saved_model_cli
,输入的格式如下:
给定的 SavedModel SignatureDef 包含以下输入(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
给定的 SavedModel SignatureDef 包含以下输出(s):
... << 输出 >> ......
方法名称为:tensorflow/serving/predict
我已经成功在本地运行了一个 TF-Serving(HTTP/REST)服务器。从我的Python客户端代码中,我有两个已填充的numpy.ndarray
对象,分别命名为ims
的形状为(1, 248, 224, 224, 3)和samples
的形状为(1, 173774, 2)。
我尝试运行对我的TF模型服务器的推理(请参见下面的客户端代码),但收到以下错误:{u'error': u'JSON Parse error: Invalid value. at offset: 0'}
# 我尝试了以下组合但没有成功:
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文档似乎没有指示这两个输入张量需要任何额外的转义/编码。由于这些不是二进制数据,我认为base64编码不是正确的方法。非常感谢提供一个有效的方法的任何指针!
英文:
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
:
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. 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).
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'}
# 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. As these aren't binary data, I don't think base64 encoding is the right approach either. Any pointers to a working approach here would be greatly appreciated!
答案1
得分: 2
你应该像这样发送你的请求,首先对请求体进行JSON序列化。
r = requests.post(url="http://localhost:9000/v1/models/multisensory:predict", data=json.dumps(data))
英文:
You should send your request like this, json serialize request body first.
r = requests.post(url="http://localhost:9000/v1/models/multisensory:predict", data=json.dumps(data))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论