问题描述:
1.报错的时机是随机的,有时不报错有时报错;
2.并非全局变量与局部变量的问题;
3.ONNX模型的路径没有问题
解决方法:参考microsoft/onnxruntime_Issues点赞最多的回答即可解决!!!
首先,在“xx.h”文件里面这样申明:
std::vector<const char*> inputNames;
std::vector< Ort::AllocatedStringPtr> inputNodeNameAllocatedStrings; // <-- newly added
std::vector<const char*> outputNames;
std::vector<Ort::AllocatedStringPtr> outputNodeNameAllocatedStrings; // <-- newly added在这里插入代码片
其次,在“xx.cpp”文件里面这样写:
/* for (auto shape : inputTensorShape)
qDebug() << "Input shape: " << shape << endl;*/
auto input_node = session.GetInputNameAllocated(0, allocator);
inputNodeNameAllocatedStrings.push_back(std::move(input_node));//新增
inputNames.push_back(inputNodeNameAllocatedStrings.back().get());//新增
//inputNames.push_back(input_node.get());//被替换
auto output_node = session.GetOutputNameAllocated(0, allocator);
outputNodeNameAllocatedStrings.push_back(std::move(output_node));//新增
outputNames.push_back(outputNodeNameAllocatedStrings.back().get());//新增
//outputNames.push_back(output_node.get());//被替换
this->inputImageShape = cv::Size(inputSize);