Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault for cv::dnn::readNetFromONNX.forward() #23080

Closed
4 tasks done
UNeedCryDear opened this issue Jan 3, 2023 · 4 comments · Fixed by #23112
Closed
4 tasks done

Segmentation fault for cv::dnn::readNetFromONNX.forward() #23080

UNeedCryDear opened this issue Jan 3, 2023 · 4 comments · Fixed by #23112

Comments

@UNeedCryDear
Copy link

UNeedCryDear commented Jan 3, 2023

System Information

OpenCV version: 4.7.0 from https://github.com/opencv/opencv/archive/refs/tags/4.7.0.zip
Operating System / Platform: Win10 22H2
Compiler & compiler version:VS2019 -MSVC14.2

Detailed description

ONNX export from yolov5-seg.pt:
https://drive.google.com/file/d/1tV2moQxNfLzNf6yXm5Zev5CVj2o9zuaz/view?usp=share_link

Some wrong happened in runWinograd63()

if (runWinograd63(input, fusedAddMat, output, conv, ntasks, minval, maxval, activ, ifMinMaxAct))

Wwhen running here finally, an error is reported: the vector is out of range.
parallel_for_(Range(0, ntasks), [&](const Range& r0) {

image

@lioneldaniel told me that it was caused by this PR #22593, so how to solve this problem?

UNeedCryDear/yolov5-seg-opencv-onnxruntime-cpp#6 (comment)

Steps to reproduce

test code:

#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
string model_path = "./yolov5s-seg.onnx";
Net net=readNetFromONNX(model_path );
net.setPreferableBackend(cv::dnn::DNN_BACKEND_DEFAULT);
net.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);
Mat test_img=Mat::zeros(Size(640,640),CV_8UC3);
Mat blob;
blobFromImage(test_img, blob, 1 / 255.0, cv::Size(640, 640), cv::Scalar(0, 0, 0), true, false);
net.setInput(blob);
vector<string> output_layer_names{ "output0","output1" };
net.forward(net_output_img, output_layer_names); 
...

The above code can run correctly in versions 4.5.0~4.6.0, but an error occurred in 4.7.0.

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)
@zihaomu zihaomu self-assigned this Jan 4, 2023
@zihaomu
Copy link
Member

zihaomu commented Jan 4, 2023

Hi @UNeedCryDear, I just check your model with 4.7 release. And it works fine on my ARM M1 chip and Ubuntu of X86 platform (with AVX2).

I will try to reproduce the issue in Win10 later.

For short you can try to close the Winograd optimization in your machine by the following code:

net.enableWinograd(false);
net.forward(net_output_img, output_layer_names); 

Mode details please refer the doc link: https://docs.opencv.org/4.x/db/d30/classcv_1_1dnn_1_1Net.html#a14a87a7604c03ef4ff366672ee9bfcf2

@UNeedCryDear
Copy link
Author

It can run correctly after adding net.enableWinograd(false);

@zihaomu
Copy link
Member

zihaomu commented Jan 9, 2023

Hi @UNeedCryDear, the patch has been merged. You can try to rebuild OpenCV from scratch to get the speed up of Winograd in your machine.

@lioneldaniel
Copy link

@zihaomu I confim that the following code works now, thanks!

else if(conv->conv_type == _FX_CONV_TYPE_WINOGRAD3X3) // winograd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants