انتقل إلى المحتوى

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 و ONNX وقت التشغيل

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 يعمل وقت التشغيل على تحسين تنفيذ ONNX النماذج من خلال الاستفادة من القدرات الخاصة بالأجهزة. يسمح هذا التحسين للنماذج بالعمل بكفاءة وأداء عال على منصات الأجهزة المختلفة ، بما في ذلك وحدات المعالجة المركزية ووحدات معالجة الرسومات والمسرعات المتخصصة.

ONNX مع ONNX وقت التشغيل

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

الميزات الرئيسية ل ONNX نماذج

قدرة ONNX للتعامل مع أشكال مختلفة يمكن أن يعزى إلى الميزات الرئيسية التالية:

  • تمثيل النموذج المشترك: ONNX يحدد مجموعة مشتركة من العوامل (مثل التلافيف والطبقات وما إلى ذلك) وتنسيق بيانات قياسي. عند تحويل نموذج إلى ONNX يتم ترجمة الشكل وهندسته المعمارية وأوزانه إلى هذا التمثيل المشترك. يضمن هذا التوحيد إمكانية فهم النموذج من خلال أي إطار يدعم ONNX.

  • تعيين الإصدار والتوافق مع الإصدارات السابقة: ONNX يحافظ على نظام إصدار لمشغليه. هذا يضمن أنه حتى مع تطور المعيار ، تظل النماذج التي تم إنشاؤها في الإصدارات القديمة قابلة للاستخدام. يعد التوافق مع الإصدارات السابقة ميزة حاسمة تمنع النماذج من أن تصبح قديمة بسرعة.

  • تمثيل النموذج القائم على الرسم البياني: ONNX يمثل النماذج كرسوم بيانية حسابية. هذه البنية القائمة على الرسم البياني هي طريقة عالمية لتمثيل نماذج التعلم الآلي ، حيث تمثل العقد العمليات أو الحسابات ، وتمثل الحواف الموترات المتدفقة بينها. هذا التنسيق قابل للتكيف بسهولة مع الأطر المختلفة التي تمثل أيضا النماذج كرسوم بيانية.

  • الأدوات والنظام البيئي: هناك نظام بيئي غني بالأدوات حولها ONNX التي تساعد في تحويل النموذج والتصور والتحسين. تسهل هذه الأدوات على المطورين العمل معها ONNX النماذج وتحويل النماذج بين الأطر المختلفة بسلاسة.

الاستخدام الشائع ل 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 النشر

ONNX غالبًا ما يتم نشر النماذج على وحدات المعالجة المركزية نظرًا لتوافقها مع ONNX وقت التشغيل. تم تحسين وقت التشغيل هذا للتنفيذ CPU . وهو يحسّن سرعة الاستدلال بشكل كبير ويجعل نشر CPU في الوقت الفعلي أمراً ممكناً.

خيارات النشر المدعومة

بينما ONNX تستخدم النماذج بشكل شائع على وحدات المعالجة المركزية ، ويمكن أيضا نشرها على الأنظمة الأساسية التالية:

  • GPU التسريع: يدعم ONNX بشكل كامل تسريع GPU ، خاصةً NVIDIA CUDA . يتيح ذلك التنفيذ الفعال على وحدات معالجة الرسومات NVIDIA للمهام التي تتطلب قوة حسابية عالية.

  • الحافة والأجهزة المحمولة: ONNX يمتد إلى أجهزة الحافة والأجهزة المحمولة ، مما يجعله مثاليا لسيناريوهات الاستدلال على الجهاز وفي الوقت الفعلي. إنه خفيف الوزن ومتوافق مع أجهزة الحافة.

  • متصفحات الويب: ONNX يمكن تشغيلها مباشرة في متصفحات الويب ، مما يؤدي إلى تشغيل تطبيقات الذكاء الاصطناعي التفاعلية والديناميكية المستندة إلى الويب.

Exporting YOLO11 Models to ONNX

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

تركيب

لتثبيت الحزمة المطلوبة ، قم بتشغيل:

تركيب

# 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.

استخدام

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.

استخدام

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'

لمزيد من التفاصيل حول عملية التصدير ، قم بزيارة Ultralytics صفحة التوثيق الخاصة بالتصدير.

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:

ملخص

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.

لمزيد من التفاصيل حول الاستخدام ، قم بزيارة ONNX الوثائق الرسمية.

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.

الأسئلة المتداولة

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

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

استخدام

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'

لمزيد من التفاصيل، يرجى زيارة وثائق التصدير.

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

Using ONNX Runtime for deploying YOLO11 models offers several advantages:

  • التوافق عبر المنصات المختلفة: ONNX يدعم وقت التشغيل العديد من الأنظمة الأساسية، مثل ويندوز وماك ولينكس، مما يضمن تشغيل نماذجك بسلاسة في بيئات مختلفة.
  • تسريع الأجهزة: ONNX يمكن لوقت التشغيل الاستفادة من التحسينات الخاصة بالأجهزة لوحدات المعالجة المركزية ووحدات معالجة الرسومات والمسرّعات المخصصة، مما يوفر استدلالاً عالي الأداء.
  • Framework interoperability: Models trained in popular frameworks like PyTorch or TensorFlow can be easily converted to ONNX format and run using ONNX Runtime.

تعرف على المزيد من خلال مراجعة وثائق وقت التشغيل ONNX .

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

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

  • وحدات المعالجة المركزية: استخدام ONNX وقت التشغيل للاستدلال الأمثل CPU الاستدلال.
  • وحدات معالجة الرسومات: الاستفادة من NVIDIA CUDA لتسريع GPU عالي الأداء .
  • أجهزة الحافة: تشغيل نماذج خفيفة الوزن على الأجهزة المتطورة والأجهزة المحمولة للاستدلال في الوقت الحقيقي على الجهاز.
  • متصفحات الويب: تنفيذ النماذج مباشرةً داخل متصفحات الويب للتطبيقات التفاعلية المستندة إلى الويب.

لمزيد من المعلومات، استكشف دليلنا حول خيارات نشر النموذج.

Why should I use ONNX format for Ultralytics YOLO11 models?

Using ONNX format for Ultralytics YOLO11 models provides numerous benefits:

  • قابلية التشغيل البيني: ONNX يسمح بنقل النماذج بين أطر التعلم الآلي المختلفة بسلاسة.
  • تحسين الأداء: ONNX يمكن لوقت التشغيل تحسين أداء النموذج من خلال استخدام التحسينات الخاصة بالأجهزة.
  • المرونة: يدعم ONNX بيئات نشر مختلفة، مما يتيح لك استخدام نفس النموذج على منصات مختلفة دون تعديل.

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. تحقق من تثبيت الإصدار الصحيح من التبعيات المطلوبة.
  2. راجع وثائقONNX الرسمية لمعرفة المشغلات والميزات المدعومة.
  3. راجع رسائل الخطأ للحصول على أدلة واستشر دليل المشكلات الشائعةUltralytics .

إذا استمرت المشاكل، اتصل بالدعم Ultralytics للحصول على مزيد من المساعدة.

📅 Created 9 months ago ✏️ Updated 22 days ago

التعليقات