Improve YOLOv8 ONNX Runtime c++ example for all OS with CmakeList.txt support (#4274)

Signed-off-by: Onuralp SEZER <thunderbirdtr@fedoraproject.org>
Signed-off-by: Onuralp SEZER <thunderbirdtr@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
Onuralp SEZER 2023-08-10 18:51:19 +03:00 committed by GitHub
parent c9be1f3cce
commit 22474e9ad5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 179 additions and 53 deletions

View file

@ -2,8 +2,6 @@
This example demonstrates how to perform inference using YOLOv8 in C++ with ONNX Runtime and OpenCV's API.
We recommend using Visual Studio to build the project.
## Benefits
- Friendly for deployment in the industrial sector.
@ -25,13 +23,20 @@ model = YOLO("yolov8n.pt")
model.export(format="onnx", opset=12, simplify=True, dynamic=False, imgsz=640)
```
Alternatively, you can use the following command for exporting the model in the terminal
```bash
yolo export model=yolov8n.pt opset=12 simplify=True dynamic=False format=onnx imgsz=640,640
```
## Dependencies
| Dependency | Version |
| ----------------------- | -------- |
| Onnxruntime-win-x64-gpu | >=1.14.1 |
| OpenCV | >=4.0.0 |
| C++ | >=17 |
| Dependency | Version |
| -------------------------------- | -------- |
| Onnxruntime(linux,windows,macos) | >=1.14.1 |
| OpenCV | >=4.0.0 |
| C++ | >=17 |
| Cmake | >=3.5 |
Note: The dependency on C++17 is due to the usage of the C++17 filesystem feature.
@ -39,9 +44,9 @@ Note: The dependency on C++17 is due to the usage of the C++17 filesystem featur
```c++
// CPU inference
DCSP_INIT_PARAM params{ model_path, YOLO_ORIGIN_V8, {imgsz_w, imgsz_h}, class_num, 0.1, 0.5, false};
DCSP_INIT_PARAM params{ model_path, YOLO_ORIGIN_V8, {imgsz_w, imgsz_h}, 0.1, 0.5, false};
// GPU inference
DCSP_INIT_PARAM params{ model_path, YOLO_ORIGIN_V8, {imgsz_w, imgsz_h}, class_num, 0.1, 0.5, true};
DCSP_INIT_PARAM params{ model_path, YOLO_ORIGIN_V8, {imgsz_w, imgsz_h}, 0.1, 0.5, true};
// Load your image
cv::Mat img = cv::imread(img_path);