Meet YOLO26: next-gen vision AI.

Link to this section在 NVIDIA Jetson 上使用 DeepStream SDK 和 TensorRT 运行 Ultralytics YOLO26#



Watch: How to use Ultralytics YOLO26 models with NVIDIA Deepstream on Jetson Orin NX 🚀

本综合指南详细介绍了如何使用 DeepStream SDK 和 TensorRT 在 NVIDIA Jetson 设备上部署 Ultralytics YOLO26。我们在此使用 TensorRT 来最大化 Jetson 平台上的推理性能。

本指南介绍了 DeepStream YOLO26 配置INT8 校准多路流设置 以及 基准测试结果

NVIDIA DeepStream SDK on Jetson platform
注意

This guide has been tested with NVIDIA Jetson Orin Nano Super Developer Kit running the latest stable JetPack release of JP6.1, Seeed Studio reComputer J4012 which is based on NVIDIA Jetson Orin NX 16GB running JetPack release of JP5.1.3 and Seeed Studio reComputer J1020 v2 which is based on NVIDIA Jetson Nano 4GB running JetPack release of JP4.6.4. It is expected to work across all the NVIDIA Jetson hardware lineup including latest and legacy.

Link to this section什么是 NVIDIA DeepStream?#

NVIDIA DeepStream SDK 是一个基于 GStreamer 的完整流分析工具包,用于人工智能驱动的多传感器处理、视频、音频和图像理解。它非常适合从事 IVA(智能视频分析)应用和服务开发的视觉 AI 开发者、软件合作伙伴、初创公司和 OEM。你现在可以创建集成神经网络及跟踪、视频编码/解码和视频渲染等复杂处理任务的流处理管道。这些管道能够对视频、图像和传感器数据进行实时分析。DeepStream 的多平台支持为你提供了一种更快速、更简便的方法,以便在本地、边缘和云端开发视觉 AI 应用和服务。

Link to this section前提条件#

在开始学习本指南之前:

提示

在本指南中,我们使用了 Debian 包方法将 DeepStream SDK 安装到 Jetson 设备上。你还可以访问 DeepStream SDK on Jetson (Archived) 以获取旧版本的 DeepStream。

Link to this sectionYOLO26 的 DeepStream 配置#

在这里,我们使用 marcoslucianops/DeepStream-Yolo GitHub 仓库,它包含了 NVIDIA DeepStream SDK 对 YOLO 模型的功能支持。我们感谢 marcoslucianops 所做的贡献!

  1. 安装 Ultralytics 及其必要的依赖项

    cd ~
    pip install -U pip
    git clone https://github.com/ultralytics/ultralytics
    cd ultralytics
    pip install -e ".[export]" onnxslim
  2. 克隆 DeepStream-Yolo 仓库

    cd ~
    git clone https://github.com/marcoslucianops/DeepStream-Yolo
  3. export_yolo26.py 文件从 DeepStream-Yolo/utils 目录复制到 ultralytics 文件夹中

    cp ~/DeepStream-Yolo/utils/export_yolo26.py ~/ultralytics
    cd ultralytics
  4. YOLO26 发布页面下载你选择的 Ultralytics YOLO26 检测模型 (.pt)。这里我们使用 yolo26s.pt

    wget https://github.com/ultralytics/assets/releases/download/v8.4.0/yolo26s.pt
注意

你也可以使用 自定义训练的 YOLO26 模型

  1. 将模型转换为 ONNX

    python3 export_yolo26.py -w yolo26s.pt
将以下参数传递给上述命令

对于 DeepStream 5.1,请删除 --dynamic 参数并使用 opset 12 或更低版本。默认的 opset 是 17。

--opset 12

要更改推理尺寸(默认:640)

-s SIZE
--size SIZE
-s HEIGHT WIDTH
--size HEIGHT WIDTH

1280 的示例:

-s 1280
or
-s 1280 1280

简化 ONNX 模型(适用于 DeepStream >= 6.0)

--simplify

使用动态批处理大小(适用于 DeepStream >= 6.1)

--dynamic

使用静态批处理大小(以批处理大小 = 4 为例)

--batch 4
  1. 将生成的 .onnx 模型文件和 labels.txt 文件复制到 DeepStream-Yolo 文件夹

    cp yolo26s.onnx labels.txt ~/DeepStream-Yolo
    cd ~/DeepStream-Yolo
  2. 根据已安装的 JetPack 版本设置 CUDA 版本

    对于 JetPack 4.6.4:

    export CUDA_VER=10.2

    对于 JetPack 5.1.3:

    export CUDA_VER=11.4

    对于 JetPack 6.1:

    export CUDA_VER=12.6
  3. 编译库

    make -C nvdsinfer_custom_impl_Yolo clean && make -C nvdsinfer_custom_impl_Yolo
  4. 根据你的模型编辑 config_infer_primary_yolo26.txt 文件(以具有 80 个类别的 YOLO26s 为例)

    [property]
    ...
    onnx-file=yolo26s.onnx
    ...
    num-detected-classes=80
    ...
    parse-bbox-func-name=NvDsInferParseYolo
    ...
YOLO26 精度设置

YOLO26 resizes the input with center padding and runs without NMS. For the best accuracy, add the following to the [property] section of config_infer_primary_yolo26.txt:

[property]
...
maintain-aspect-ratio=1
symmetric-padding=1
cluster-mode=4
...
  1. 编辑 deepstream_app_config 文件

    ...
    [primary-gie]
    ...
    config-file=config_infer_primary_yolo26.txt
  2. 你也可以在 deepstream_app_config 文件中更改视频源。此处加载了一个默认的视频文件

    ...
    [source0]
    ...
    uri=file:///opt/nvidia/deepstream/deepstream/samples/streams/sample_1080p_h264.mp4

Link to this section运行推理#

deepstream-app -c deepstream_app_config.txt
注意

在开始推理之前,生成 TensorRT 引擎文件需要较长时间,请耐心等待。

YOLO26 with deepstream
提示

If you want to convert the model to FP16 precision, simply set model-engine-file=model_b1_gpu0_fp16.engine and network-mode=2 inside config_infer_primary_yolo26.txt

Link to this sectionINT8 校准#

如果你想使用 INT8 精度进行推理,需要遵循以下步骤:

注意

目前 INT8 无法在 TensorRT 10.x 上工作。本节指南已在 TensorRT 8.x 上进行了测试,预计可以正常工作。

  1. 设置 OPENCV 环境变量

    export OPENCV=1
  2. 编译库

    make -C nvdsinfer_custom_impl_Yolo clean && make -C nvdsinfer_custom_impl_Yolo
  3. 对于 COCO 数据集,下载 val2017,解压并移动到 DeepStream-Yolo 文件夹

  4. 为校准图像创建一个新目录

    mkdir calibration
  5. 运行以下命令从 COCO 数据集中随机选择 1000 张图像进行校准

    for jpg in $(ls -1 val2017/*.jpg | sort -R | head -1000); do
      cp ${jpg} calibration/
    done
注意

NVIDIA 建议至少使用 500 张图像以获得良好的精度。在此示例中,选择了 1000 张图像以获得更高的精度(图像越多 = 精度越高)。你可以通过 head -1000 设置它。例如,对于 2000 张图像,使用 head -2000。此过程可能需要很长时间。

  1. 创建包含所有选定图像的 calibration.txt 文件

    realpath calibration/*jpg > calibration.txt
  2. 设置环境变量

    export INT8_CALIB_IMG_PATH=calibration.txt
    export INT8_CALIB_BATCH_SIZE=1
注意

较高的 INT8_CALIB_BATCH_SIZE 值将带来更高的精度和更快的校准速度。请根据你的 GPU 内存进行设置。

  1. 更新 config_infer_primary_yolo26.txt 文件

    ...
    model-engine-file=model_b1_gpu0_fp32.engine
    #int8-calib-file=calib.table
    ...
    network-mode=0
    ...

    ...
    model-engine-file=model_b1_gpu0_int8.engine
    int8-calib-file=calib.table
    ...
    network-mode=1
    ...

Link to this section运行 INT8 推理#

运行相同的命令来构建 INT8 引擎并开始推理:

deepstream-app -c deepstream_app_config.txt

Link to this section多流设置#



Watch: How to Run Multi-Stream Inference with Ultralytics YOLO26 using NVIDIA DeepStream on Jetson Orin 🚀

要在单个 DeepStream 应用程序下设置多个流,请对 deepstream_app_config.txt 文件进行以下更改:

  1. 更改行数和列数以根据你想要的流数量构建网格显示。例如,对于 4 个流,我们可以添加 2 行和 2 列。

    [tiled-display]
    rows=2
    columns=2
  2. 为每个流添加一个单独的 [sourceN] 组,并为其指定各自的 urinum-sources=1

    [source0]
    enable=1
    type=3
    uri=file:///path/to/video1.mp4
    num-sources=1
    
    [source1]
    enable=1
    type=3
    uri=file:///path/to/video2.mp4
    num-sources=1
    
    [source2]
    enable=1
    type=3
    uri=file:///path/to/video3.mp4
    num-sources=1
    
    [source3]
    enable=1
    type=3
    uri=file:///path/to/video4.mp4
    num-sources=1

Link to this section运行多路流推理#

运行相同的命令以在平铺显示器中启动所有流:

deepstream-app -c deepstream_app_config.txt
DeepStream multi-camera streaming configuration

Link to this section基准测试结果#

以下 基准测试 总结了 YOLO11 模型在 NVIDIA Jetson Orin NX 16GB 上以 640x640 输入尺寸、不同 TensorRT 精度级别下的性能表现。YOLO26 使用与上述相同的 DeepStream 导出和推理工作流程。

Link to this section对比图#

NVIDIA Jetson DeepStream performance benchmarks

Link to this section详细对比表#

性能
格式状态推理时间 (ms/im)
TensorRT (FP32)8.64
TensorRT (FP16)5.27
TensorRT (INT8)4.54

Link to this section致谢#

本指南最初由 Seeed Studio 的朋友 Lakshantha 和 Elaine 创建。

Link to this section常见问题解答#

Link to this section我该如何在 NVIDIA Jetson 设备上设置 Ultralytics YOLO26?#

要在 NVIDIA Jetson 设备上设置 Ultralytics YOLO26,你首先需要安装与你的 JetPack 版本兼容的 DeepStream SDK。请按照我们的快速入门指南中的分步说明配置你的 NVIDIA Jetson 以进行 YOLO26 部署。

Link to this section在 NVIDIA Jetson 上将 TensorRT 与 YOLO26 一起使用有什么好处?#

在 NVIDIA Jetson 设备上,将 TensorRT 与 YOLO26 结合使用可以优化推理模型,显著降低延迟并提高吞吐量。TensorRT 通过层融合、精度校准和内核自动调优,提供高性能、低延迟的深度学习推理。这实现了更快、更高效的执行,特别适用于视频分析和自动驾驶机器等实时应用。

Link to this section我可以跨不同的 NVIDIA Jetson 硬件运行带有 DeepStream SDK 的 Ultralytics YOLO26 吗?#

是的,本指南关于使用 DeepStream SDK 和 TensorRT 部署 Ultralytics YOLO26 的说明兼容整个 NVIDIA Jetson 产品系列。这包括配备 JetPack 5.1.3 的 Jetson Orin NX 16GB 以及配备 JetPack 4.6.4 的 Jetson Nano 4GB 等设备。有关详细步骤,请参阅YOLO26 的 DeepStream 配置一节。

Link to this section我该如何将 YOLO26 模型转换为 ONNX 以供 DeepStream 使用?#

To convert a YOLO26 model to ONNX format for deployment with DeepStream, use the utils/export_yolo26.py script from the DeepStream-Yolo repository.

以下是一个命令示例:

python3 utils/export_yolo26.py -w yolo26s.pt --opset 12 --simplify

有关模型转换的更多详细信息,请查看我们的模型导出部分

Link to this section如何在 DeepStream 上使用 YOLO26 运行 INT8 推理?#

To run INT8 inference, calibrate the model on a representative image set and switch the DeepStream config to INT8 mode. Download the COCO val2017 images, select around 1000 calibration images, set the INT8_CALIB_IMG_PATH and INT8_CALIB_BATCH_SIZE environment variables, then update config_infer_primary_yolo26.txt with model-engine-file=model_b1_gpu0_int8.engine, int8-calib-file=calib.table, and network-mode=1. See the INT8 Calibration section for the full steps. INT8 currently requires TensorRT 8.x.

Link to this section如何在 Jetson 上使用 DeepStream 运行多摄像头流?#

To process multiple streams in a single DeepStream application, edit the deepstream_app_config.txt file to add a tiled-display grid and list each source URI. Set the rows and columns under [tiled-display] to build the grid, add a separate [sourceN] group per stream with its own uri and num-sources=1, and adjust the grid to fit the number of streams. See the MultiStream Setup section for a complete example.

Link to this sectionNVIDIA Jetson Orin NX 上的 YOLO 性能基准测试结果如何?#

YOLO11 模型在 NVIDIA Jetson Orin NX 16GB 上的性能会根据 TensorRT 精度级别而有所不同。例如,YOLO11s 模型可达到:

  • FP32 精度:14.53 毫秒/图像,68.8 FPS
  • FP16 精度:7.91 毫秒/图像,126 FPS
  • INT8 精度:6.05 毫秒/图像,165 FPS

这些基准测试凸显了在 NVIDIA Jetson 硬件上使用 TensorRT 优化后的 YOLO11 模型的高效性和性能。欲了解更多详情,请参阅我们的 基准测试结果 部分。

评论