All Projects → doleron → yolov5-opencv-cpp-python

doleron / yolov5-opencv-cpp-python

Licence: MIT license
Example of using ultralytics YOLO V5 with OpenCV 4.5.4, C++ and Python

Programming Languages

python
139335 projects - #7 most used programming language
C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to yolov5-opencv-cpp-python

epic-awesome-gamer
🍷 Gracefully claim weekly free games and monthly content from Epic Store.
Stars: ✭ 600 (+391.8%)
Mutual labels:  yolov5
food-detection-yolov5
🍔🍟🍗 Food analysis baseline with Theseus. Integrate object detection, image classification and multi-class semantic segmentation. 🍞🍖🍕
Stars: ✭ 68 (-44.26%)
Mutual labels:  yolov5
dofbot-jetson nano
Yahboom DOFBOT AI Vision Robotic Arm with ROS for Jetson NANO 4GB B01
Stars: ✭ 24 (-80.33%)
Mutual labels:  yolov5
deep utils
An open-source toolkit which is full of handy functions, including the most used models and utilities for deep-learning practitioners!
Stars: ✭ 73 (-40.16%)
Mutual labels:  yolov5
yolov5 obb
yolov5 + csl_label.(Oriented Object Detection)(Rotation Detection)(Rotated BBox)基于yolov5的旋转目标检测
Stars: ✭ 1,105 (+805.74%)
Mutual labels:  yolov5
ros-yolo-sort
YOLO v3, v4, v5, v6, v7 + SORT tracking + ROS platform. Supporting: YOLO with Darknet, OpenCV(DNN), OpenVINO, TensorRT(tkDNN). SORT supports python(original) and C++. (Not Deep SORT)
Stars: ✭ 162 (+32.79%)
Mutual labels:  yolov5
pytorch YOLO OpenVINO demo
No description or website provided.
Stars: ✭ 73 (-40.16%)
Mutual labels:  yolov5
JSON2YOLO
Convert JSON annotations into YOLO format.
Stars: ✭ 222 (+81.97%)
Mutual labels:  yolov5
pylabel
Python library for computer vision labeling tasks. The core functionality is to translate bounding box annotations between different formats-for example, from coco to yolo.
Stars: ✭ 171 (+40.16%)
Mutual labels:  yolov5
dockerfile-yolov5-jetson
Dockerfile for yolov5 inference on NVIDIA Jetson
Stars: ✭ 30 (-75.41%)
Mutual labels:  yolov5
Vehicle-Detection
Vehicle Detection Using Deep Learning and YOLO Algorithm
Stars: ✭ 96 (-21.31%)
Mutual labels:  yolov5
YOLO-Streaming
Push-pull streaming and Web display of YOLO series
Stars: ✭ 56 (-54.1%)
Mutual labels:  yolov5
yolov5 cpp openvino
用c++实现了yolov5使用openvino的部署
Stars: ✭ 222 (+81.97%)
Mutual labels:  yolov5
reflective-clothes-detect-yolov5
reflective-clothes-detect-dataset、helemet detection yolov5、工作服(反光衣)检测数据集、安全帽检测、施工人员穿戴检测
Stars: ✭ 295 (+141.8%)
Mutual labels:  yolov5
yolov5 deepsort tensorrt
This repo uses YOLOv5 and DeepSORT to implement object tracking algorithm. Also using TensorRTX to transform model to engine, and deploying all code on the NVIDIA Xavier with TensorRT further.
Stars: ✭ 117 (-4.1%)
Mutual labels:  yolov5
Object-Detection-Knowledge-Distillation
An Object Detection Knowledge Distillation framework powered by pytorch, now having SSD and yolov5.
Stars: ✭ 189 (+54.92%)
Mutual labels:  yolov5
yolov5 ROS
ROS使用YOLOv5 run YOLOv5 in ROS
Stars: ✭ 77 (-36.89%)
Mutual labels:  yolov5
make-your-yolov5 dataset
💥Make your yolov5 dataset by using labelimg.I hope my work can help you make your yolov5 datasets more quickly.
Stars: ✭ 60 (-50.82%)
Mutual labels:  yolov5
yolov5-dnn-cpp-python
用opencv的dnn模块做yolov5目标检测,包含C++和Python两个版本的程序
Stars: ✭ 326 (+167.21%)
Mutual labels:  yolov5
yolov5 tensorrt int8
TensorRT int8 量化部署 yolov5s 模型,实测3.3ms一帧!
Stars: ✭ 112 (-8.2%)
Mutual labels:  yolov5

yolov5-opencv-cpp-python

Example of performing inference with ultralytics YOLO V5, OpenCV 4.5.4 DNN, C++ and Python

Looking for YOLO V4 OpenCV C++/Python inference? Check this repository

Code explanation

This code is explained in this medium article

Example of YOLO v5 detection on video file

Prerequisites

Make sure you have already on your system:

  • Any modern Linux OS (tested on Ubuntu 20.04)
  • OpenCV 4.5.4+
  • Python 3.7+ (only if you are intended to run the python program)
  • GCC 9.0+ (only if you are intended to run the C++ program)

IMPORTANT!!! Note that OpenCV versions prior to 4.5.4 will not work at all.

Running the python script

The python code is here.

git clone https://github.com/doleron/yolov5-opencv-cpp-python.git
cd yolov5-opencv-cpp-python
python python/yolo.py 

If your machine/OpenCV install are CUDA capable you can try out running using the GPU:

git clone https://github.com/doleron/yolov5-opencv-cpp-python.git
cd yolov5-opencv-cpp-python
python python/yolo.py cuda

Running the C++ program

The C++ code is here.

git clone https://github.com/doleron/yolov5-opencv-cpp-python.git
cd yolov5-opencv-cpp-python
g++ -O3 cpp/yolo.cpp -o yolo_example `pkg-config --cflags --libs opencv4`
./yolo_example

Or using CUDA if available:

git clone https://github.com/doleron/yolov5-opencv-cpp-python.git
cd yolov5-opencv-cpp-python
g++ -O3 cpp/yolo.cpp -o yolo_example `pkg-config --cflags --libs opencv4`
./yolo_example cuda

running the examples

PS.: Video sample from https://www.youtube.com/watch?v=NyLF8nHIquM

Which YOLO version should I use?

This repository uses YOLO V5 but it is not the only YOLO version out there. You can read this article to learn more about YOLO versions and choose the more suitable one for you.

Exporting yolo v5 models to .onnx format

Check here: ultralytics/yolov5#251

My commands were:

git clone https://github.com/ultralytics/yolov5
cd yolov5
pip install -r requirements.txt

And then to convert the model:

$ python3 export.py --weights yolov5n.pt --img 640 --include onnx
export: data=data/coco128.yaml, weights=['yolov5n.pt'], imgsz=[640], batch_size=1, device=cpu, half=False, inplace=False, train=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=12, verbose=False, workspace=4, nms=False, agnostic_nms=False, topk_per_class=100, topk_all=100, iou_thres=0.45, conf_thres=0.25, include=['onnx']
YOLOv5 🚀 v6.0-192-g436ffc4 torch 1.10.1+cu102 CPU

Fusing layers... 
Model Summary: 213 layers, 1867405 parameters, 0 gradients

PyTorch: starting from yolov5n.pt (4.0 MB)

ONNX: starting export with onnx 1.10.2...
/home/user/workspace/smartcam/yolov5/models/yolo.py:57: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  if self.onnx_dynamic or self.grid[i].shape[2:4] != x[i].shape[2:4]:
ONNX: export success, saved as yolov5n.onnx (7.9 MB)

Export complete (1.33s)
Results saved to /home/doleron/workspace/smartcam/yolov5
Visualize with https://netron.app
Detect with `python detect.py --weights yolov5n.onnx` or `model = torch.hub.load('ultralytics/yolov5', 'custom', 'yolov5n.onnx')
Validate with `python val.py --weights yolov5n.onnx`
$ 

throubleshooting

First time I got a error with protobuf version:

"AttributeError: module 'google.protobuf.descriptor' has no attribute '_internal_create_key"?

I fixed it by running:

pip install --upgrade protobuf

References

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].