UNeedCryDear/yolov7-opencv-dnn-cpp

segmentation fault (core dumped)

Closed this issue · 9 comments

Hello. I'm just adding yolov7.onnx and want to do an inference on test image; But it throws Segmentation Fault error.
opencv => 4.7
ubuntu 22.4
g++ 11.3
USE_CUDA is false

for example when i log the steps, there are some nan values.
the log: -nan,6.95044e-43,9.3887e-44,6.5861e-44,-nan
these 2 nan values are pdata[0] and pdata[4]( but sometimes pdata[1] or pdata[2] becomes nan )
the code (Yolo::Detect method):
for (int stride = 0; stride < strideSize; stride++) { float* pdata = (float*)netOutputImg[stride].data;

First ,yolov7 should set this flag false.

#define YOLOV5 false //true:Yolov5, false:yolov7

Sec, change this to your class name if custom model.
std::vector<std::string> className = { "person", "bicycle", "car", "motorcycle", "airplane", "bus", "train", "truck", "boat", "traffic light",

Third,make sure that the img size is equal to Yolo.netWidth and Yolo.neiHeight when you export onnx.
At the same time, use this page open your onnx model(https://netron.app/) to check how many outputs.
If three, set YOLO_P6 false. Four,set it true.
image

image

If there are still problems after the above modifications, can you provide your model?

This is my ONNX output in Netron:
name: classes
type: float32[1,25200,4]
name: boxes
type: float32[1,25200,80]

Its shape is neither 3 nor 4. It has only classes and boxes with the above shapes.

What is the purpose of YOLO_P6 actually?

Please export onnx with code like:

python path/to/export.py --weights yolov7.pt --img [640,640]

P6 is the same as P3,P4,P5,but it stride is 64.
ultralytics/yolov5#2835 (comment)
Both yolov5 and v7 use the P5-model by default, but sometimes the P6 model is used to detect oversized objects,such as yolov5s6.pt and yolov7-d6.pt

Thanks.

Downgrading opencv to 4.6.0 fixed my issue in segmentation fault

How can I read the onnx model file or pt model file without using any library(link opencv dnn module,...)?
(I know this is not part of the issue. But its important for me to load load model file into network in an embedded platform)

sorry, I don't know