YOLOv10 Tutorial

This tutorial will guide you through using trtutils with YOLOv10 models. We will cover:

  1. Downloading ONNX weights from YOLOv10

  2. Building a TensorRT engine

  3. Running inference with the engine

Downloading ONNX Weights

YOLOv10 models can be automatically downloaded and converted to ONNX format using the trtutils CLI:

# Download and convert YOLOv10 models to ONNX
# Available models: yolov10n, yolov10s, yolov10m, yolov10l, yolov10x
$ python3 -m trtutils download --model yolov10n --output yolov10n.onnx --imgsz 640 --opset 17

# For other YOLOv10 variants
$ python3 -m trtutils download --model yolov10s --output yolov10s.onnx --imgsz 640 --opset 17

Building TensorRT Engine

Once you have the ONNX weights, you can build a TensorRT engine using trtutils:

# Note that build_yolo is not used since we exported the end2end model
# using the ONNX weights directly
python3 -m trtutils build \
    --onnx PATH_TO_WEIGHTS \
    --output PATH_TO_OUTPUT \
    --fp16

Alternatively, if you want to export the engine using the Python API:

from trtutils.builder import build_engine

# Build the engine with FP16 precision
build_engine(
    onnx="yolov10.onnx",
    output="yolov10.engine",
    fp16=True,
)

# For Jetson devices with DLA support
build_engine(
    onnx="yolov10.onnx",
    output="yolov10_dla.engine",
    int8=True,  # Orin series optimize for int8
    fp16=True,  # Can use fp16 on Xavier series
    dla_core=0,  # Use DLA core 0
)

Running Inference

The YOLO class provides a high-level interface for running YOLOv10 inference:

import cv2
from trtutils.models import YOLO, YOLOv10

# Load the YOLOv10 model
yolo = YOLO("yolov10.engine")

# OR, use the YOLOv10 class
yolo = YOLOv10("yolov10.engine")

# Read and process an image
img = cv2.imread("example.jpg")
detections = yolo.end2end(img)

# Print results
for bbox, confidence, class_id in detections:
    print(f"Class: {class_id}, Confidence: {confidence}")
    print(f"Bounding Box: {bbox}")