【问题标题】:How to run Yolov5 tensorflow model.pb inside c++ code?如何在 C++ 代码中运行 Yolov5 tensorflow model.pb?
【发布时间】:2021-12-16 16:58:52
【问题描述】:
我已经使用 yolov5 训练了一个模型,我得到了我转换的 model.pt
现在我想要它使用导出文件到 TensorFlow 兼容的 model.pb
用 c++ 而不是 python 使用这个模型我做了很多研究
但我确实配置了如何做到这一点,所以我在哪里可以找到
在 c++ 代码中使用 model.pb 的示例?
我尝试使用 TochScript 运行 model.pt,它运行良好我尝试过
运行 model.onnx 它运行但速度很慢我现在正在尝试运行
模式.pb
【问题讨论】:
标签:
c++
tensorflow
yolov5
tensorflow-c++
【解决方案1】:
我没有找到直接运行 model.pb 的方法,但经过长时间的研究,我已经能够运行 saved_model。有重要的代码行
// the input node is:
const string input_node = "serving_default_input_1:0";
// the output node is:
std::vector<string> output_nodes ={"StatefulPartitionedCall:0"};
tensorflow::SavedModelBundle bundle;
//std::string path = path to the saved model folder ./yolov5s_saved_model/
tensorflow::LoadSavedModel(session_options, run_options, path, {"serve"},
&bundle);
std::vector<std::pair<string, Tensor>> inputs_data = {{input_node, image_output}};
std::vector<tensorflow::Tensor> predictions;
bundle.GetSession()->Run( inputs_data , output_nodes, {}, &predictions);