← Work

YOLOs-CPP

C++ inference engine for the YOLO family: one API from YOLOv5 to YOLO26 for detection, segmentation, pose, OBB, classification and depth. No Python in the inference path

Creator & Maintainer · 2024 · active · GitHub ↗ · Demo ↗

Problem

Running YOLO in robotics and embedded systems typically means a Python runtime, a subprocess boundary, and latency you can’t budget. The ONNX ecosystem promised cross-platform inference, but the reference implementations were Python-first. Teams either lived with the Python overhead or rewrote from scratch every time a new YOLO version dropped.

The deeper problem: YOLO versions v5 through v12 have incompatible output formats. Each update broke existing C++ wrappers. Projects using detection today and adding segmentation tomorrow had to touch two separate codebases.

Approach

One unified API for every supported YOLO version and task. Include yolos/yolos.hpp, link ONNX Runtime and OpenCV, construct a detector from a model path and call detect(frame). The same pattern covers detection, segmentation, pose, oriented bounding boxes, classification, metric depth and YOLOE open-vocabulary models: switching task types is a one-line change. Version 1.0.0 consolidated the early per-task headers into this modular library; version 1.1.0 added depth estimation, batch inference and loading models straight from memory.

Model-agnostic output parsing handles differences between YOLO output formats internally. Adding v12 support required touching only the parser, not any caller code.

Architecture

Each header encapsulates: ONNX session initialisation, pre-processing (resize, normalise, NCHW conversion), inference, and post-processing (NMS, coordinate rescaling). GPU execution paths use the ONNX Runtime CUDA execution provider when available; the same binary falls back to CPU without recompilation.

Quantized models (INT8/FP16) load identically to FP32: no code changes needed. Sample pipelines cover image files, video streams, and live camera feeds via OpenCV VideoCapture. 50 Ultralytics-parity tests and 57 self-contained tests run in CI.

Results

Measured on Intel i7-12700H / RTX 3060, 640×640 input, YOLOv11n model:

Backend FPS Latency Memory
CPU 15 FPS 67 ms 48 MB
CUDA (GPU) 97 FPS 10 ms 412 MB

Additional GPU benchmarks (RTX 3060, 640×640):

Model FPS
YOLOv8n 86 FPS
YOLO26n 78 FPS
YOLOv11n-seg 65 FPS
YOLOv11n-pose 80 FPS
  • Supports YOLOv5 through YOLO26 across detection, segmentation, OBB, pose, classification and depth, plus YOLOE open-vocabulary detection and segmentation
  • Zero Python in the inference path: deterministic latency on embedded hardware
  • Used in production robotics perception and industrial inspection

Lessons

Post-processing is where version differences live. YOLO v8 switched from anchor-based to anchor-free heads; v10 added NMS-free variants. Keeping the pre/post-processing logic inside each header rather than a shared base class made these changes easier to isolate and test without regressions.

Keeping one header per task worked for the early releases, but every new task duplicated plumbing. Version 1.0.0 moved to a modular library behind one API, so new tasks such as depth and YOLOE plug in without touching caller code.

Stack

  • C++17
  • ONNX Runtime 1.x
  • OpenCV 4.x
  • CUDA (optional)
  • CMake

Technologies

  • C++17
  • ONNX Runtime
  • OpenCV
  • CUDA
  • YOLOv5 to YOLO26
  • Quantization (INT8/FP16)