Zum Inhalt springen

Ultralytics YOLO11 on NVIDIA Jetson using DeepStream SDK and TensorRT



Pass auf: How to Run Multiple Streams with DeepStream SDK on Jetson Nano using Ultralytics YOLO11

This comprehensive guide provides a detailed walkthrough for deploying Ultralytics YOLO11 on NVIDIA Jetson devices using DeepStream SDK and TensorRT. Here we use TensorRT to maximize the inference performance on the Jetson platform.

DeepStream auf NVIDIA Jetson

Hinweis

Diese Anleitung wurde sowohl mit dem Seeed Studio reComputer J4012 getestet, der auf dem NVIDIA Jetson Orin NX 16GB mit der JetPack-Version JP5.1.3 basiert, als auch mit dem Seeed Studio reComputer J1020 v2, der auf dem NVIDIA Jetson Nano 4GB mit der JetPack-Version JP4.6.4 basiert. Es wird erwartet, dass es mit der gesamten NVIDIA Jetson-Hardware-Reihe funktioniert, einschließlich der neuesten und der älteren.

Was ist NVIDIA DeepStream?

NVIDIA's DeepStream SDK is a complete streaming analytics toolkit based on GStreamer for AI-based multi-sensor processing, video, audio, and image understanding. It's ideal for vision AI developers, software partners, startups, and OEMs building IVA (Intelligent Video Analytics) apps and services. You can now create stream-processing pipelines that incorporate neural networks and other complex processing tasks like tracking, video encoding/decoding, and video rendering. These pipelines enable real-time analytics on video, image, and sensor data. DeepStream's multi-platform support gives you a faster, easier way to develop vision AI applications and services on-premise, at the edge, and in the cloud.

Voraussetzungen

Bevor Sie dieser Anleitung folgen:

Tipp

In dieser Anleitung haben wir die Debian-Paketmethode verwendet, um das DeepStream SDK auf dem Jetson-Gerät zu installieren. Sie können auch das DeepStream SDK auf Jetson (archiviert) besuchen, um auf ältere Versionen von DeepStream zuzugreifen.

DeepStream Configuration for YOLO11

Hier verwenden wir marcoslucianops/DeepStream-Yolo GitHub Repository, das NVIDIA DeepStream SDK Unterstützung für YOLO Modelle enthält. Wir danken marcoslucianops für seine Beiträge!

  1. Installieren von Abhängigkeiten

    pip install cmake
    pip install onnxsim
    
  2. Klonen Sie das folgende Repository

    git clone https://github.com/marcoslucianops/DeepStream-Yolo
    cd DeepStream-Yolo
    
  3. Download Ultralytics YOLO11 detection model (.pt) of your choice from YOLO11 releases. Here we use yolov8s.pt.

    wget https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8s.pt
    

    Hinweis

    You can also use a custom trained YOLO11 model.

  4. Modell konvertieren in ONNX

    python3 utils/export_yoloV8.py -w yolov8s.pt
    

    Übergeben Sie die folgenden Argumente an den obigen Befehl

    Verwenden Sie für DeepStream 6.0.1 opset 12 oder niedriger. Die Standardeinstellung ist 16.

    --opset 12
    

    So ändern Sie die Inferenzgröße (Standard: 640)

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

    Beispiel für 1280:

    -s 1280
    or
    -s 1280 1280
    

    Zur Vereinfachung der ONNX Modell (DeepStream >= 6.0)

    --simplify
    

    So verwenden Sie die dynamische Batch-Größe (DeepStream >= 6.1)

    --dynamic
    

    So verwenden Sie die statische Batchgröße (Beispiel für Batchgröße = 4)

    --batch 4
    
  5. Setze die CUDA Version entsprechend der installierten JetPack Version

    Für JetPack 4.6.4:

    export CUDA_VER=10.2
    

    Für JetPack 5.1.3:

    export CUDA_VER=11.4
    
  6. Kompilieren Sie die Bibliothek

    make -C nvdsinfer_custom_impl_Yolo clean && make -C nvdsinfer_custom_impl_Yolo
    
  7. Bearbeiten Sie die config_infer_primary_yoloV8.txt Datei entsprechend Ihrem Modell (für YOLOv8s mit 80 Klassen)

    [property]
    ...
    onnx-file=yolov8s.onnx
    ...
    num-detected-classes=80
    ...
    
  8. Bearbeiten Sie die deepstream_app_config Datei

    ...
    [primary-gie]
    ...
    config-file=config_infer_primary_yoloV8.txt
    
  9. Sie können die Videoquelle auch in deepstream_app_config Datei. Hier wird eine Standard-Videodatei geladen

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

Ausführen von Rückschlüssen

deepstream-app -c deepstream_app_config.txt

Hinweis

Es wird lange dauern, die TensorRT Engine-Datei, bevor Sie die Inferenz starten. Habt also bitte etwas Geduld.

YOLO11 with deepstream

Tipp

If you want to convert the model to FP16 precision, simply set model-engine-file=model_b1_gpu0_fp16.engine und network-mode=2 innerhalb config_infer_primary_yoloV8.txt

INT8 Kalibrierung

Wenn du die INT8-Präzision für die Inferenz verwenden möchtest, musst du die folgenden Schritte ausführen

  1. Garnitur OPENCV Umgebungsvariable

    export OPENCV=1
    
  2. Kompilieren Sie die Bibliothek

    make -C nvdsinfer_custom_impl_Yolo clean && make -C nvdsinfer_custom_impl_Yolo
    
  3. Laden Sie für das COCO-Dataset die val2017, extrahieren und nach DeepStream-Yolo Ordner

  4. Erstellen eines neuen Verzeichnisses für Kalibrierungsbilder

    mkdir calibration
    
  5. Führen Sie Folgendes aus, um 1000 zufällige Bilder aus dem COCO-Datensatz auszuwählen, um die Kalibrierung durchzuführen

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

    Hinweis

    NVIDIA recommends at least 500 images to get a good accuracy. On this example, 1000 images are chosen to get better accuracy (more images = more accuracy). You can set it from head -1000. For example, for 2000 images, head -2000. This process can take a long time.

  6. Erstellen Sie die calibration.txt Datei mit allen ausgewählten Bildern

    realpath calibration/*jpg > calibration.txt
    
  7. Festlegen von Umgebungsvariablen

    export INT8_CALIB_IMG_PATH=calibration.txt
    export INT8_CALIB_BATCH_SIZE=1
    

    Hinweis

    Höhere INT8_CALIB_BATCH_SIZE-Werte führen zu einer höheren Genauigkeit und schnelleren Kalibrierungsgeschwindigkeit. Stelle ihn entsprechend deinem GPU Speicher ein.

  8. Aktualisieren Sie die config_infer_primary_yoloV8.txt Datei

    Von

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

    An

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

Ausführen von Rückschlüssen

deepstream-app -c deepstream_app_config.txt

MultiStream-Einrichtung

Um mehrere Streams unter einer einzigen Deepstream-Anwendung einzurichten, können Sie die folgenden Änderungen an der deepstream_app_config.txt Datei

  1. Ändern Sie die Zeilen und Spalten, um eine Rasteranzeige entsprechend der Anzahl der gewünschten Streams zu erstellen. Zum Beispiel können wir für 4 Streams 2 Zeilen und 2 Spalten hinzufügen.

    [tiled-display]
    rows=2
    columns=2
    
  2. Garnitur num-sources=4 und fügen Sie uri aller 4 Streams

    [source0]
    enable=1
    type=3
    uri=<path_to_video>
    uri=<path_to_video>
    uri=<path_to_video>
    uri=<path_to_video>
    num-sources=4
    

Ausführen von Rückschlüssen

deepstream-app -c deepstream_app_config.txt
Multistream-Einrichtung

Benchmark-Ergebnisse

Die folgende Tabelle fasst zusammen, wie die YOLOv8s Modelle bei verschiedenen TensorRT Genauigkeitsstufen mit einer Eingabegröße von 640x640 auf NVIDIA Jetson Orin NX 16GB abschneiden.

ModellnamePräzisionInferenzzeit (ms/im)FPS
YOLOv8sFP3215.6364
FP167.94126
INT85.53181

Bestätigungen

Dieser Leitfaden wurde ursprünglich von unseren Freunden von Seeed Studio, Lakshantha und Elaine, erstellt.

FAQ

How do I set up Ultralytics YOLO11 on an NVIDIA Jetson device?

To set up Ultralytics YOLO11 on an NVIDIA Jetson device, you first need to install the DeepStream SDK compatible with your JetPack version. Follow the step-by-step guide in our Quick Start Guide to configure your NVIDIA Jetson for YOLO11 deployment.

What is the benefit of using TensorRT with YOLO11 on NVIDIA Jetson?

Using TensorRT with YOLO11 optimizes the model for inference, significantly reducing latency and improving throughput on NVIDIA Jetson devices. TensorRT provides high-performance, low-latency deep learning inference through layer fusion, precision calibration, and kernel auto-tuning. This leads to faster and more efficient execution, particularly useful for real-time applications like video analytics and autonomous machines.

Can I run Ultralytics YOLO11 with DeepStream SDK across different NVIDIA Jetson hardware?

Yes, the guide for deploying Ultralytics YOLO11 with the DeepStream SDK and TensorRT is compatible across the entire NVIDIA Jetson lineup. This includes devices like the Jetson Orin NX 16GB with JetPack 5.1.3 and the Jetson Nano 4GB with JetPack 4.6.4. Refer to the section DeepStream Configuration for YOLO11 for detailed steps.

How can I convert a YOLO11 model to ONNX for DeepStream?

To convert a YOLO11 model to ONNX format for deployment with DeepStream, use the utils/export_yoloV8.py Skript aus dem DeepStream-Yolo Repository.

Hier ist ein Beispielbefehl:

python3 utils/export_yoloV8.py -w yolov8s.pt --opset 12 --simplify

Weitere Informationen zur Modellkonvertierung findest du in unserem Abschnitt zum Modellexport.

What are the performance benchmarks for YOLO on NVIDIA Jetson Orin NX?

The performance of YOLO11 models on NVIDIA Jetson Orin NX 16GB varies based on TensorRT precision levels. For example, YOLOv8s models achieve:

  • FP32 Präzision: 15,63 ms/im, 64 FPS
  • FP16 Präzision: 7,94 ms/im, 126 FPS
  • INT8 Präzision: 5,53 ms/im, 181 FPS

These benchmarks underscore the efficiency and capability of using TensorRT-optimized YOLO11 models on NVIDIA Jetson hardware. For further details, see our Benchmark Results section.

📅 Created 3 months ago ✏️ Updated 22 days ago

Kommentare