learnopencv icon indicating copy to clipboard operation
learnopencv copied to clipboard

Can't read .onnx file in c++

Open Helyousfi opened this issue 1 year ago • 3 comments

Hi,

opencv version : tried opencv-4.5.5 & opencv-4.6 but got the same error.

I'm trying the same c++ code from the repo, but I have an error in the line net = readNet("yolo5n.onnx"); :

    // Load model.
    Net net;
    net = readNet("yolo5n.onnx");

I got the following error.

OpenCV: terminate handler is called! The last OpenCV error is: OpenCV(4.5.5) Error: Bad argument (Can't read ONNX file: yolo5n.onnx) in cv::dnn::dnn4_v20211220::ONNXImporter::ONNXImporter, file C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp, line 194

Does anybody have the same problem ? Thanks

Helyousfi avatar Jul 27 '22 09:07 Helyousfi

Can you try using an absolute path for "yolo5n.onnx"? Are you sure it is in the "current working directory CWD"?

brmarkus avatar Jul 28 '22 06:07 brmarkus

Problem solved, I had to build the opencv-contrib repository

Helyousfi avatar Aug 03 '22 11:08 Helyousfi

i met the same problem when i run the python code as following: (base) ubuntu@ubuntu-XPS-8930:~/heop_devel_kit/volume/visionanalyticsAI$ python yolov5.py Traceback (most recent call last): File "yolov5.py", line 120, in net = cv2.dnn.readNet(modelWeights) cv2.error: OpenCV(4.2.0) /io/opencv/modules/dnn/src/onnx/onnx_importer.cpp:110: error: (-215:Assertion failed) !tensor_pr oto.raw_data().empty() || !tensor_proto.float_data().empty() || !tensor_proto.double_data().empty() || !tensor_proto.int6 4_data().empty() in function 'getMatFromTensor' i solved it when i run the code by (base) ubuntu@ubuntu-XPS-8930:~/heop_devel_kit/volume/visionanalyticsAI$ python3.6 yolov5.py Inference time: 300.82 ms

pppaulpeter avatar Mar 28 '23 07:03 pppaulpeter