doleron / yolov5-opencv-cpp-python

Example of using ultralytics YOLO V5 with OpenCV 4.5.4, C++ and Python
MIT License
328 stars 103 forks source link

[Fixed] Custom Weight Error : Segmentation fault #3

Open lanbao2021 opened 2 years ago

lanbao2021 commented 2 years ago
image

Hi, it's me again.

I exported my custom weight file and modified yolo.cpp towards the path and classes.txt towards the labels.

the error came from your code or my custom weight? or anything else to modified?

hope to your reply😍

doleron commented 2 years ago

Hi, Lan.

the error came from your code or my custom weight? or anything else to modified?

To be honest, there is no way to know. The best way here is debugging the code and check where the seg fault happens.

Also, double check if you are using a .onnx file or .pt file. OpenCV only works with .onnx

lanbao2021 commented 2 years ago

@doleron Thank you for your early reply!

I will try to figure it out by myself.

lanbao2021 commented 2 years ago
image

Hi, doleron.

I would like to add some information.

I debugged the yolo.cpp by setting flag_num as the image above.

Maybe the problem was caused by the data += 85 ?

😵Could you please help me to understand the constant dimension and rows?

@doleron

doleron commented 2 years ago

@lanbao2021 85 is 80 (number of COCO classes) + 1 (confidence) + 4 (xywh). If your model has only 10 classes, replace 85 by 15. Check this article where I explain that, in particular the section "Unwrapping the output".

lanbao2021 commented 2 years ago

ohhhhhh! it works! !

😍Thank you very much! @doleron

doleron commented 2 years ago

Thanks for the feedback @lanbao2021 !

I'll keep this issue open to make it more visible for someone looking for the same problem.

hanyuan97 commented 2 years ago

@lanbao2021 85 is 80 (number of COCO classes) + 1 (confidence) + 4 (xywh). If your model has only 10 classes, replace 85 by 15. Check this article where I explain that, in particular the section "Unwrapping the output".

This article is really helpful !! and, can you please teach me how to calculate or find the rows if I change the input size, for example 416*416?

doleron commented 2 years ago

@lanbao2021 85 is 80 (number of COCO classes) + 1 (confidence) + 4 (xywh). If your model has only 10 classes, replace 85 by 15. Check this article where I explain that, in particular the section "Unwrapping the output".

This article is really helpful !! and, can you please teach me how to calculate or find the rows if I change the input size, for example 416*416?

@hanyuan97 Hello. Thank you! If you have some question about the article, can you ask there in medium?