简体   繁体   English

Tensorflow2 C++ model_pruner 失败:参数无效:图不包含终端节点 detection_boxes

[英]Tensorflow2 C++ model_pruner failed: Invalid argument: Graph does not contain terminal node detection_boxes

I export savemodel.pb through python, load by C++ API.我通过 python 导出 savemodel.pb,通过 C++ API 加载。 Here is my load code这是我的加载代码

string strModelPath = "/home/hxy/tf/objectrec/train/train/saved_model/";
string inputLayer = "input_tensor:0";
    vector<string> outputLayer = {"detection_boxes", "detection_classes", "detection_scores", "num_detections"};

tensorflow::SessionOptions session_option;
tensorflow::RunOptions run_option;
tensorflow::SavedModelBundle iBundle
Status load_graph_status = tensorflow::LoadSavedModel(session_option, run_option, strModelDir, {"serve"}, &iBundle);
if (!load_graph_status.ok())
{
    return;
}
cv::Mat frame = cv::imread("/home/hxy/tf/objectrec/test_images/raccoon_dt2.jpg");
Tensor input_tensor(tensorflow::DT_FLOAT, tensorflow::TensorShape({1, frame.rows, frame.cols, frame.channels()}));
float* p = input_tensor.flat<float>().data();
cv::Mat m_input(frame.rows, frame.cols, CV_32FC1, p);
frame.convertTo(m_input, CV_32FC1);

std::vector<tensorflow::Tensor> outputs;
outputs.clear();
Status runStatus = session->Run({{inputLayer, input_tensor},}, outputLayer, {}, &outputs);
...

get error message:得到错误信息:

2020-07-30 18:25:23.941979: I tensorflow/cc/saved_model/loader.cc:303] SavedModel load for tags { serve }; Status: success: OK. Took 5927735 microseconds.
2020-07-30 18:25:24.226638: E tensorflow/core/grappler/optimizers/meta_optimizer.cc:581] model_pruner failed: Invalid argument: Graph does not contain terminal node detection_boxes.

I though maybe output layer name error, so i run saved_model_cli saw model:我虽然可能 output 层名称错误,所以我运行 saved_model_cli 看到 model:

The given SavedModel SignatureDef contains the following output(s):
  outputs['detection_boxes'] tensor_info:
      dtype: DT_FLOAT
      shape: (1, 300, 4)
      name: StatefulPartitionedCall:1
  outputs['detection_classes'] tensor_info:
      dtype: DT_FLOAT
      shape: (1, 300)
      name: StatefulPartitionedCall:2
  outputs['detection_scores'] tensor_info:
      dtype: DT_FLOAT
      shape: (1, 300)
      name: StatefulPartitionedCall:4
  outputs['num_detections'] tensor_info:
      dtype: DT_FLOAT
      shape: (1)
      name: StatefulPartitionedCall:5

I saw has detection_boxes, please give me some suggestion,thanks我看到有detection_boxes,请给我一些建议,谢谢

I solve it by myself, the inputLayer and outputLayer name from saved_model_cli information.我自己解决了,来自saved_model_cli信息的inputLayer和outputLayer名称。 in my pro, it is serving_default_input_tensor:0 and StatefulPartitionedCall:1(or x).在我的专业人士中,它是 serving_default_input_tensor:0 和 StatefulPartitionedCall:1(或 x)。

if you has error: invalid argument specified in either feed_devices or fetch_devices was not found in the graph.如果您有错误:在图中未找到 feed_devices 或 fetch_devices 中指定的无效参数。 maybe it's input layer name wrong, the answer is above, saw input name from saved_model_cli.也许是输入层名称错误,答案在上面,从 save_model_cli 中看到输入名称。 but it's one reason cause this error, maybe you can find other clue, good luck.但这是导致此错误的原因之一,也许您可以找到其他线索,祝您好运。

if you has error: Expects arg[0] to be uint8 but float is provided.如果您有错误:期望 arg[0] 为 uint8 但提供了浮点数。 check your tensor datatype, is must match with saved_model_cli give dtype检查您的张量数据类型,必须与 saved_model_cli 匹配给 dtype

you can lean saved_model_cli from https://www.tensorflow.org/guide/saved_model你可以从https://www.tensorflow.org/guide/saved_model 学习 saved_model_cli

good luck祝你好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM