JustasBart/yolov8_CPP_Inference_OpenCV_ONNX

There is an error reported in net.forward(output, net.getUnconnectedOutLayersNames())

SuperGentry opened this issue · 3 comments

  1. Hi, I have the following problem when loading the model you gave me for yolov8s.onnx.
    [ERROR:0@0.211] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\dnn.cpp (3875) cv::dnn::dnn4_v20211220::Net::Impl::getLayerShapesRecursively OPENCV/DNN: [Reshape]:(390): getMemoryShapes() throws exception. inputs=1 outputs=1/1 blobs=0 [ERROR:0@0.211] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\dnn.cpp (3878) cv::dnn::dnn4_v20211220::Net::Impl::getLayerShapesRecursively input[0] = [ 1 64 8400 ] [ERROR:0@0.211] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\dnn.cpp (3882) cv::dnn::dnn4_v20211220::Net::Impl::getLayerShapesRecursively output[0] = [ ] [ERROR:0@0.211] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\dnn.cpp (3888) cv::dnn::dnn4_v20211220::Net::Impl::getLayerShapesRecursively Exception message: OpenCV(4.5.5) C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\layers\reshape_layer.cpp:107: error: (-215:Assertion failed) total(srcShape, srcRange.start, srcRange.end) == maskTotal in function 'cv::dnn::computeShapeByReshapeMask'
    After many attempts, I suspect that it is a problem with opencv, what is the version of opencv?

  2. In addition, if cuda is used, there is an error reported
    [ WARN:0@0.217] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\dnn.cpp (1483) cv::dnn::dnn4_v20211220::Net::Impl::setUpNet DNN module was not built with CUDA backend; switching to CPU.
    So please ask if you have encountered any corresponding problems?

@SuperGentry This to me looks like an issue with the input shape of the model. On the example that I've included here the exported models are 640x480 and not say 640x640 as they are by default (You can also export your own ones as you desire). Please confirm that you're trying to use the correct input shape.

Otherwise you might not have built your OpenCV with the ONNX flag or some other flag(s). Please refer to:

OpenCV build

This describes the build process for the current latest (4.7.0), but it should be similar to any other version. Though some older versions had a flag of something like the INF_ENGINE and N_GRAPH so maybe keep an eye out for those.

Other than that let me know how you get on, good luck! 🚀

Thank you very much for your answer, following the hints you gave, I guess it's because I didn't use CmakeList to configure Opencv, I installed Opencv and configured the properties directly in Visual Studio.

@SuperGentry Oh, I see, interesting, well I'm glad you were able to resolve it!

Good luck! 🚀