using cv2 dnn interface to run yolov8 model#24396
using cv2 dnn interface to run yolov8 model#24396asmorkalov merged 16 commits intoopencv:4.xfrom Tsai-chia-hsiang:yolov8cv
Conversation
samples/dnn/dnn_model_runner/dnn_conversion/ultralytics/predict/dog1.jpg
Outdated
Show resolved
Hide resolved
samples/dnn/dnn_model_runner/dnn_conversion/ultralytics/yolov8_cv.py
Outdated
Show resolved
Hide resolved
|
@dkurt However, according to the comment above it, shoudn't it be Or Do I misunderstand the usage of this line ? Thanks |
|
@Tsai-chia-hsiang, made some changes with sample update and common parts unification. Please give your comment on the padding preprocessing (I removed it for now). If you don't mind, we can introduce it in the next PR. Also, I have replaced onnx URL to Ultralytics's Now sample works with the following commands: YOLOv4 (Darknet): SSD (Caffe): |
|
@dkurt |
|
@Tsai-chia-hsiang, I recommend to keep this PR just enable YOLOv8 postprocessing. Need more time to think about the pre-processing proposal. |
|
OK, I see. Thanks! |
|
|
@asmorkalov , dis you convert a model to ONNX or used https://github.com/JasonLin1110/ultralytics_yolov8_onnx_model/blob/main/yolov8net.onnx ? I tested second option, let me try again. Update: convert step worked for me too. Can you please check that |
add yolov8 to object_detection.py and models.yml
change yoloV8 readNetFromONNX to readNet, change lastLayer.type == 'Identity' to args.postprocessing == 'yolov8'
add padding image to blobFromImage. Solve case yolov8 doen't have config(args.config == None), so cv.samples.findFile(args.config) will return error
add a if else in nms_indices = nms_indices[:, 0] if len(nms_indices) else [], because yolov8's nms_indices is 1-d array
Correct yolov8 onnx's url and classes
minScore, minClassLoc, x
|
Ok. I found out the issue reason.
|
samples/dnn/models.yml
Outdated
| # model.export(format="onnx") | ||
| yolov8: | ||
| load_info: | ||
| url: "https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt" |
There was a problem hiding this comment.
ONNX link is required here.
There was a problem hiding this comment.
It's better to rename model: "yolov8net.onnx" to model: "yolov8n.pt".
config for download_models.py contains link to pt, but not onnx. The file is renamed to .onnx as it's defined in yaml config.
I have not seen entry for YOLOv8 in download_models.py except https://github.com/CVHub520/X-AnyLabeling/releases/download/v0.1.0/yolov8n.onnx which is not an official repo. Can we keep a link to .pt?
There was a problem hiding this comment.
Oh, excuse me. I just missed that there is another https://github.com/opencv/opencv/blob/4.x/samples/dnn/download_models.py
asmorkalov
left a comment
There was a problem hiding this comment.
👍
Tested manually with current OpenCV 4.x, Ubuntu 18.04 and ONNX model by link in yaml config.
|
@asmorkalov, thanks for testing! |
Using cv2 dnn interface to run yolov8 model opencv#24396 This is a sample code for using opencv dnn interface to run ultralytics yolov8 model for object detection. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [X] I agree to contribute to the project under Apache 2 License. - [X] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [X] The PR is proposed to the proper branch - [] There is a reference to the original bug report and related work - [] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [] The feature is well documented and sample code can be built with the project CMake
Using cv2 dnn interface to run yolov8 model opencv#24396 This is a sample code for using opencv dnn interface to run ultralytics yolov8 model for object detection. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [X] I agree to contribute to the project under Apache 2 License. - [X] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [X] The PR is proposed to the proper branch - [] There is a reference to the original bug report and related work - [] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [] The feature is well documented and sample code can be built with the project CMake
Using cv2 dnn interface to run yolov8 model opencv#24396 This is a sample code for using opencv dnn interface to run ultralytics yolov8 model for object detection. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [X] I agree to contribute to the project under Apache 2 License. - [X] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [X] The PR is proposed to the proper branch - [] There is a reference to the original bug report and related work - [] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [] The feature is well documented and sample code can be built with the project CMake

This is a sample code for using opencv dnn interface to run ultralytics yolov8 model for object detection.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.