Introduction

  • Core idea - Use a ONNX file to represent the model, to be used in C++.

YOLOv5

Exporting as ONNX

Implementation in C++


YOLOv8

Exporting as ONNX

From the YOLOv8 github repo

from ultralytics import YOLO
 
# Load a model
model = YOLO("yolov8n.yaml")  # build a new model from scratch
model = YOLO("yolov8n.pt")  # load a pretrained model (recommended for training)
 
# Use the model
model.train(data="coco128.yaml", epochs=3)  # train the model
metrics = model.val()  # evaluate model performance on the validation set
results = model("https://ultralytics.com/images/bus.jpg")  # predict on an image
path = model.export(format="onnx")  # export the model to ONNX format

The last line exports the model as ONNX

Implementation in C++

  • An implementation by a random dude in this github repo.