mirror of
https://github.com/opencv/opencv.git
synced 2024-12-03 16:35:09 +08:00
a8d1373919
Add sample support of YOLOv9 and YOLOv10 in OpenCV #25794 This PR adds sample support of [`YOLOv9`](https://github.com/WongKinYiu/yolov9) and [`YOLOv10`](https://github.com/THU-MIG/yolov10/tree/main)) in OpenCV. Models for this test are located in this [PR](https://github.com/opencv/opencv_extra/pull/1186). **Running YOLOv10 using OpenCV.** 1. In oder to run `YOLOv10` one needs to cut off postporcessing with dynamic shapes from torch and then convert it to ONNX. If someone is looking for ready solution, there is [this forked branch](https://github.com/Abdurrahheem/yolov10/tree/ash/opencv-export) from official YOLOv10. Particularty follow this proceduce. ```bash git clone git@github.com:Abdurrahheem/yolov10.git conda create -n yolov10 python=3.9 conda activate yolov10 pip install -r requirements.txt python export_opencv.py --model=<model-name> --imgsz=<input-img-size> ``` By default `model="yolov10s"` and `imgsz=(480,640)`. This will generate file `yolov10s.onnx`, which can be use for inference in OpenCV 2. For inference part on OpenCV. one can use `yolo_detector.cpp` [sample](https://github.com/opencv/opencv/blob/4.x/samples/dnn/yolo_detector.cpp). If you have followed above exporting procedure, then you can use following command to run the model. ``` bash build opencv from source cd build ./bin/example_dnn_yolo_detector --model=<path-to-yolov10s.onnx-file> --yolo=yolov10 --width=640 --height=480 --input=<path-to-image> --scale=0.003921568627 --padvalue=114 ``` If you do not specify `--input` argument, OpenCV will grab first camera that is avaliable on your platform. For more deatils on how to run the `yolo_detector.cpp` file see this [guide](https://docs.opencv.org/4.x/da/d9d/tutorial_dnn_yolo.html#autotoc_md443) **Running YOLOv9 using OpenCV** 1. Export model following [official guide](https://github.com/WongKinYiu/yolov9)of the YOLOv9 repository. Particularly you can do following for converting. ```bash git clone https://github.com/WongKinYiu/yolov9.git cd yolov9 conda create -n yolov9 python=3.9 conda activate yolov9 pip install -r requirements.txt wget https://github.com/WongKinYiu/yolov9/releases/download/v0.1/yolov9-t-converted.pt python export.py --weights=./yolov9-t-converted.pt --include=onnx --img-size=(480,640) ``` This will generate <yolov9-t-converted.onnx> file. 2. Inference on OpenCV. ```bash build opencv from source cd build ./bin/example_dnn_yolo_detector --model=<path-to-yolov9-t-converted.onnx> --yolo=yolov9 --width=640 --height=480 --scale=0.003921568627 --padvalue=114 --path=<path-to-image> ``` ### 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 - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake |
||
---|---|---|
.. | ||
cityscapes_semsegm_test_enet.py | ||
imagenet_cls_test_alexnet.py | ||
imagenet_cls_test_googlenet.py | ||
imagenet_cls_test_inception.py | ||
npy_blob.cpp | ||
npy_blob.hpp | ||
pascal_semsegm_test_fcn.py | ||
test_backends.cpp | ||
test_caffe_importer.cpp | ||
test_common.cpp | ||
test_common.hpp | ||
test_common.impl.hpp | ||
test_darknet_importer.cpp | ||
test_googlenet.cpp | ||
test_graph_simplifier.cpp | ||
test_ie_models.cpp | ||
test_int8_layers.cpp | ||
test_layers.cpp | ||
test_main.cpp | ||
test_misc.cpp | ||
test_model.cpp | ||
test_nms.cpp | ||
test_onnx_conformance_layer_filter__cuda_denylist.inl.hpp | ||
test_onnx_conformance_layer_filter__halide_denylist.inl.hpp | ||
test_onnx_conformance_layer_filter__openvino.inl.hpp | ||
test_onnx_conformance_layer_filter__vulkan_denylist.inl.hpp | ||
test_onnx_conformance_layer_filter_opencv_all_denylist.inl.hpp | ||
test_onnx_conformance_layer_filter_opencv_cpu_denylist.inl.hpp | ||
test_onnx_conformance_layer_filter_opencv_denylist.inl.hpp | ||
test_onnx_conformance_layer_filter_opencv_ocl_fp16_denylist.inl.hpp | ||
test_onnx_conformance_layer_filter_opencv_ocl_fp32_denylist.inl.hpp | ||
test_onnx_conformance_layer_parser_denylist.inl.hpp | ||
test_onnx_conformance.cpp | ||
test_onnx_importer.cpp | ||
test_precomp.hpp | ||
test_tf_importer.cpp | ||
test_tflite_importer.cpp | ||
test_torch_importer.cpp |