Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Abdurrahheem
Copy link
Contributor

@Abdurrahheem Abdurrahheem commented Jun 20, 2024

This PR adds sample support of YOLOv9 and YOLOv10) in OpenCV. Models for this test are located in this PR.

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 from official YOLOv10. Particularty follow this proceduce.
git clone [email protected]: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

  1. For inference part on OpenCV. one can use yolo_detector.cpp sample. If you have followed above exporting procedure, then you can use following command to run the model.
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

Running YOLOv9 using OpenCV

  1. Export model following official guideof the YOLOv9 repository. Particularly you can do following for converting.
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.

  1. Inference on OpenCV.
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

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • 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

@Abdurrahheem Abdurrahheem added this to the 4.11.0 milestone Jun 20, 2024
@Abdurrahheem Abdurrahheem requested review from asmorkalov and dkurt June 20, 2024 11:53
@Abdurrahheem Abdurrahheem self-assigned this Jun 20, 2024
@Abdurrahheem Abdurrahheem changed the title Add support of YOLOv10 in OpenCV Add sample support of YOLOv9 and YOLOv10 in OpenCV Jun 21, 2024
@asmorkalov
Copy link
Contributor

opencv_extra PR is missing.

@Abdurrahheem
Copy link
Contributor Author

opencv_extra PR is missing.

Just added. Here

@asmorkalov
Copy link
Contributor

Test and sample changes look good for me. What about Yolov10 export steps? I expect significant changes in the tutorial text.

@Abdurrahheem
Copy link
Contributor Author

Test and sample changes look good for me. What about Yolov10 export steps? I expect significant changes in the tutorial text.

Exprot steps are outline in this fork of yolov10 in GitHub. And the instruction for this are lacted in this READme

@asmorkalov
Copy link
Contributor

I propose to extend "PyTorch Model Export" for Yolov10 as soon as it's not trivial.

@asmorkalov asmorkalov marked this pull request as ready for review July 2, 2024 10:10
@rmsalinas
Copy link

Hi. results differ significantly (worse) from the original model.

Original model :

yolo predict model= models/yolov10s.pt source= ultralytics/assets/bus.jpg

_Ultralytics YOLOv8.1.34 🚀 Python-3.10.14 torch-2.0.1+cu117 CPU (13th Gen Intel Core(TM) i7-13700H)
YOLOv10s summary (fused): 293 layers, 8096880 parameters, 86880 gradients, 24.8 GFLOPs

image 1/1 /home/salinas/yolov10/ultralytics/assets/bus.jpg: 640x480 4 0s, 1 5, 1 11, 81.1ms
Speed: 1.4ms preprocess, 81.1ms inference, 1.0ms postprocess per image at shape (1, 3, 640, 480)
Results saved to /home/salinas/yolov10/runs/detect/predict5_

bus

Proposed model:
./example_dnn_yolo_detector --model=/home/salinas/yolov10_opencv/yolov10-ash-opencv-export/yolov10s.onnx -i=/home/salinas/yolov10/ultralytics/assets/bus.jpg --yolo=yolov10 --width=640 --height=480 --scale=0.003921568627 --padvalue=114 --thr=0.1

Yolo Object Detector_screenshot_09 08 2024

@CloudRobot
Copy link

infer error, incorrect frames are numerous ,in yolov9 and yolov10

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants