【问题标题】:Reshape input layer 'requested shape' size always 'input shape' size squared重塑输入层“请求的形状”大小总是“输入形状”大小的平方
【发布时间】:2020-05-14 01:03:33
【问题描述】:

我正在尝试使用 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】:

    原来问题是我没有正确使用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);
    

    【讨论】:

      猜你喜欢
      • 2019-12-11
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 2017-03-13
      • 1970-01-01
      • 2019-08-05
      • 1970-01-01
      • 2019-12-06
      相关资源
      最近更新 更多