我正在尝试使用C-API运行SavedModel。 在运行TF_SessionRun
时,它总是在各种输入节点上失败,并出现相同的错误。
TF_SessionRun status: 3:Input to reshape is a tensor with 6 values, but the requested shape has 36
TF_SessionRun status: 3:Input to reshape is a tensor with 19 values, but the requested shape has 361
TF_SessionRun status: 3:Input to reshape is a tensor with 3111 values, but the requested shape has 9678321
...
可以看出,请求的形状值的数量始终是预期输入大小的平方。这很奇怪。
使用saved_model_cli
命令,模型运行良好。 输入都是标量DT_STRING或DT_FLOATs,我不是在进行图像识别。 下面是该命令的输出:
signature_def['serving_default']:
The given SavedModel SignatureDef contains the following input(s):
inputs['f1'] tensor_info:
dtype: DT_STRING
shape: (-1)
name: f1:0
inputs['f2'] tensor_info:
dtype: DT_STRING
shape: (-1)
name: f2:0
inputs['f3'] tensor_info:
dtype: DT_STRING
shape: (-1)
name: f3:0
inputs['f4'] tensor_info:
dtype: DT_FLOAT
shape: (-1)
name: f4:0
inputs['f5'] tensor_info:
dtype: DT_STRING
shape: (-1)
name: f5:0
The given SavedModel SignatureDef contains the following output(s):
outputs['o1_probs'] tensor_info:
dtype: DT_DOUBLE
shape: (-1, 2)
name: output_probs:0
outputs['o1_values'] tensor_info:
dtype: DT_STRING
shape: (-1, 2)
name: output_labels:0
outputs['predicted_o1'] tensor_info:
dtype: DT_STRING
shape: (-1, 1)
name: output_class:0
Method name is: tensorflow/serving/predict
任何关于正在发生的事情的线索都非常感谢。saved_model.pb 文件来自 AutoML,我的代码只是查询该模型。我不改变图表。
事实证明,该问题是由于我没有正确使用TF_AllocateTensor功能引起的。
原始代码是这样的:
TF_Tensor* t = TF_AllocateTensor(TF_STRING, nullptr, 0, sz);
当它出现时,它应该是:
int64_t dims = 0;
TF_Tensor* t = TF_AllocateTensor(TF_STRING, &dims, 1, sz);