Run YOLO inference in C++ or Python using ONNX model
Pic credit: Matthias Hangst/Getty Images
- OpenCV 4.7.0
- Python 3.10
- CMake 3.5.1
- C++ 17
- Tested Yolov5 & Yolov7 ONNX models
- Change the input image, class names, and model path in
src/yolo_inference.cpp
orsrc/yolo_inference.py
C++
- Clone the repository
- Create a build directory
- Run cmake
- Run make
git clone https://github.com/kvnptl/yolo-inference-onnx.git
cd yolo-inference-onnx
mkdir build
cd build
cmake ..
make
- Go to the build directory
- Run the executable
./yolo_inference
(OPTIONAL) Note: there is also a header file include/yolo_inference.hpp
which contains the inference function. You can use that function in your own code if you want.
Python
python3 src/yolo_inference.py