tensorflow-serving - tensorflow_model_server:错误“填充的第一维必须是输入的等级[4,2] ...”
问题描述
我正在使用 tensorflow_model_server 来提供 SavedModel。我不断收到此响应代码 400 和以下错误:
{ "error": "The first dimension of paddings must be the rank of inputs[4,2] [1,1,1,208,770,3]\\n\\t [[{{node Generator/FlatConv/sequential/zero_padding2d/Pad}}]]" }
保存模型 cli 的输出显示 ...
MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:
signature_def['__saved_model_init_op']:
The given SavedModel SignatureDef contains the following input(s):
The given SavedModel SignatureDef contains the following output(s):
outputs['__saved_model_init_op'] tensor_info:
dtype: DT_INVALID
shape: unknown_rank
name: NoOp
Method name is:
signature_def['serving_default']:
The given SavedModel SignatureDef contains the following input(s):
inputs['input_1'] tensor_info:
dtype: DT_FLOAT
shape: (-1, -1, -1, 3)
name: serving_default_input_1:0
The given SavedModel SignatureDef contains the following output(s):
outputs['output_1'] tensor_info:
dtype: DT_FLOAT
shape: (-1, -1, -1, 3)
name: StatefulPartitionedCall:0
Method name is: tensorflow/serving/predict
WARNING:tensorflow:From /tensorflow-1.15.0/python3.6/tensorflow_core/python/ops/resource_variable_ops.py:1781: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
Defined Functions:
Function Name: '_default_save_signature'
Option #1
Callable with:
Argument #1
input_1: TensorSpec(shape=(?, ?, ?, 3), dtype=tf.float32, name='input_1')
预处理
img_path = "/content/input_images/my_img.jpg"
img = np.array(Image.open(img_path).convert("RGB"))
img = np.expand_dims(img, 0).astype(np.float32) / 127.5 - 1
请求代码:
payload = {
"instances": [{'input_1': [input_image.tolist()]}]
}
headers = {"content-type": "application/json"}
json_response = requests.post('http://localhost:8501/v1/models/my_model:predict', data=json.dumps(payload), headers=headers)
print("Request complete")
print (json_response)
response_text = json_response.text
response_text
响应/输出
Request complete
<Response [400]>
'{ "error": "The first dimension of paddings must be the rank of inputs[4,2] [1,1,1,449,674,3]\\n\\t [[{{node Generator/FlatConv/sequential/zero_padding2d/Pad}}]]" }'
代码在 Colab 上运行
我不明白这里有什么问题。
解决方案
这意味着您的输入数据应该是四维数组,而您有 6d
推荐阅读
- rust - 是否通过来自多个线程的相同指针访问对象以进行原子操作未定义行为?
- powerbi - DAX 根据查找 tbl 中存在的所有不同月份将过滤表传递给聚合
- list - 映射两个长度不均匀的列表 - 方案
- jestjs - 使用 jest 自动模拟时,用户模块被视为节点模块
- javascript - 在 BeforeMount 或 Mounted-VUE.JS 中使用道具
- docker - 如何仅列出位于特定私有注册表中的图像
- .net-core - 使用 dll 路径时不支持 dotnet test /p 选项
- python - python tkinter - 如何使 ttk Notebook 选项卡更改其顺序?
- python - 如何确定文件中的行是否为空白,或者仅将填充的行写入文件,python 3x
- javascript - 使用 Node.js 添加/编辑单独 HTML 文档的 dom 元素