I am following this tutorial to load the yolov5*.onnx models with the OpenCV DNN module and use it to make inference. I get the following error when trying to load the model:
[ERROR:0@10.376] global E:\Libraries\C++\opencv_gpu\opencv_source\modules\dnn\src\onnx\onnx_importer.cpp (1021) cv::dnn::dnn4_v20220524::ONNXImporter::handleNode DNN/ONNX: ERROR during processing node with 1 inputs and 1 outputs: [Identity]:(onnx_node!Identity_0) from domain='ai.onnx' OpenCV(4.6.0-dev)
E:\Libraries\C++\opencv_gpu\opencv_source\modules\dnn\src\onnx\onnx_importer.cpp:1040: error: (-2:Unspecified error) in function 'cv::dnn::dnn4_v20220524::ONNXImporter::handleNode' > Node [Identity@ai.onnx]:(onnx_node!Identity_0) parse error: OpenCV(4.6.0-dev) E:\Libraries\C++\opencv_gpu\opencv_source\modules\dnn\src\layer.cpp:246: error: (-215:Assertion failed) inputs.size() in function 'cv::dnn::dnn4_v20220524::Layer::getMemoryShapes' >
The minimal code to reproduce the error is as follows:
#include <iostream>
#include <fstream>
// openCV related includes
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
using namespace cv::dnn;
using namespace cuda;
int main()
{
printCudaDeviceInfo(0);
// Load model.
Net net;
try
{
//net = readNet("yolov5s.onnx");
net = readNetFromONNX("yolov5s.onnx");
}
catch (cv::Exception& e)
{
cerr << endl << endl << e.msg << endl << endl; // output exception message
return -1;
}
return 0
}
I built OpenCV from source with CUDA / CuDNN other relevant modules using cmake on windows. (OpenCV version 4.6.0).
Why I am getting this exception? How can I correctly load the onnx model of yolo?