重塑输入层“要求的形状”的大小总是“输入形状”的大小的平方

问题描述 投票:0回答:1

我正在尝试使用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_FLOAT,我没有做图像识别。这是该命令的输出:

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,我的代码仅查询该模型。我不更改图表。

tensorflow predict c-api
1个回答
0
投票

事实证明,问题是由我未正确使用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);
© www.soinside.com 2019 - 2024. All rights reserved.