> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.stereolabs.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.stereolabs.com/_mcp/server.

# How to Export a YOLO Model to ONNX for ZED Custom Object Detection

## Introduction

This page shows you how to export a YOLO model to an ONNX file for use with the [ZED YOLO TensorRT inference example](/docs/integrations/yolo), or with the `CUSTOM_YOLOLIKE_BOX_OBJECTS` mode in the native ZED SDK Object Detection module.

This lets you train your own model using [Ultralytics YOLO (v5, v8, v10, v11, v12, and YOLO26)](https://docs.ultralytics.com/), [YOLOv6](https://github.com/meituan/YOLOv6), or [YOLOv7](https://github.com/WongKinYiu/yolov7).

You can also use the default model trained on the COCO dataset (80 classes) provided by the framework maintainers, or train a custom detector with the same architecture. The following tutorials walk you through the process of training a custom detector:

* YOLOv6: [https://github.com/meituan/YOLOv6/blob/main/docs/Train\_custom\_data.md](https://github.com/meituan/YOLOv6/blob/main/docs/Train_custom_data.md)
* YOLOv5: [https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data](https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data)
* Ultralytics (YOLOv8 and later): [https://docs.ultralytics.com/modes/train/](https://docs.ultralytics.com/modes/train/)

It enables the use of ZED 3D cameras with YOLO object detection, adding 3D localization and tracking to the most recent YOLO models using your own classes.

![YOLO latency-accuracy and FLOPs-accuracy trade-offs](/_fern-files/stereolabs.docs.buildwithfern.com/acfbd54a56d2263083ed05516e9cfa9f64b69bd826982b1185992e32a7c9ff49/docs/software-integration/yolo/images/tradeoff_turbo.svg)

YOLO Comparison in terms of latency-accuracy (left) and FLOPs-accuracy (right) trade-offs (from [YOLOv12](https://github.com/sunsmarterjie/yolov12))

## Workflow

The process is as follows:

1. Train your model or use an existing state-of-the-art (SOTA) model.
2. Export it into an ONNX file.
3. Load the ONNX file into the SDK or sample to generate an optimized model. This process uses the TensorRT framework to run inference and requires an initial step of inference engine generation.

ZED SDK samples are available on GitHub:

* [Custom detector sample](https://github.com/stereolabs/zed-sdk/tree/master/object%20detection/custom%20detector)
* [zed-yolo](https://github.com/stereolabs/zed-yolo)
* [ROS 2 custom Object Detection](/docs/integrations/ros-2/object-detection-and-tracking/)

> **Note**
>
> Keep track of the input resolution (`imgsz`) used at export time. A model exported with a fixed input size keeps it. For a model exported with `dynamic=True`, set `ObjectDetectionParameters::custom_onnx_dynamic_input_shape` to the square input resolution to use (default 512x512) when loading it with the native `CUSTOM_YOLOLIKE_BOX_OBJECTS` mode. The input size must be a multiple of 32 (e.g. 608 or 640).

## Ultralytics YOLO (v5, v8, v10, v11, v12, and YOLO26)

### Installing ultralytics

The `ultralytics` package can be installed directly from pip using the following command:

```sh
python -m pip install -U ultralytics
```

### ONNX file export

In this documentation, we use the Ultralytics CLI for export. See the [export mode documentation](https://docs.ultralytics.com/modes/export/) for the full list of options.

#### YOLO26

```sh
yolo export model=yolo26n.pt format=onnx simplify=True dynamic=False imgsz=608
```

> **Note**
>
> YOLO26 requires a recent `ultralytics` release (the 8.4.x series or newer). Older versions do not recognize the `yolo26` model name. Upgrade with `python -m pip install -U ultralytics` if needed.

#### YOLOv12

```sh
yolo export model=yolo12n.pt format=onnx simplify=True dynamic=False imgsz=608
```

#### YOLOv11

```sh
yolo export model=yolo11n.pt format=onnx simplify=True dynamic=False imgsz=608
```

#### YOLOv10

```sh
yolo export model=yolov10n.pt format=onnx simplify=True dynamic=False imgsz=608
```

#### YOLOv8

```sh
yolo export model=yolov8n.pt format=onnx simplify=True dynamic=False imgsz=608
```

#### YOLOv5 (YOLOv5u)

```sh
yolo export model=yolov5nu.pt format=onnx simplify=True dynamic=False imgsz=608
```

> **Note**
>
> The Ultralytics package only provides the anchor-free YOLOv5u models (`yolov5nu.pt`, `yolov5su.pt`, etc.; a `yolov5n.pt` name is automatically replaced by `yolov5nu.pt`). They use the YOLOv8 output format. To export a model trained with the original YOLOv5 repository, see [YOLOv5 (original repository)](#yolov5-original-repository).

### Variants

For each model, the variant (n, s, m, l, x) can be selected, for example:

```sh
yolo export model=yolo12x.pt format=onnx simplify=True dynamic=False imgsz=608
```

### Dynamic size

The model can also use dynamic dimensions:

```sh
yolo export model=yolo12m.pt format=onnx simplify=True dynamic=True
```

### Custom model

For a custom model, simply change the weight file:

```sh
yolo export model=yolov8l_custom_model.pt format=onnx simplify=True dynamic=False imgsz=512
```

Please refer to the corresponding documentation for more details [https://github.com/ultralytics/ultralytics](https://github.com/ultralytics/ultralytics)

## YOLOv6

The sample was mainly tested with YOLOv6 v3.0 but should work with other versions with minor or no modifications.

### Installing yolov6

YOLOv6 can be installed by cloning the repository and installing its requirements:

```sh
git clone https://github.com/meituan/YOLOv6
cd YOLOv6
pip install -r requirements.txt
pip install "onnx>=1.10.0"
```

### ONNX file export

```sh
wget https://github.com/meituan/YOLOv6/releases/download/0.3.0/yolov6s.pt
python ./deploy/ONNX/export_onnx.py \
    --weights yolov6s.pt \
    --img 640 \
    --batch 1 \
    --simplify
```

For a custom model, simply change the weight file:

```sh
python ./deploy/ONNX/export_onnx.py \
    --weights yolov6l_custom_model.pt \
    --img 640 \
    --batch 1 \
    --simplify
```

Please refer to the corresponding documentation for more details [https://github.com/meituan/YOLOv6/tree/main/deploy/ONNX](https://github.com/meituan/YOLOv6/tree/main/deploy/ONNX)

## YOLOv7

### Installing yolov7

YOLOv7 can be installed by cloning the repository and installing its requirements:

```sh
git clone https://github.com/WongKinYiu/yolov7.git
cd yolov7
python -m pip install -r requirements.txt
```

### ONNX file export

In this documentation, we'll use the export script `export.py`:

```sh
python export.py --weights ./yolov7-tiny.pt --grid --simplify --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640
```

> **Note**
>
> The `--end2end` option must NOT be used to run the inference with the ZED SDK for compatibility reasons.

For a custom model, simply change the weight file:

```sh
python export.py --weights ./yolov7_custom_model.pt --grid --simplify --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 512 512
```

Please refer to the corresponding documentation for more details [https://github.com/WongKinYiu/yolov7/tree/main?tab=readme-ov-file#export](https://github.com/WongKinYiu/yolov7/tree/main?tab=readme-ov-file#export)

## YOLOv5 (original repository)

### Installing yolov5

YOLOv5 can be installed by cloning the repository and installing its requirements:

```sh
git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install
```

### ONNX file export

```sh
python export.py --weights yolov5s.pt --include onnx --imgsz 640
```

For a custom model, simply change the weight file:

```sh
python export.py --weights yolov5l_custom_model.pt --include onnx
```

Please refer to the corresponding documentation for more details [https://docs.ultralytics.com/yolov5/](https://docs.ultralytics.com/yolov5/).