neu*_*rix 5 rest keras tensorflow tensorflow-serving tensorflow-estimator
我已将 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
Run Code Online (Sandbox Code Playgroud)
我转换了特征规范,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"]}]'
Run Code Online (Sandbox Code Playgroud)
现在,我将此模型加载到 TF Serving 中,模型服务器启动正常。
当我使用下面的 json 有效负载 (application/json) 请求模型预测时,我收到以下错误:
{
"signature_name":"serving_default",
"instances":[
{
"examples":["99214,17000,17000,13121,99203"]
}
]
}
Run Code Online (Sandbox Code Playgroud)
错误:
"error": "Expected serialized to be a vector, got shape: [1,1]
Run Code Online (Sandbox Code Playgroud)
不同的有效载荷结构,导致此错误
{
"signature_name":"serving_default",
"examples":[
{
"procedure":["99214,17000,17000,13121,99203"]
}
]
}
Run Code Online (Sandbox Code Playgroud)
错误:
"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."
Run Code Online (Sandbox Code Playgroud)
在这个预测案例中,TensorFlow Serving 请求的正确负载格式是什么?
负载是否需要在 tf.Example 结构中格式化?
小智 1
您可以尝试使用build_raw_serving_input_receiver_fn()导出模型吗?procedure并将JSON 预测请求中的原始张量 ( ) 传递为:
{
"signature_name": "serving_default",
"instances": [
{
"procedure": ["99214,17000,17000,13121,99203"]
}
]
}
Run Code Online (Sandbox Code Playgroud)
鉴于您使用的是默认服务签名名称和单个命名输入,您可以将请求缩短为:
{
"instances": ["99214,17000,17000,13121,99203"]
}
Run Code Online (Sandbox Code Playgroud)
关于您现有的代码,使用导出模型build_parsing_serving_input_receiver_fn()需要序列化tf.Example字符串 blob 作为输入。saved_model_cli工具(是Python并且可以访问protos)为你完成这个序列化,因此工作得很好。使用 Web/REST API 时进行原型序列化可能会很麻烦(需要 protobuf 库),并且对您的使用来说是一种过度的杀伤力。
| 归档时间: |
|
| 查看次数: |
4046 次 |
| 最近记录: |