Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Example] Three threads inference in Yolov8 with Opencv DNN C++ loading Onnx, and Python. C++ in window10, Linux #10201

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

ZouJiu1
Copy link
Contributor

@ZouJiu1 ZouJiu1 commented Apr 21, 2024

  1. I have checked for Existing Contributions: Before submitting, my contribution is unique and complementary.

  2. No related issues.

directory: examples\YOLOv8-Threads-Cpp-Python-Video

Three threads inference in Yolov8 with Opencv DNN C++ loading Onnx, and Python.

C++ and Python, it all have three threads to cowork. each of them works independently. Like customer and producer.

  1. the first thread reads video frame;

  2. the second thread predict the frame;

  3. the third thread plot the prediction result to the frame and save it to video;

Reading video thread is a producer, predicting the frame thread is a customer. Then predicting the frame thread will give a prediction result, now it is a producer, ploting and saving thread is a customer. To write these function, we need a queue which is safe between different threads. Python have a Queue which is thread-safe in queue package. C++ doesn't provide such thread-safe queue, so I write a thread-safe queue by myself.

I have read the CLA Document and I sign the CLA

I also have read the examples/README.md

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Introducing multi-threaded video processing for YOLOv8 in both C++ and Python.

📊 Key Changes

  • Added a comprehensive guide and example for implementing a three-threaded inference model using YOLOv8, with support for both C++ and Python.
  • Demonstrated thread-safe queue implementations to manage data flow between reading, predicting, and writing video frames.
  • Provided detailed setup instructions for exporting YOLOv8 models, configuring environment variables, and compiling code in Windows and Linux.
  • Included class labels for object detection and inference scripts that incorporate multi-threading for improved processing performance.

🎯 Purpose & Impact

  • 🚀 Enhances Efficiency: Utilizes multi-threading to significantly speed up video processing by paralleling video frame reading, prediction, and writing.
  • 🛠 Promotes Cross-platform Compatibility: Offers detailed setup and run instructions for both Windows and Linux, ensuring broad accessibility.
  • Facilitates Model Exportation: Simplifies the process of exporting YOLOv8 models to ONNX format, enabling seamless integration into the video processing pipeline.
  • 📝 Thread-Safety: Implements a custom thread-safe queue in C++ and leverages Python’s queue module, ensuring data integrity across threads.

Overall, this update is set to markedly improve the speed and efficiency of video processing tasks using YOLOv8, making it more accessible across different platforms and even to those with limited multi-threading experience.

Copy link

codecov bot commented Apr 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.60%. Comparing base (8d17af7) to head (2e4d986).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10201      +/-   ##
==========================================
- Coverage   74.77%   70.60%   -4.18%     
==========================================
  Files         122      122              
  Lines       15634    15634              
==========================================
- Hits        11690    11038     -652     
- Misses       3944     4596     +652     
Flag Coverage Δ
Benchmarks 35.50% <ø> (-0.04%) ⬇️
GPU 37.28% <ø> (-5.65%) ⬇️
Tests 66.75% <ø> (-3.66%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants