【发布时间】:2018-08-09 22:18:50
【问题描述】:
我已将 Keras 模型转换为 Tensorflow 估计器,将 Tensorflow Transform 添加到图表中,然后导出模型以供服务。
当我检查模型签名时,我可以看到以下信息:
signature_def['serving_default']:
The given SavedModel SignatureDef contains the following input(s):
inputs['examples'] tensor_info:
dtype: DT_STRING
shape: (-1)
name: input_example_tensor:0
The given SavedModel SignatureDef contains the following output(s):
outputs['specialities'] tensor_info:
dtype: DT_FLOAT
shape: (-1, 154)
name: specialities/Softmax:0
Method name is: tensorflow/serving/predict
我用tf.estimator.export.build_parsing_serving_input_receiver_fn 转换了特征规范,因此签名中输入节点的名称是example。我的模型中输入节点的名称是procedures。
然后我使用saved_model_cli 手动测试导出的模型,一切看起来都不错(我得到了一个概率列表)
!saved_model_cli run --dir=/model_dir/1533849825
--tag_set serve
--signature_def serving_default
--input_examples 'examples=[{"procedures": ["99214,17000,17000,13121,99203"]}]'
现在,我将此模型加载到 TF Serving 中,模型服务器启动正常。
当我使用下面的 json 有效负载 (application/json) 请求模型预测时,我收到以下错误:
{
"signature_name":"serving_default",
"instances":[
{
"examples":["99214,17000,17000,13121,99203"]
}
]
}
错误:
"error": "Expected serialized to be a vector, got shape: [1,1]
不同的有效载荷结构,导致此错误
{
"signature_name":"serving_default",
"examples":[
{
"procedure":["99214,17000,17000,13121,99203"]
}
]
}
错误:
"error": "JSON Value: {\n \"signature_name\": \"serving_default\",\n
\"examples\": [\n {\n \"procedures\":
["99214,17000,17000,13121,99203"]]\n }\n ]\n} not formatted
correctly. Expecting object with \'instances\' key and a list/array as the value."
在这个预测案例中,TensorFlow Serving 请求的正确负载格式是什么?
payload需要在tf.Example结构中格式化吗?
【问题讨论】:
-
您是否尝试使用 `raw_input_receiver_fn' 代替? tensorflow.org/api_docs/python/tf/estimator/export/…
标签: rest tensorflow keras tensorflow-serving tensorflow-estimator