YOLOv5 is a popular detector by Ultralytics. This project implements the YOLOv5 object detector in C++ utilizing the ONNX Runtime to speed up inference performance.
- Supports both image and video inference.
- Faster CPU inference speeds.
- Supports dynamic input sizes.
The following instructions demonstrates how to build this project on a Linux system. Windows is currently not supported by the DeepSparse library.
-
CMake v3.8+ - found at https://cmake.org/
-
MSVC 2017++ (Windows Build) or GCC/G++ compiler (Linux Build)
-
Python 3.8+ - Python is used to install the deepsparse library which is required for the build. Download here.
-
OpenCV v4.0+ - Download here.
-
ONNX Runtime v1.5.1+ - Download here.
-
Set the
OpenCV_DIR
environment variable to point to your../../opencv/build
directory (if not set). -
Set the
ONNX_INCLUDE_DIR
to point the ONNX runtime header filesdirectory. -
Set the
ONNX_LIB_DIR
to point the ONNX runtime lib directory. -
Run the following build commands: a. [Windows] VS Developer Command Prompt:
cd \d <yolov5-onnx-cpp-directory> cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release cd build MSBuild yolov5-onnx-cpp.sln /property:Configuration=Release
b. [Linux] Bash:
cd <yolov5-onnx-cpp-directory> cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release cd build make
-
The compiled
.exe
will be inside theRelease
folder for Windows build, while the executable will be in root folder for Linux build.
-
Clone the YOLOv5 repo and install the dependencies.
-
Export the ONNX file:
python export.py --weights=yolov5n.onnx --include onnx --dynamic
-
To run the inference, execute the following command:
yolov5-onnx-cpp --model <ONNX_MODEL_PATH> [-i <IMAGE_PATH> | -v <VIDEO_PATH>] [--labels <LABEL_PATH>] [--imgsz IMAGE_SIZE] [--iou-thresh IOU_THRESHOLD] [--score-thresh CONFIDENCE_THRESHOLD]
- Mohammed Yasin - @Y-T-G
Thanks to @Hyuto for his work on ONNX implementation of YOLO-NAS in C++ which was utilized in this project.
This project is licensed under the MIT License - see the LICENSE file for details.