Object detection implementation is inspired by hpc203/yolov7-opencv-onnxrun-cpp-py
This repository serves mostly as documentation for my personal use, demonstrating how to use ONNX and OpenCV with CMake on MacOS.
- Install dependencies:
$ brew install cmake
$ brew install onnxruntime
$ brew install opencv
-
If you are on ARM then you are good to go 🎉
-
If you are not using an ARM processor, download correct runtime 1.12.1 header files from the official GitHub repository.
-
Put onnxruntime files to
external/
-
Set
ONNXRUNTIME_ROOT
env variable to your onnxruntime folder name
- Install dependencies:
$ choco install cmake --pre
$ choco install opencv
- Download ONNX Runtime 1.12.1
- Extract and put onnxruntime folder to
external/onnxruntime-win-x64-1.12.1
- This example utilizes a custom-trained model. If you wish to train your own model, you can create a dataset using Roboflow and then use one of their official notebooks to perform the training. There are also many comprehensive tutorials in the official ultralytics/yolov5 repository
- You are free to use any model you prefer, but be sure to update the
class.names
file accordingly. Additionally, for instance segmentation, it is important to passSegNetConfig
with proper parameters.
100 epochs. Trained on YOLOv5n-640 models. Inference on M1 CPU takes ~40ms.
Object detection dataset information:
- 186 training images
- 57 validation images
- 25 test images
Instance segmentation dataset information:
- 540 training images (AUGMENTATION rotation: Between -15° and +15°)
- 53 validation images
- 28 test images