TensorFlow Serving REST API – JSON解析错误

huangapple go评论65阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年1月3日 14:41:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/59574255.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定