Zum Inhalt springen

ONNX Export for YOLO11 Models

Often, when deploying computer vision models, you'll need a model format that's both flexible and compatible with multiple platforms.

Exporting Ultralytics YOLO11 models to ONNX format streamlines deployment and ensures optimal performance across various environments. This guide will show you how to easily convert your YOLO11 models to ONNX and enhance their scalability and effectiveness in real-world applications.

ONNX und ONNX Laufzeit

ONNX, which stands for Open Neural Network Exchange, is a community project that Facebook and Microsoft initially developed. The ongoing development of ONNX is a collaborative effort supported by various organizations like IBM, Amazon (through AWS), and Google. The project aims to create an open file format designed to represent machine learning models in a way that allows them to be used across different AI frameworks and hardware.

ONNX models can be used to transition between different frameworks seamlessly. For instance, a deep learning model trained in PyTorch can be exported to ONNX format and then easily imported into TensorFlow.

ONNX

Alternatively, ONNX models can be used with ONNX Runtime. ONNX Runtime is a versatile cross-platform accelerator for machine learning models that is compatible with frameworks like PyTorch, TensorFlow, TFLite, scikit-learn, etc.

ONNX Runtime optimiert die Ausführung von ONNX Modellen, indem es hardwarespezifische Funktionen nutzt. Durch diese Optimierung können die Modelle effizient und mit hoher Leistung auf verschiedenen Hardware-Plattformen ausgeführt werden, darunter CPUs, GPUs und spezielle Beschleuniger.

ONNX mit ONNX Laufzeit

Whether used independently or in tandem with ONNX Runtime, ONNX provides a flexible solution for machine learning model deployment and compatibility.

Die wichtigsten Merkmale der ONNX Modelle

Die Fähigkeit von ONNX , mit verschiedenen Formaten umzugehen, lässt sich auf die folgenden Hauptmerkmale zurückführen:

  • Gemeinsame Modelldarstellung: ONNX definiert einen gemeinsamen Satz von Operatoren (wie Faltungen, Schichten usw.) und ein Standarddatenformat. Wenn ein Modell in das Format ONNX konvertiert wird, werden seine Architektur und Gewichte in diese gemeinsame Darstellung übersetzt. Diese Einheitlichkeit stellt sicher, dass das Modell von jedem Framework, das ONNX unterstützt, verstanden werden kann.

  • Versionierung und Rückwärtskompatibilität: ONNX unterhält ein Versionierungssystem für seine Betreiber. Dadurch wird sichergestellt, dass Modelle, die in älteren Versionen erstellt wurden, auch dann noch verwendbar sind, wenn sich der Standard weiterentwickelt. Die Rückwärtskompatibilität ist ein wichtiges Merkmal, das verhindert, dass Modelle schnell veraltet sind.

  • Graphenbasierte Modelldarstellung: ONNX stellt Modelle als Berechnungsgraphen dar. Diese graphenbasierte Struktur ist eine universelle Art der Darstellung von Modellen des maschinellen Lernens, bei der die Knoten Operationen oder Berechnungen und die Kanten die Tensoren darstellen, die zwischen ihnen fließen. Dieses Format lässt sich leicht an verschiedene Frameworks anpassen, die Modelle ebenfalls als Graphen darstellen.

  • Tools und Ökosystem: Rund um ONNX gibt es ein reichhaltiges Ökosystem von Tools, die bei der Modellkonvertierung, Visualisierung und Optimierung helfen. Diese Tools erleichtern den Entwicklern die Arbeit mit ONNX Modellen und die nahtlose Konvertierung von Modellen zwischen verschiedenen Frameworks.

Übliche Verwendung von ONNX

Before we jump into how to export YOLO11 models to the ONNX format, let's take a look at where ONNX models are usually used.

CPU Einsatz

ONNX Modelle werden aufgrund ihrer Kompatibilität mit ONNX Runtime häufig auf CPUs eingesetzt. Diese Runtime ist für die Ausführung von CPU optimiert. Sie verbessert die Inferenzgeschwindigkeit erheblich und ermöglicht den Einsatz von CPU in Echtzeit.

Unterstützte Bereitstellungsoptionen

Die Modelle von ONNX werden in der Regel auf CPUs verwendet, können aber auch auf den folgenden Plattformen eingesetzt werden:

  • GPU Beschleunigung: ONNX unterstützt vollständig GPU Beschleunigung, insbesondere NVIDIA CUDA . Dies ermöglicht eine effiziente Ausführung auf NVIDIA GPUs für Aufgaben, die eine hohe Rechenleistung erfordern.

  • Edge- und Mobilgeräte: ONNX ist auch für Edge- und Mobilgeräte geeignet und damit perfekt für On-Device- und Echtzeit-Inferenzszenarien. Es ist leichtgewichtig und kompatibel mit Edge-Hardware.

  • Webbrowser: ONNX kann direkt in Webbrowsern ausgeführt werden und ermöglicht so interaktive und dynamische webbasierte KI-Anwendungen.

Exporting YOLO11 Models to ONNX

You can expand model compatibility and deployment flexibility by converting YOLO11 models to ONNX format.

Installation

Um das benötigte Paket zu installieren, führe es aus:

Installation

# Install the required package for YOLO11
pip install ultralytics

For detailed instructions and best practices related to the installation process, check our YOLO11 Installation guide. While installing the required packages for YOLO11, if you encounter any difficulties, consult our Common Issues guide for solutions and tips.

Verwendung

Before diving into the usage instructions, be sure to check out the range of YOLO11 models offered by Ultralytics. This will help you choose the most appropriate model for your project requirements.

Verwendung

from ultralytics import YOLO

# Load the YOLO11 model
model = YOLO("yolo11n.pt")

# Export the model to ONNX format
model.export(format="onnx")  # creates 'yolo11n.onnx'

# Load the exported ONNX model
onnx_model = YOLO("yolo11n.onnx")

# Run inference
results = onnx_model("https://ultralytics.com/images/bus.jpg")
# Export a YOLO11n PyTorch model to ONNX format
yolo export model=yolo11n.pt format=onnx  # creates 'yolo11n.onnx'

# Run inference with the exported model
yolo predict model=yolo11n.onnx source='https://ultralytics.com/images/bus.jpg'

Weitere Informationen über den Exportprozess findest du auf der Dokumentationsseite zum Export unterUltralytics .

Deploying Exported YOLO11 ONNX Models

Once you've successfully exported your Ultralytics YOLO11 models to ONNX format, the next step is deploying these models in various environments. For detailed instructions on deploying your ONNX models, take a look at the following resources:

  • ONNX Laufzeit Python API Dokumentation: Dieser Leitfaden enthält wichtige Informationen zum Laden und Ausführen von ONNX Modellen mit ONNX Runtime.

  • Einsatz auf Edge-Geräten: Auf dieser Dokumentseite findest du verschiedene Beispiele für den Einsatz von ONNX Modellen auf Edge-Geräten.

  • ONNX Tutorials auf GitHub: Eine Sammlung umfassender Tutorials, die verschiedene Aspekte der Nutzung und Implementierung von ONNX Modellen in unterschiedlichen Szenarien behandeln.

Zusammenfassung

In this guide, you've learned how to export Ultralytics YOLO11 models to ONNX format to increase their interoperability and performance across various platforms. You were also introduced to the ONNX Runtime and ONNX deployment options.

Weitere Einzelheiten zur Verwendung findest du in der offiziellen DokumentationONNX .

Also, if you'd like to know more about other Ultralytics YOLO11 integrations, visit our integration guide page. You'll find plenty of useful resources and insights there.

FAQ

How do I export YOLO11 models to ONNX format using Ultralytics?

To export your YOLO11 models to ONNX format using Ultralytics, follow these steps:

Verwendung

from ultralytics import YOLO

# Load the YOLO11 model
model = YOLO("yolo11n.pt")

# Export the model to ONNX format
model.export(format="onnx")  # creates 'yolo11n.onnx'

# Load the exported ONNX model
onnx_model = YOLO("yolo11n.onnx")

# Run inference
results = onnx_model("https://ultralytics.com/images/bus.jpg")
# Export a YOLO11n PyTorch model to ONNX format
yolo export model=yolo11n.pt format=onnx  # creates 'yolo11n.onnx'

# Run inference with the exported model
yolo predict model=yolo11n.onnx source='https://ultralytics.com/images/bus.jpg'

Weitere Informationen findest du in der Exportdokumentation.

What are the advantages of using ONNX Runtime for deploying YOLO11 models?

Using ONNX Runtime for deploying YOLO11 models offers several advantages:

  • Plattformübergreifende Kompatibilität: ONNX Runtime unterstützt verschiedene Plattformen wie Windows, macOS und Linux und sorgt dafür, dass deine Modelle in unterschiedlichen Umgebungen reibungslos laufen.
  • Hardware-Beschleunigung: ONNX Die Laufzeitumgebung kann hardwarespezifische Optimierungen für CPUs, GPUs und spezielle Beschleuniger nutzen, um leistungsstarke Inferenzen zu ermöglichen.
  • Framework interoperability: Models trained in popular frameworks like PyTorch or TensorFlow can be easily converted to ONNX format and run using ONNX Runtime.

Weitere Informationen findest du in der ONNX Runtime-Dokumentation.

What deployment options are available for YOLO11 models exported to ONNX?

YOLO11 models exported to ONNX can be deployed on various platforms including:

  • CPUs: Die Nutzung von ONNX Runtime für optimierte CPU Inferenz.
  • GPUs: Die Nutzung von NVIDIA CUDA für eine leistungsstarke GPU Beschleunigung.
  • Edge-Geräte: Leichtgewichtige Modelle auf Edge- und Mobilgeräten für Echtzeit-Inferenzen auf dem Gerät.
  • Webbrowser: Ausführen von Modellen direkt in Webbrowsern für interaktive webbasierte Anwendungen.

Weitere Informationen findest du in unserem Leitfaden zu den Optionen für die Modellbereitstellung.

Why should I use ONNX format for Ultralytics YOLO11 models?

Using ONNX format for Ultralytics YOLO11 models provides numerous benefits:

  • Interoperabilität: ONNX ermöglicht die nahtlose Übertragung von Modellen zwischen verschiedenen Machine-Learning-Frameworks.
  • Leistungsoptimierung: ONNX Die Laufzeit kann die Modellleistung durch hardwarespezifische Optimierungen verbessern.
  • Flexibilität: ONNX unterstützt verschiedene Einsatzumgebungen, so dass du dasselbe Modell ohne Änderungen auf verschiedenen Plattformen verwenden kannst.

Refer to the comprehensive guide on exporting YOLO11 models to ONNX.

How can I troubleshoot issues when exporting YOLO11 models to ONNX?

When exporting YOLO11 models to ONNX, you might encounter common issues such as mismatched dependencies or unsupported operations. To troubleshoot these problems:

  1. Überprüfe, ob du die richtige Version der erforderlichen Abhängigkeiten installiert hast.
  2. In der offiziellen DokumentationONNX findest du die unterstützten Operatoren und Funktionen.
  3. Prüfe die Fehlermeldungen auf Hinweise und konsultiere den Ultralytics Leitfaden für häufige Probleme.

Wenn das Problem weiterhin besteht, wende dich an den Ultralytics Support, um weitere Unterstützung zu erhalten.

📅 Created 9 months ago ✏️ Updated 22 days ago

Kommentare