تصدير Sony IMX500
يُعد Sony IMX500 مستشعر صور مزودًا بمسرّع ذكاء اصطناعي على الشريحة من أجل الذكاء الاصطناعي الطرفي، ويُستخدم في كاميرا Raspberry Pi AI: تشغّل الكاميرا الشبكة بنفسها وترسل النتائج مع كل إطار إلى Raspberry Pi. يؤدي تصدير نموذج Ultralytics YOLO11n أو YOLOv8n باستخدام format="imx" إلى تكميمه إلى INT8 باستخدام مجموعة أدوات ضغط النماذج من Sony (MCT)، وتجميعه باستخدام محوّل IMX500، وكتابة مجلد يحمل اسم النموذج، مثل yolo11n_imx_model/ لـ yolo11n.pt أو yolov8n_imx_model/ لـ yolov8n.pt، ويحتوي على packerOut.zip، وهو النموذج المُجمّع الذي تنسخه إلى Raspberry Pi. عائلات النماذج الأخرى، بما فيها YOLO26، غير مدعومة، وكذلك الأحجام الأكبر، باستثناء نماذج s للتصنيف. يعمل التصدير على حاسوب Linux ولا يحتاج إلى كاميرا.
لمحة سريعة#
| الخاصية | التفاصيل |
|---|---|
وسيطة format | imx |
| المخرجات | <model>_imx_model/، مثل yolo11n_imx_model/، وهو مجلد يحتوي على packerOut.zip للكاميرا، وmodel_imx.onnx للاختبارات على حاسوب، وlabels.txt، راجع تنسيق الإخراج |
| يعمل على | مستشعر IMX500، الموجود مثلًا في كاميرا Raspberry Pi AI على Raspberry Pi 5 أو 4 Model B. يشغّل YOLO() model_imx.onnx على وحدة المعالجة المركزية في الحاسوب للتحقق من النموذج المُكمَّم |
| بيئة التشغيل | على Raspberry Pi: البرنامج الثابت IMX500 (imx500-all) ومكتبة وحدات التطبيق من Sony. على الحاسوب: ONNX Runtime مع عوامل تشغيل MCT |
| الدقة | INT8 فقط، ويُكمَّم باستخدام تكميم ما بعد التدريب من MCT على صور المعايرة من data. حجم YOLO11n للكشف هو 2.3 MB بصيغة packerOut.zip |
| جهاز التصدير | Linux مع Python 3.10 إلى 3.12 وJava 17 أو أحدث. لا يدعم macOS أو Windows. لا يحتاج التصدير إلى كاميرا؛ وعند توفر وحدة GPU من CUDA، فإنها تنفّذ التكميم |
يمكن لـ منصة Ultralytics تصدير نموذج YOLO11n أو YOLOv8n مدرّب إلى IMX500، لذا لن تحتاج إلى بيئة تصدير محلية.
البدء السريع#
ثبّت حزمة Ultralytics في بيئة افتراضية على جهاز Linux باستخدام Python 3.10 أو 3.11 أو 3.12. حدّث pip أولًا: لا يستطيع pip من الإصدار 24.0 إلى 25.0، بما في ذلك pip 24.0 الذي يضعه python3 -m venv في بيئة جديدة على Ubuntu 24.04، حلّ تبعيات حزم IMX:
python3 -m venv imx-env && source imx-env/bin/activate
pip install --upgrade pip
pip install ultralyticsيتطلب التصدير أيضًا Java 17 أو أحدث على PATH لتشغيل محوّل IMX500. تحقّق باستخدام java --version. ثبّته باستخدام sudo apt install openjdk-21-jre على Ubuntu وDebian 13 أو أحدث، أو openjdk-17-jre على Debian 12 وRaspberry Pi OS Bookworm؛ وفي غياب Java، يحاول التصدير تنفيذ هذا الأمر بنفسه، راجع القيود واستكشاف الأخطاء وإصلاحها. إذا لم يتوفر sudo، ففك ضغط أرشيف JDK، مثل Eclipse Temurin، في مجلدك الرئيسي وأضف مجلد bin إلى PATH، كما حدث لهذه الصفحة.
يثبّت أول تصدير IMX من Ultralytics مجموعة أدوات ضغط النماذج من Sony (model-compression-toolkit)، ومحوّل IMX500 (imx500-converter[pt])، وتبعياتهما، ويستبدل matplotlib بالإصدار 3.9.4 وnetworkx بالإصدار 3.0، وهما الإصداران اللذان تتطلبهما هذه الحزم. ويسجّل Restart runtime or rerun command for updates to take effect، لكنه يُكمل العملية في التشغيل نفسه. لم يثبّت التصدير الثاني شيئًا في البيئة نفسها.
لتثبيت كل هذه الحزم قبل أول تصدير من Ultralytics، مثلًا في صورة حاوية تعمل باستخدام YOLO_AUTOINSTALL=false، شغّل:
pip install "model-compression-toolkit>=2.4.1" "edge-mdt-cl>=1.1.0" "edge-mdt-tpc>=1.2.0" "pydantic<2.12" "imx500-converter[pt]>=3.18.2" "pulp<4"باستخدام هذه الحزم، لم يثبّت التصدير أي شيء عند تثبيت YOLO_AUTOINSTALL=false على Python 3.11 و3.12، كما نُفّذ التنبؤ والتحقق في البيئة نفسها. يحتاج التنبؤ إلى model-compression-toolkit وedge-mdt-cl وonnxruntime-extensions وonnx وonnxruntime؛ وعلى الحاسوب الذي يشغّل نموذجًا مُصدّرًا فقط، يثبّتها أول عملية تنبؤ، راجع النشر. يتطلب التصدير الإصدارات التالية:
| المتطلب | الإصدار |
|---|---|
| Python | من 3.10 إلى 3.12، كما تحقّق منه التصدير. أُجريت عمليات التصدير لهذه الصفحة باستخدام 3.10 و3.11 و3.12؛ راجع القيود واستكشاف الأخطاء وإصلاحها للإصدار 3.13 |
| PyTorch | لا يتحقق التصدير من الإصدار؛ تستخدم بيئة Ultralytics CI الخاصة بـ IMX الإصدار 2.9 أو أحدث، وأقل من 2.12. أُجريت عمليات التصدير لهذه الصفحة باستخدام 2.10.0 و2.11.0 و2.14.1 و2.15.0 |
model-compression-toolkit | الإصدار 2.4.1 أو أحدث. استخدمت جميع عمليات التصدير لهذه الصفحة الإصدار 2.5.1: يتطلب uni-pytorch 3.19.0، الذي يثبّته imx500-converter[pt] 3.19.2، الإصدار mct-quantizers 1.6، وهو ما لا يقبله MCT 2.6 الأحدث |
imx500-converter[pt] | الإصدار 3.18.2 أو أحدث. استخدمت جميع عمليات التصدير لهذه الصفحة الإصدار 3.19.2، مع uni-pytorch 3.19.0 |
edge-mdt-cl, edge-mdt-tpc | الإصداران 1.1.0 و1.2.0 أو أحدث. استخدمت جميع عمليات التصدير لهذه الصفحة الإصدارين 1.1.1 و1.3.0 |
pydantic | أقل من 2.12. استخدمت عمليات التصدير لهذه الصفحة الإصدارين 2.11.9 و2.11.10 |
pulp | أقل من 4، كما تحقّق منه التصدير: يفشل model-compression-toolkit 2.5.1 مع PuLP 4. استخدمت جميع عمليات التصدير لهذه الصفحة الإصدار 3.3.2 |
| Java | الإصدار 17 أو أحدث لمحوّل التحويل. استخدمت عمليات التصدير لهذه الصفحة Eclipse Temurin 21.0.13 |
| نظام التشغيل | Linux، ويتحقق التصدير من ذلك. أُجريت عمليات التصدير لهذه الصفحة على Ubuntu 24.04 بنظام x86-64 |
للاطلاع على طرق التثبيت الأخرى، راجع دليل التثبيت. ثم صدّر نموذج Ultralytics YOLO11n:
from ultralytics import YOLO
# حمّل نموذج YOLO11n
model = YOLO("yolo11n.pt")
# صدّر النموذج إلى تنسيق IMX500 مع تكميم INT8
model.export(format="imx") # creates 'yolo11n_imx_model/'# Export a YOLO11n PyTorch model to IMX500 format with INT8 quantization
yolo export model=yolo11n.pt format=imx # creates 'yolo11n_imx_model/'على خادم AMD EPYC 9655 مشترك مزوّد بوحدة GPU من طراز NVIDIA RTX PRO 6000 Blackwell، استغرق التصدير الافتراضي لـ YOLO11n، دون أي وسيطات أخرى، من 145 إلى 458 s عند تثبيت الحزم، ومن 154 إلى 457 s في أول عملية تصدير ضمن بيئة جديدة، والتي تثبّتها أيضًا، ومن 156 إلى 214 s على وحدة المعالجة المركزية مع إخفاء وحدة GPU. استغرقت عمليات التصدير التي عايرت النموذج على صور coco128.yaml الـ 128 من 370 إلى 647 s. وشغّل الخادم مهام أخرى، وتراوح متوسط الحمل بين 68 و685.
يشغّل التنبؤ والتحقق باستخدام مجلد Ultralytics IMX500 المُصدّر model_imx.onnx على وحدة المعالجة المركزية في الحاسوب، للتحقق من النموذج المُكمَّم قبل نشره على كاميرا Raspberry Pi AI:
from ultralytics import YOLO
# حمّل نموذج IMX500 المُصدّر؛ يشغّل Ultralytics model_imx.onnx على وحدة المعالجة المركزية
model = YOLO("yolo11n_imx_model")
# تنفيذ الاستدلال
results = model("https://ultralytics.com/images/bus.jpg")# Run inference with the exported IMX500 model on the CPU
yolo predict model=yolo11n_imx_model source='https://ultralytics.com/images/bus.jpg'from ultralytics import YOLO
# تحميل نموذج IMX500 المُصدّر
model = YOLO("yolo11n_imx_model")
# # التحقق من الدقة على مجموعة بيانات COCO8
metrics = model.val(data="coco8.yaml")# Validate the exported IMX500 model on the CPU
yolo val model=yolo11n_imx_model data=coco8.yamlالمهام المدعومة#
يدعم تصدير Ultralytics IMX500 أربعًا من المهام السبع لنماذج nano من YOLO11 وYOLOv8، كما يدعم التصنيف لنماذج s منهما. لكل مهمة، صُدّرت نقاط التحقق YOLO11n وYOLOv8n بحجم الصورة الافتراضي لكل منها وشُغّلت على جهاز التصدير:
| المهمة | القيمة الافتراضية imgsz | YOLO11n | YOLOv8n | packerOut.zip (MB)، YOLO11n وYOLOv8n |
|---|---|---|---|---|
| كشف | 640 | ✅ | ✅ | 2.3 و2.2 |
| تجزئة | 640 | ✅ | ✅ | 2.2 و2.2 |
| دلالي | — | — | — | لا توجد نقاط تحقق لـ YOLO11 أو YOLOv8. يفشل تصدير YOLO26 مع IMX export only supported for detection, pose estimation, classification, and segmentation models. |
| العمق | — | — | — | لا توجد نقاط تحقق لـ YOLO11 أو YOLOv8. يفشل تصدير YOLO26 مع IMX export is not supported for depth models. |
| تصنيف | 224 | ✅ | ✅ | 2.4 و2.3 |
| الوضعية | 640 | ✅ | ✅ | 2.1 و2.1 |
| OBB | — | ❌ | ❌ | IMX export only supported for detection, pose estimation, classification, and segmentation models. |
تفشل عائلات النماذج الأخرى مع IMX export only supported for YOLOv8n and YOLO11n models.: جُرّبت YOLO26 لكل مهمة، وYOLO12، وYOLOv10، وYOLOv5nu، ونماذج RT-DETR. يتعرّف Ultralytics على النموذجين المدعومين من خلال عدد طبقاتهما، ويستخدم إعدادات MCT المخصصة لكل منهما؛ لذلك يُصدّر أيضًا النموذج المدرّب انطلاقًا من YOLO11n أو YOLOv8n بفئاتك الخاصة: إذ صُدّر نموذج كشف YOLO11n ضُبط بدقة انطلاقًا من yolo11n.pt على 3 فئات. تحتوي نماذج s من العائلتين على عدد الطبقات نفسه، وتجتاز هذا الفحص. لكنها لا تلائم مهام الكشف: يفشل YOLOv8s أثناء التكميم مع The model cannot be quantized to meet the specified resource utilization for the following targets: {'weights': 2550540.8}، وهو حدّ لذاكرة الأوزان يحدده Ultralytics للكشف والتقسيم وتقدير الوضعيات، كما يُكمَّم YOLO11s ثم يفشل في محوّل IMX500 مع Not enough memory, available: 8.00MB , required: 9.53MB. لا يوجد هذا الحد في التصنيف، وقد صُدّر YOLO11s-cls وYOLOv8s-cls وناسبا الذاكرة، بملفي packerOut.zip بحجم 5.7 و5.4 MB، مع استخدام 7.33MB و6.93MB من الذاكرة. يحتوي YOLO11m-cls وYOLOv8m-cls على طبقات أكثر، ويفشلان مع IMX export only supported for YOLOv8n and YOLO11n models.؛ ووفقًا لفحص الطبقات في الشيفرة، تفشل نماذج الكشف الأكبر أيضًا في هذا الفحص، ولم تُختبر.
وسيطات التصدير#
| المعامل | النوع | الافتراضي | الوصف |
|---|---|---|---|
format | str | 'imx' | التنسيق المستهدف للنموذج المُصدَّر، ويحدد مدى توافقه مع بيئات النشر المختلفة. |
imgsz | int أو tuple | حجم نقطة التحقق | حجم صورة إدخال النموذج، ويُحدّد أثناء التصدير: عدد صحيح للصور المربعة أو صف (height, width). إذا لم يُحدّد، يستخدم التصدير الحجم الذي دُرّب عليه النموذج: 640 للكشف والتقسيم وتقدير الوضعيات، و224 للتصنيف. راجع حجم الصورة. |
quantize | int أو str | None | الدقة. عند عدم التحديد، تؤدي القيم 8 و'int8' و'w8a8' إلى إنشاء INT8، وهي الدقة الوحيدة؛ راجع الدقة. تحل هذه القيم محل العَلَمين المهجورين half/int8. |
data | str | None | ملف YAML لـمجموعة البيانات يتضمن صور المعايرة؛ أما التصنيف فيتطلب دليل مجموعة بيانات أو اسم مجموعة بيانات مضمّنة. إذا لم يُحدّد، يستخدم Ultralytics مجموعة البيانات الافتراضية الصغيرة للمهمة، مثل coco8.yaml للكشف. راجع المعايرة. |
fraction | float أو int أو list | 1.0 | مجموعة المعايرة الفرعية: نسبة أو عدد صور (الأعداد الصحيحة الأكبر من 1) أو قائمة [train, val, test]، ويُستخدم منها الإدخال الخاص بقسم المعايرة. |
nms | bool، اختياري | None | تضمّن عمليات تصدير الكشف والتقسيم وتقدير الوضعيات NMS دائمًا: يسجّل None وFalse IMX export requires nms=True, setting nms=True. ترفض نماذج التصنيف nms=True. راجع تنسيق الإخراج. |
conf | float | None | عتبة الدرجة في NMS المضمّن، وتكون 0.25 عند عدم تحديدها. تُثبَّت قيمتها في النموذج، راجع العتبات في النموذج. |
iou | float | None | عتبة IoU في NMS المضمّن، وتكون 0.5 عند عدم تحديدها، وتُثبَّت في النموذج. |
max_det | int | 500 | عدد الاكتشافات التي يعيدها NMS المضمّن، وهو ثابت في النموذج. وتُخفّض القيم التي تتجاوز 500، وهو حد المحوّل، إلى هذا الحد. |
device | str | None | الجهاز المستخدم للتكميم. من دون device أو مع device=cpu، يستخدم التصدير أول GPU من نوع CUDA عند توفره ويسجّل IMX export uses CUDA if available, setting device=0. Use CUDA_VISIBLE_DEVICES='' for CPU. لإجراء التكميم على CPU لجهاز يحتوي على GPU، أخفِ GPU باستخدام CUDA_VISIBLE_DEVICES=""؛ راجع القيود واستكشاف الأخطاء وإصلاحها. يعمل محوّل IMX500 على CPU. |
للاطلاع على الوسيطات المشتركة بين جميع التنسيقات، راجع وثائق وضع التصدير.
الدقة#
يشغّل IMX500 نماذج INT8، لذا يكمّم التصدير النموذج دائمًا باستخدام MCT:
quantize | النتيجة |
|---|---|
| غير معيّن | INT8. |
8 أو 'int8' أو 'w8a8' | INT8، مثل القيمة غير المحددة؛ وكذلك int8=True القديم |
16 أو 'fp16' | يفشل مع quantize=16 (FP16) is not supported; format='imx' supports quantize=8 (INT8). See https://docs.ultralytics.com/modes/export#quantization-options؛ وكذلك half=True القديم |
32 أو 'fp32' | يفشل باستخدام quantize=32 (FP32) is not supported; format='imx' supports quantize=8 (INT8). See https://docs.ultralytics.com/modes/export#quantization-options |
'w8a16' أو 'w8a32' | يفشل مع quantize='w8a16' is not supported; format='imx' supports quantize=8 (INT8). See https://docs.ultralytics.com/modes/export#quantization-options وتظهر الرسالة نفسها لـ 'w8a32' |
ينفّذ Ultralytics التكميم بعد التدريب باستخدام إعدادات النظام الأساسي المستهدف IMX500 في edge-mdt-tpc. ويُبقي على تنشيطات بدقة 16 بت لطبقات رأسي الكشف والتقسيم وتقدير الوضعيات التي تفك ترميز الصناديق والنقاط المفتاحية، ويتيح لبحث الدقة المختلطة في MCT اختيار عرض البتات للأوزان كي يلائم النموذج ذاكرة المستشعر. يستخدم التصدير التكميم بعد التدريب فقط: فالتكميم بعد التدريب القائم على التدرج (GPTQ) والتدريب الواعي بالتكميم في MCT غير متاحين عبر model.export().
المعايرة#
يكمّم التصدير النموذج باستخدام تكميم MCT بعد التدريب: إذ يشغّل MCT النموذج على صور المعايرة لقياس نطاق كل تنشيط. ويمرّر Ultralytics إلى MCT التقسيم val من data، أو split الذي تحدده. إذا لم تُحدّد data، يستخدم التصدير مجموعة البيانات الافتراضية الصغيرة للمهمة ويسجّل INT8 export requires a missing 'data' arg for calibration. Using default 'data=coco8.yaml'.، على سبيل المثال؛ ومثال ذلك أن الكشف يستخدم 4 صور، كما يسجّل التصدير >300 images recommended for INT8 calibration, found 4 images. تستخدم نماذج التصنيف 12 صورة من imagenet10.
- عدد الصور: يستخدم تصدير Ultralytics كل صورة في التقسيم: 128 صورة مع
coco128.yaml، و64 معfraction=0.5، و10 معfraction=10. - لم تُفد زيادة الصور كثيرًا: على صور COCO الـ 500 في المقاييس، التي شُغّلت على جهاز التصدير، غيّرت المعايرة على أول 500 صورة من COCO train2017 بدلًا من الصور الافتراضية الأربع الدقة بمقدار يتراوح بين -2.9 و2.9 نقطة mAP50-95 مع
conf=0.001(صُدّرت كل مجموعة مرة واحدة)؛ وبالنسبة إلى نماذج الكشف YOLO11n وYOLOv8n، حققcoco128.yamlمعconf=0.001نتيجتي 38.0 و36.7. عاير النموذج على صور من بيانات النشر لديك، ثم تحقّق من النتيجة، راجع النشر. - الوقت: تمر صور المعايرة عبر MCT. على الخادم المشترك، استغرقت عمليات تصدير نماذج الكشف والتقسيم وتقدير الوضعيات الستة لـ YOLO11n وYOLOv8n، ضمن اختبارات الدقة وبالمعايرة الافتراضية، من 150 إلى 314 s، بينما استغرقت من 591 إلى 1655 s عند استخدام 500 صورة.
العتبات في النموذج#
تنتهي عمليات تصدير الكشف والتقسيم وتقدير الوضعيات بعملية NMS في النموذج، وينفّذها IMX500 على المستشعر؛ لذلك تُثبّت قيم conf وiou وmax_det الخاصة بالتصدير في packerOut.zip وmodel_imx.onnx. إذا لم تُحدّد conf، يستخدم التصدير القيمة 0.25، وهي عتبة الدرجة الافتراضية للتنبؤات. لا يمكن لـ conf الذي تمرّره لاحقًا إلى predict أو val سوى إزالة مزيد من عمليات الكشف، راجع النشر.
يقلّل هذا من الدقة التي يبلغ عنها val، إذ يحتسب عمليات الكشف ذات الدرجات المنخفضة: على صور COCO الـ 500 في المقاييس، كانت نتيجة التصدير الافتراضي أقل من PyTorch بمقدار يتراوح بين 5.5 و14.2 نقطة mAP50-95، بينما كانت نتيجة التصدير نفسه مع conf=0.001 أقل منه بمقدار يتراوح بين 1.1 و10.6 نقطة. تحتفظ نصوص الكاميرا في كاميرا Raspberry Pi AI على أي حال بعمليات الكشف التي تتجاوز 0.4 أو 0.55. لقياس دقة التكميم، صدّر نموذج Ultralytics YOLO11n ثانيًا باستخدام conf=0.001 للتحقق:
from ultralytics import YOLO
model = YOLO("yolo11n.pt")
# احتفظ بعمليات الكشف حتى الدرجة 0.001، كما يفعل التحقق، ثم تحقّق على جهاز التصدير
model.export(format="imx", conf=0.001) # overwrites 'yolo11n_imx_model/'
metrics = YOLO("yolo11n_imx_model").val(data="coco8.yaml")# Keep detections down to a score of 0.001, as validation does, then validate on the export host
yolo export model=yolo11n.pt format=imx conf=0.001 # overwrites 'yolo11n_imx_model/'
yolo val model=yolo11n_imx_model data=coco8.yamlحجم الصورة#
تحتوي IMX500 على ذاكرة بسعة 8 MB للنموذج وتنشيطاته، ويُظهر المحوّل في model_imx_MemoryReport.json مقدار الذاكرة التي يستخدمها النموذج المُجمّع. يسرد الجدول مقدار تلك الذاكرة بوحدة MB لنموذجي YOLO11n وYOLOv8n عند كل imgsz جرى تصديره، باستخدام المعايرة الافتراضية؛ وقد جُمّع كل حجم مربع جرى تصديره، من 256 إلى 704 بكسل بخطوات من 64، لكلا النموذجين والمهام الثلاث، وظل packerOut.zip بين 2.1 و2.3 MB:
imgsz | Detect | Segment | الوضعية |
|---|---|---|---|
256 | 3.45 / 3.45 | 3.38 / 3.49 | 3.41 / 3.40 |
320 | 3.78 / 3.78 | 3.71 / 3.82 | 3.74 / 3.72 |
384 | 4.35 / 4.35 | 4.28 / 4.38 | 4.30 / 4.30 |
448 | 4.81 / 4.80 | 4.77 / 4.88 | 4.76 / 4.76 |
512 | 5.57 / 5.56 | 5.49 / 5.59 | 5.53 / 5.52 |
576 | 6.21 / 6.18 | 6.29 / 6.40 | 6.17 / 6.15 |
640 | 7.17 / 7.14 | 7.18 / 7.28 | 7.13 / 7.12 |
704 | 7.90 / 7.85 | 7.79 / 7.89 | 7.85 / 7.84 |
1280 | فشل: #boxes X #classes exceeds the supported limit of 2097120 | يفشل، كما في الكشف | يفشل: يحتاج إلى 19.73 / 19.71 MB |
(480, 640) | يُصدّر | يُصدّر | يُصدّر |
- 704 بكسل تستهلك ما يعادل 97 إلى 99% من الذاكرة وفقًا لما يعرضه المحوّل؛ وفي نماذج التقسيم، يسجّل المحوّل أولًا
ConvFe failed with insufficient memory, trying to run Tiling Advisorثم يجمع النموذج. - 1280 بكسل: يفشل تصدير الكشف والتقسيم في المحوّل، الذي يدعم 2,097,120 صندوقًا كحد أقصى مضروبًا في عدد الفئات في NMS للنموذج، بينما ينتج عن 1280 بكسل 33,600 صندوق لـ 80 فئة؛ ويفشل تصدير تقدير الوضعيات مع
Not enough memory, available: 8.00MB , required: 19.73MB(19.71 MB لـ YOLOv8n). ثم يفشل التصدير معreturned non-zero exit status 3.و1.على التوالي. - نماذج التصنيف جُمّعت عند كل حجم جرى تصديره: 128 و160 و224 و288 و320 و384 و448 و512 و640 بكسل، واستخدمت من الذاكرة ما يتراوح بين 2.96MB و7.28MB.
- لم تُقَس الدقة عند الأحجام الأخرى لهذه الصفحة؛ تحقّق من الحجم الذي تختاره باستخدام بياناتك، راجع النشر. وقد كُتبت نصوص الكاميرا في كاميرا Raspberry Pi AI للأحجام الافتراضية.
تنسيق المخرجات#
يكتب التصدير مجلدًا باسم yolo11n_imx_model/ حجمه 14.7 MB لـ YOLO11n، بجوار الملف .pt؛ ويطبع سجل التصدير الحجم بوحدة MiB بصيغة (14.0 MB). لا يلزم Raspberry Pi سوى packerOut.zip وlabels.txt؛ أما model_imx.onnx فهو للاختبارات على الحاسوب. أحجام الملفات بوحدة MB (10^6 بايت):
| الملف | الحجم (MB) | المحتويات |
|---|---|---|
packerOut.zip | 2.3 | النموذج المُجمّع لمستشعر IMX500، الذي تنسخه إلى Raspberry Pi، حيث تحوّله أدوات IMX500 إلى ملف البرنامج الثابت للكاميرا |
labels.txt | <0.01 | أسماء الفئات، اسم واحد في كل سطر، لتطبيقك على الكاميرا |
model_imx.onnx | 10.9 | النموذج المُكمَّم مع عوامل تشغيل المُكمِّم في MCT وNMS الخاصة بالنموذج، والذي يشغّله YOLO() على وحدة المعالجة المركزية في الحاسوب، مع تضمين البيانات الوصفية من Ultralytics |
model_imx.pbtxt | 1.5 | المخطط النصي للنموذج المُجمّع، الذي يكتبه المحوّل |
dnnParams.xml | <0.01 | موترات الإدخال والإخراج للنموذج المُجمّع، وهي موجودة أيضًا داخل packerOut.zip |
model_imx_MemoryReport.json | <0.01 | الذاكرة التي يستخدمها النموذج على المستشعر: 7.17MB من أصل 8.00MB لكشف YOLO11n |
يستقبل model_imx.onnx مدخلًا واحدًا اسمه input، وشكله (batch, 3, 640, 640): صور RGB بترتيب القنوات أولًا، بصيغة float32 ومقيسة إلى المجال 0-1، كما في تصدير ONNX؛ أما نماذج التصنيف فتستقبل (batch, 3, 224, 224). ولا يكون حجم الدفعة ثابتًا. وتنتهي نماذج الكشف والتجزئة والوضعية بتطبيق NMS الخاص بالنموذج، لذا تكون مخرجاتها الاكتشافات بعد NMS، مع سعة تصل إلى 500، وهي max_det الخاصة بالتصدير. والأشكال المعروضة لصورة واحدة، وهي نفسها في YOLO11n وYOLOv8n:
| المهمة | المخرجات |
|---|---|
| Detect | الصناديق (1, 500, 4) float32، والدرجات (1, 500) float32، ومؤشرات الفئات (1, 500) int32، وعدد عمليات الكشف (1, 1) int32 |
| Segment | الصناديق والدرجات ومؤشرات الفئات كما في الكشف، ثم معاملات القناع (1, 500, 32) float32 ونماذج القناع الأولية (1, 32, 160, 160) float32 |
| التصنيف | (1, 1000) float32: احتمال لكل فئة من فئات ImageNet الألف |
| الوضعية | الصناديق والدرجات ومؤشرات الفئات كما في الكشف، ثم 17 نقطة مفتاحية × 3 قيم (1, 500, 51) float32 |
- الصناديق: زوايا
x1, y1, x2, y2بالبكسل لصورة الإدخال 640x640. تعيد عمليات تصدير الكشف أيضًا عدد عمليات الكشف الصالحة، وتكون الصفوف التي تليه حشوًا؛ ولا تعيد عمليات تصدير التقسيم وتقدير الوضعيات عددًا، لذا رشّح صفوفها بحسب الدرجة. - NMS: تحتفظ NMS الخاصة بالنموذج بعمليات الكشف التي تتجاوز درجتها
conf، وتستبعد التداخلات التي تتجاوزiou، باستخدام قيم التصدير: 0.25 و0.5 افتراضيًا، راجع العتبات في النموذج. يعطيnms=Falseالنموذج نفسه، ولا يتوفر الرأس الخالي من NMS في YOLO26 لأن YOLO26 لا يُصدّر. - التقسيم: اضرب معاملات الأقنعة الـ 32 لكل عملية كشف في النماذج الأولية
(32, 160, 160)للحصول على القناع، كما في تصدير ONNX. - البيانات الوصفية: يخزّن
model_imx.onnxالبيانات الوصفية من Ultralytics (namesوtaskوimgszوstrideوargs) في البيانات الوصفية لـ ONNX، التي يقرأهاYOLO()؛ ويحتويlabels.txtعلى أسماء الفئات للكاميرا.
على bus.jpg، قورنت عمليات الكشف من model_imx.onnx بعمليات الكشف من تصدير ONNX بدقة FP32 لنقطة التحقق نفسها، وشغّلتها YOLO() على دخل 640x640 نفسه (224x224 للتصنيف) على جهاز التصدير x86-64، بصورة واحدة لكل مهمة. تُعد عملية الكشف مطابقة إذا كانت فئتها نفسها وكان تداخل صندوقها يتجاوز 0.5 IoU:
| المهمة | YOLO11n | YOLOv8n |
|---|---|---|
| Detect | تطابقت 5 من أصل 5 عمليات كشف ONNX، وعدد عمليات الكشف 5، والصناديق ضمن 12 px | تطابقت 5 من أصل 5 عمليات كشف ONNX، وعدد عمليات الكشف 5، والصناديق ضمن 33 px |
| Segment | تطابقت 5 من أصل 5 عمليات كشف ONNX، وعدد عمليات الكشف 5، والصناديق ضمن 17 px، وIoU الأقنعة ≥ 0.84 | تطابقت 4 من أصل 6 عمليات كشف ONNX، وعدد عمليات الكشف 4، والصناديق ضمن 50 px، وIoU الأقنعة ≥ 0.94 |
| التصنيف | الفئة نفسها في المرتبة الأولى، والدرجة الأولى 0.57 → 0.62 | الفئة نفسها في المرتبة الأولى، والدرجة الأولى 0.51 → 0.64 |
| الوضعية | تطابقت 4 من أصل 4 عمليات كشف ONNX، وعدد عمليات الكشف 4، والصناديق ضمن 5 px، والنقاط المفتاحية ضمن 28 px | تطابقت 4 من أصل 4 عمليات كشف ONNX، وعدد عمليات الكشف 4، والصناديق ضمن 13 px، والنقاط المفتاحية ضمن 29 px |
عثر سبعة من نماذج INT8 الثمانية على العناصر نفسها التي عثر عليها ONNX؛ وعثر YOLOv8n-seg على 4 من عمليات الكشف الست في ONNX. بلغ أكبر اختلاف في زاوية صندوق 50 بكسل ضمن صورة ارتفاعها 1080 بكسل، واختلفت درجات INT8 عن ONNX؛ لذا تحقّق من نموذج INT8 باستخدام بياناتك، وراجع المقاييس لمعرفة الدقة على COCO.
التشغيل باستخدام ONNX Runtime#
لتشغيل تصدير Ultralytics IMX500 في شيفرة Python خاصة بك على حاسوب، حمّل model_imx.onnx باستخدام ONNX Runtime وخيارات الجلسة mct-quantizers، التي تسجّل عوامل تشغيل مُكمِّم MCT، كما يفعل Ultralytics. يحتاج المثال إلى الحزم التي تثبّتها أول عملية تنبؤ من Ultralytics، وإلى صورة bus.jpg في مجلد العمل:
import mct_quantizers as mctq
import numpy as np
import onnxruntime as ort
from edgemdt_cl.pytorch.nms import nms_ort # noqa: F401, registers the NMS operator of the model
from PIL import Image
# Export first: yolo export model=yolo11n.pt format=imx
options = mctq.get_ort_session_options() # registers the MCT quantizer operators
options.enable_mem_reuse = False # as Ultralytics does; without it, some models fail with a buffer shape mismatch
session = ort.InferenceSession("yolo11n_imx_model/model_imx.onnx", options, providers=["CPUExecutionProvider"])
labels = open("yolo11n_imx_model/labels.txt").read().splitlines()
# Letterbox the RGB image to 640x640 with gray padding, channels first, scaled to 0-1
image = Image.open("bus.jpg").convert("RGB")
r = 640 / max(image.size)
w, h = round(image.width * r), round(image.height * r)
canvas = Image.new("RGB", (640, 640), (114, 114, 114))
canvas.paste(image.resize((w, h), Image.BILINEAR), ((640 - w) // 2, (640 - h) // 2))
x = np.asarray(canvas, dtype=np.float32).transpose(2, 0, 1)[None] / 255
boxes, scores, classes, n = session.run(None, {"input": x})
for box, score, c in zip(boxes[0][: n[0, 0]], scores[0], classes[0]):
x1, y1, x2, y2 = (box - [(640 - w) // 2, (640 - h) // 2] * 2) / r # back to the original image
print(f"{labels[c]} {score:.2f} [{x1:.0f}, {y1:.0f}, {x2:.0f}, {y2:.0f}]")بالنسبة إلى YOLO11n، طبع هذا العناصر الخمسة نفسها في bus.jpg التي طبعها YOLO()، مع اختلاف طفيف في الدرجات وزوايا الصناديق: يغيّر المثال الحجم باستخدام Pillow، بينما يغيّر Ultralytics الحجم باستخدام OpenCV. تكون الصناديق بالبكسل لصورة الإدخال 640x640 حتى السطر الأخير الذي يعيد إسقاطها على الصورة.
النشر#
يحمّل YOLO("yolo11n_imx_model") model_imx.onnx من المجلد ويشغّله باستخدام ONNX Runtime على وحدة المعالجة المركزية، مع عوامل تشغيل مُكمِّم MCT في mct-quantizers وعامل تشغيل NMS في edge-mdt-cl. يتيح ذلك التحقق من نموذج Ultralytics المُكمَّم على حاسوب قبل نسخه إلى الكاميرا؛ ولا يستخدم IMX500. أُجريت الاختبارات أدناه على جهاز التصدير x86-64 باستخدام نُسخ من عملية تصدير واحدة لـ YOLO11n:
- وحدة المعالجة المركزية فقط: يشغّل Ultralytics النموذج باستخدام مزوّد تنفيذ وحدة المعالجة المركزية في ONNX Runtime، حتى عند تمرير
device=0. تجعل عوامل تشغيل مُكمِّم MCT العملية بطيئة: على 32 وحدة معالجة مركزية في جهاز التصدير المشترك، استغرقت مرحلة الاستدلال فيvalمن 2032 إلى 4078 ms لكل صورة لعمليات تصدير الكشف الثماني لـ YOLO11n وYOLOv8n ضمن المقاييس، مقارنةً بـ 18.1 إلى 18.5 ms لعمليات تصدير FP32 ONNX المقابلة في عمليات التشغيل نفسها. هذه ليست السرعة على الكاميرا، راجع المقاييس. - حجم الإدخال الثابت: يعمل النموذج فقط بالحجم الذي صُدّر به
imgsz، والذي يقرأهYOLO()من البيانات الوصفية، لذا يعمل كلٌّ منpredictوvalبهذا الحجم، حتى عند التصدير بأبعاد مستطيلة مثلimgsz=(480, 640)، ويستبدلان به أيimgszيُمرَّر إليهما؛ أعد التصدير لتغيير الحجم. - الدفعات: حجم الدفعة غير ثابت. أعطت قائمة من ثلاث صور ثلاث نتائج، بما في ذلك مع
batch=3، وعملvalمعbatch=4، محققًا 48.1 mAP50-95 على COCO8 على جهاز التصدير x86-64، مقابل 47.1 معbatch=1. - العتبات: لا تحتفظ NMS الخاصة بالنموذج إلا بعمليات الكشف التي تتجاوز درجتها
confالخاصة بالتصدير. عند استخدام القيمة الافتراضية 0.25، أعطىpredictمعconf=0.1عمليات الكشف الخمس نفسها علىbus.jpgكما في الإعداد الافتراضي، بينما أعطىconf=0.5أربع عمليات، راجع العتبات في النموذج. - اسم المجلد: يتعرّف Ultralytics على التنسيق من خلال
_imx_modelفي اسم المجلد، بصرف النظر عن حالة الأحرف، ولا يقرأ البيانات الوصفية إلا إذا انتهى الاسم به. يفشل المجلد المسمىmymodelمعmodel='mymodel' is not a supported model format.، أما المجلد المسمىyolo11n_imx_model_v2فيُحمّل من دون بياناته الوصفية ويعيد نتائج خاطئة من دون إصدار خطأ: أسماء الفئاتclass0وclass1وما إلى ذلك، ودرجات أعلى من 1. أعد تسمية المجلد كما تشاء، لكن أبقِ_imx_modelفي النهاية، مثلcustom_imx_model. - الملفات المطلوب تحميلها: يحتاج
YOLO()إلى ملف.onnxفقط في الدليل، بأي اسم؛ ويحتاج إلى دليل لا يحتوي إلا علىmodel_imx.onnxالمحمّل مع أسماء الفئات والمهمة. يُحمّل أول ملف.onnxيعثر عليه، لذا أبقِ ملفًا واحدًا هناك. يؤدي تحميل ملفmodel_imx.onnxنفسه بدلًا من دليله إلى التعامل معه كنموذج ONNX عادي: على حاسوب مزود بوحدة GPU من CUDA، يثبّت أولًاonnxruntime-gpu، الذي استبدل في بيئة هذه الصفحة (1.32.0) إصدارprotobuf4.25.5 الذي يثبّته محوّل IMX500، بالإصدار 7.36.2، ثم يفشل معmct_quantizers:ActivationPOTQuantizer(-1) is not a registered function/op. - macOS: على جهاز Mac مزود بمعالج Apple silicon، حمّل
YOLO()دليلًا مُصدّرًا على Linux، وثبّت الحزم التي يحتاج إليها، وعثر على الكائنات الخمسة نفسها فيbus.jpg. أعطى التحقق باستخدام COCO8 قيمة 48.9 mAP50-95 هناك مع MCT 2.6.2 وmct-quantizers1.7.0، مقابل 47.1 على جهاز التصدير المضيف x86-64 مع MCT 2.5.1 وmct-quantizers1.6.0، وكلاهما باستخدام ONNX Runtime 1.32.0. لا يعمل التصدير نفسه إلا على Linux.
كاميرا Raspberry Pi AI#
تعود الخطوات أدناه إلى إصدارات سابقة من هذه الصفحة، وقد كُتبت باستخدام ultralytics من 8.3.28 إلى 8.3.234، ونُقلت كما هي. لم تتوفر كاميرا Raspberry Pi AI Camera لهذه الصفحة، لذا لم تُنفذ الخطوات على الكاميرا. على حاسوب x86-64، ثبّت أمر الخطوة 4 حزمة Sony modlib 1.5.0، وحُلّت عمليات الاستيراد في النصوص البرمجية الأربعة، وحمّل نموذج الفئة في كل نص برمجي packerOut.zip وlabels.txt لتصدير Ultralytics المُعد لهذه الصفحة؛ ثم توقف AiCamera() مع ImportError: libcamera module is not available...، كما هو متوقع في غياب الكاميرا. تسرد مكتبة وحدات التطبيقات نظام Raspberry Pi OS Bookworm مع Python 3.11 ونظام Raspberry Pi OS Trixie مع Python 3.13؛ وتذكر الملاحظة أدناه الإصدار الذي اختُبرت هذه الخطوات معه لأول مرة.
بعد تصدير نموذج Ultralytics YOLO11n إلى تنسيق IMX500، يمكنك نشره على Raspberry Pi AI Camera لإجراء الاستدلال.
متطلبات العتاد#
تأكد من توفر الأجهزة التالية:
- Raspberry Pi 5 أو Raspberry Pi 4 Model B
- كاميرا Raspberry Pi AI
وصّل Raspberry Pi AI Camera بموصل MIPI CSI ذي 15 سنًا على Raspberry Pi، ثم شغّل Raspberry Pi.
متطلبات البرمجيات#
اختُبر هذا الدليل باستخدام Raspberry Pi OS Bookworm على Raspberry Pi 5.
الخطوة 1: افتح نافذة طرفية ونفّذ الأوامر التالية لتحديث برنامج Raspberry Pi إلى أحدث إصدار.
sudo apt update && sudo apt full-upgradeالخطوة 2: ثبّت البرنامج الثابت لـ IMX500، وهو مطلوب لتشغيل مستشعر IMX500.
sudo apt install imx500-allالخطوة 3: أعد تشغيل Raspberry Pi لتطبيق التغييرات.
sudo rebootالخطوة 4: ثبّت مكتبة وحدة تطبيق AITRIOS لـ Raspberry Pi
pip install git+https://github.com/SonySemiconductorSolutions/aitrios-rpi-application-module-library.gitالخطوة 5: شغّل كشف الكائنات وتقدير الوضعية والتصنيف والتجزئة باستخدام YOLO11 عبر البرامج النصية التالية، المتوفرة في أمثلة مكتبة وحدة تطبيق aitrios-rpi-application-module-library.
تأكد من استبدال الدليلين model_file وlabels.txt بما يتناسب مع بيئتك قبل تشغيل هذه البرامج النصية.
import numpy as np
from modlib.apps import Annotator
from modlib.devices import AiCamera
from modlib.models import COLOR_FORMAT, MODEL_TYPE, Model
from modlib.models.post_processors import pp_od_yolo_ultralytics
class YOLO(Model):
"""YOLO model for IMX500 deployment."""
def __init__(self):
"""Initialize the YOLO model for IMX500 deployment."""
super().__init__(
model_file="yolo11n_imx_model/packerOut.zip", # replace with proper directory
model_type=MODEL_TYPE.CONVERTED,
color_format=COLOR_FORMAT.RGB,
preserve_aspect_ratio=False,
)
self.labels = np.genfromtxt(
"yolo11n_imx_model/labels.txt", # replace with proper directory
dtype=str,
delimiter="\n",
)
def post_process(self, output_tensors):
"""Post-process the output tensors for object detection."""
return pp_od_yolo_ultralytics(output_tensors)
device = AiCamera(frame_rate=16) # Optimal frame rate for maximum FPS of the YOLO model running on the AI Camera
model = YOLO()
device.deploy(model)
annotator = Annotator()
with device as stream:
for frame in stream:
detections = frame.detections[frame.detections.confidence > 0.55]
labels = [f"{model.labels[class_id]}: {score:0.2f}" for _, score, class_id, _ in detections]
annotator.annotate_boxes(frame, detections, labels=labels, alpha=0.3, corner_radius=10)
frame.display()from modlib.apps import Annotator
from modlib.devices import AiCamera
from modlib.models import COLOR_FORMAT, MODEL_TYPE, Model
from modlib.models.post_processors import pp_yolo_pose_ultralytics
class YOLOPose(Model):
"""YOLO pose estimation model for IMX500 deployment."""
def __init__(self):
"""Initialize the YOLO pose estimation model for IMX500 deployment."""
super().__init__(
model_file="yolo11n-pose_imx_model/packerOut.zip", # استبدله بالدليل الصحيح
model_type=MODEL_TYPE.CONVERTED,
color_format=COLOR_FORMAT.RGB,
preserve_aspect_ratio=False,
)
def post_process(self, output_tensors):
"""Post-process the output tensors for pose estimation."""
return pp_yolo_pose_ultralytics(output_tensors)
device = AiCamera(frame_rate=17) # معدل الإطارات الأمثل لتحقيق أقصى FPS لنموذج YOLO-pose الذي يعمل على AI Camera
model = YOLOPose()
device.deploy(model)
annotator = Annotator()
with device as stream:
for frame in stream:
detections = frame.detections[frame.detections.confidence > 0.4]
annotator.annotate_keypoints(frame, detections)
annotator.annotate_boxes(frame, detections, corner_length=20)
frame.display()import cv2
import numpy as np
from modlib.apps import Annotator
from modlib.devices import AiCamera
from modlib.models import COLOR_FORMAT, MODEL_TYPE, Model
from modlib.models.post_processors import pp_cls
class YOLOClassification(Model):
"""YOLO classification model for IMX500 deployment."""
def __init__(self):
"""Initialize the YOLO classification model for IMX500 deployment."""
super().__init__(
model_file="yolo11n-cls_imx_model/packerOut.zip", # replace with proper directory
model_type=MODEL_TYPE.CONVERTED,
color_format=COLOR_FORMAT.RGB,
preserve_aspect_ratio=False,
)
self.labels = np.genfromtxt("yolo11n-cls_imx_model/labels.txt", dtype=str, delimiter="\n")
def post_process(self, output_tensors):
"""Post-process the output tensors for classification."""
return pp_cls(output_tensors)
device = AiCamera()
model = YOLOClassification()
device.deploy(model)
annotator = Annotator()
with device as stream:
for frame in stream:
for i, label in enumerate([model.labels[id] for id in frame.detections.class_id[:3]]):
text = f"{i + 1}. {label}: {frame.detections.confidence[i]:.2f}"
cv2.putText(frame.image, text, (50, 30 + 40 * (i + 1)), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (100, 0, 100), 2)
frame.display()import numpy as np
from modlib.apps import Annotator
from modlib.devices import AiCamera
from modlib.models import COLOR_FORMAT, MODEL_TYPE, Model
from modlib.models.post_processors import pp_yolo_segment_ultralytics
class YOLOSegment(Model):
"""YOLO segmentation model for IMX500 deployment."""
def __init__(self):
"""Initialize the YOLO segmentation model for IMX500 deployment."""
super().__init__(
model_file="yolo11n-seg_imx_model/packerOut.zip", # replace with proper directory
model_type=MODEL_TYPE.CONVERTED,
color_format=COLOR_FORMAT.RGB,
preserve_aspect_ratio=False,
)
self.labels = np.genfromtxt(
"yolo11n-seg_imx_model/labels.txt", # replace with proper directory
dtype=str,
delimiter="\n",
)
def post_process(self, output_tensors):
"""Post-process the output tensors for instance segmentation."""
return pp_yolo_segment_ultralytics(output_tensors)
device = AiCamera(frame_rate=17) # Optimal frame rate for maximum FPS of the YOLO-seg model running on the AI Camera
model = YOLOSegment()
device.deploy(model)
annotator = Annotator()
with device as stream:
for frame in stream:
detections = frame.detections[frame.detections.confidence > 0.4]
labels = [f"{model.labels[c]}" for m, c, s, _, _ in detections]
annotator.annotate_instance_segments(frame, detections)
annotator.annotate_boxes(frame, detections, labels=labels)
frame.display()أدلة النشر#
- وثائق Raspberry Pi AI Camera: إعداد الكاميرا وبرنامج IMX500 الثابت وأمثلة
rpicam-appsوPicamera2. - وثائق AITRIOS Raspberry Pi AI Camera: وثائق Sony الخاصة بأدوات IMX500 والمحوّل وأداة تجميع الحزم.
- مكتبة وحدات التطبيقات: مكتبة Sony بلغة Python لتطبيقات AI Camera، مع أمثلة لنماذج Ultralytics YOLO.
- دليل Raspberry Pi: إعداد Ultralytics YOLO على Raspberry Pi.
- خيارات نشر النماذج: مقارنة IMX500 بتنسيقات التصدير الأخرى.
القيود واستكشاف الأخطاء وإصلاحها#
- pip 24.0 إلى 25.0:
ResolutionImpossible: في بيئة جديدة أُنشئت باستخدامpython3 -m venvعلى Ubuntu 24.04، والتي تتضمن pip 24.0، يتوقف تثبيت حزم IMX معCannot install imx500-converter>=3.18.2 and imx500-converter[pt]==3.19.2 because these package versions have conflicting dependencies.، ثم يفشل التصدير الأول، الذي يثبتها باستخدام pip نفسه، معNo module named 'model_compression_toolkit'. توقفت الإصدارات pip 24.2 و24.3.1 و25.0 بالطريقة نفسها؛ بينما حلّت الإصدارات pip 23.0.1 و25.1 و26.3 تبعيات الحزم نفسها. شغّلpip install --upgrade pipأولًا، كما في البدء السريع. - Python 3.13 والإصدارات الأحدث: يتوقف التصدير مع
IMX export requires Python>=3.10,<3.13.قبل تثبيت أي شيء. لا يُثبّت محوّل IMX500 في هذه البيئة: تتطلب حزمةuni-pytorchالخاصة به إصدار Python أقدم من 3.13، ويتوقف pip معNo matching distribution found for ortools==9.9.3963 (from conv-allocator). يُثبّت MCT نفسه على Python 3.13: عند تجاوز فحص Python في التصدير لأغراض الاختبار، اكتمل التكميم ثم فشل التصدير معFileNotFoundError: imxconv-pt not found. Install with: pip install imx500-converter[pt]. أجرِ التصدير باستخدام Python من 3.10 إلى 3.12؛ إذ لا يمكن تشغيله باستخدام Python 3.13 المرفق بالنظام في Raspberry Pi OS Trixie. - macOS وWindows: يتوقف التصدير مع
Export only supported on Linux. See https://developer.aitrios.sony-semicon.com/en/docs/raspberry-pi-ai-camera/imx500-converter?version=3.17.3&progLang=على macOS؛ ويوقفه الفحص نفسه على Windows، حيث لم يُجرَ الاختبار. أجرِ التصدير على Linux أو باستخدام منصة Ultralytics؛ إذ لا يزال بإمكانYOLO()تشغيل الدليل المُصدّر على Mac، انظر النشر. - لا يتوفر Java: عند غياب
javaعلىPATH، يشغّل التصديرsudo aptلتثبيتopenjdk-21-jreعلى Ubuntu وDebian 13 أو أحدث، أوopenjdk-17-jreعلى Debian 12 وRaspberry Pi OS Bookworm، ويسجلUltralytics requirement ['openjdk-21-jre'] not found, attempting AutoUpdate...أولًا على Ubuntu؛ أما على توزيعات Linux الأخرى فلا يثبت شيئًا. في غياب صلاحياتsudo، يسجلCommand '['sudo', 'apt', 'update']' returned non-zero exit status 1.، ويكمّم النموذج، ثم يفشل المحوّل معjava: command not foundوreturned non-zero exit status 127.. ثبّت Java 17 أو أحدث، انظر البدء السريع. - تعطيل التثبيت التلقائي: مع
YOLO_AUTOINSTALL=falseوpip install ultralyticsعادي، يسجل التصديرUltralytics requirements ['model-compression-toolkit>=2.4.1', 'edge-mdt-cl>=1.1.0', 'edge-mdt-tpc>=1.2.0', 'pydantic<2.12', 'imx500-converter[pt]>=3.18.2', 'pulp<4'] not found, AutoUpdate disabled by YOLO_AUTOINSTALL=Falseويفشل معNo module named 'model_compression_toolkit'. ثبّت الحزم أولًا، انظر البدء السريع. - نماذج وأحجام أخرى: تفشل العائلات والأحجام الأخرى التي جُرّبت، ويكون سبب الفشل في معظم الحالات
IMX export only supported for YOLOv8n and YOLO11n models.؛ والاستثناء هو التصنيف، حيث تُصدّر أيضًا النماذج s، انظر المهام المدعومة. - التجزئة الدلالية وتقدير العمق وOBB: تفشل نماذج التجزئة الدلالية مع
IMX export only supported for detection, pose estimation, classification, and segmentation models.، ونماذج العمق معIMX export is not supported for depth models.، ونماذج OBB مع الرسالة نفسها الخاصة بالتجزئة الدلالية. batchوdynamicوopsetوsimplifyوoptimizeوworkspace: تفشل قيمةbatchغير 1، وdynamic=True، وأيopset، وsimplify=False، وoptimize=True، وأيworkspaceمعargument 'batch' is not supported for format='imx'والرسالة نفسها للقيم الأخرى؛ أما القيم الافتراضية فتنجح. يقبل النموذج المُصدّر أي حجم دفعة على أي حال، انظر النشر.nms: تتضمن نماذج الكشف والتجزئة وتقدير الوضع NMS دائمًا، ويسجلnms=Noneأوnms=FalseالرسالةIMX export requires nms=True, setting nms=True.. وتفشل نماذج التصنيف مع'nms=True' is not valid for classification models..device=cpuعلى جهاز يحتوي على GPU: عندما يكون GPU من نوع CUDA ظاهرًا، يجري التصدير باستخدامdevice=cpuالتكميم على أول GPU، كما في حالة عدم استخدامdevice: يضع MCT 2.5.1 وmct-quantizers1.6.0 موتراتهما على GPU كلما اكتشف PyTorch وجوده. لإجراء التكميم على CPU، أخفِ GPU باستخدامCUDA_VISIBLE_DEVICES=""؛ وقد اكتمل التصدير، معdevice=cpuومن دونه، عند عدم ظهور أي GPU.- أحجام الصور الكبيرة: عند
imgsz=1280، تفشل صادرات الكشف والتجزئة في المحوّل مع#boxes X #classes exceeds the supported limit of 2097120، وتفشل صادرات تقدير الوضع معNot enough memory, available: 8.00MB , required: 19.73MB(حجم YOLOv8n هو 19.71 MB)؛ أجرِ التصدير بدقة 704 بكسل أو أقل، انظر حجم الصورة. - تختلف نتائج عمليات التصدير المتكررة: نتج عن 5 عمليات تصدير لـYOLO11n بالإعدادات الافتراضية نفسها، 3 على وحدة GPU و2 على CPU، خمسة ملفات
packerOut.zipمختلفة، بأحجام تتراوح بين 2,291,836 و2,292,214 بايت، وبدقة mAP50-95 تتراوح بين 30.3 و32.1 على صور COCO الخمسمئة في المعايير. قارن عمليات التصدير باستخدام بيانات التحقق الخاصة بك بدلًا من الاعتماد على تشغيل واحد. - دليل الإخراج: تحذف كل عملية تصدير لنقطة تحقق واحدة
yolo11n_imx_model/وتعيد كتابته، بصرف النظر عنimgszأوdataأوconfالخاصة بها؛ لذا أعد تسمية الدليل قبل تصدير نسخة أخرى، وأبقِ_imx_modelفي نهاية الاسم. - الرسائل في سجل التصدير: يسجل MCT
OperatorSetNames.DEPTHWISE_CONV is not in model.، ويسجلNot enough images in representative dataset to generate 10 data points, only 4 were generatedعند استخدام أقل من 10 صور للمعايرة؛ ولا تؤدي أي من الرسالتين إلى إيقاف التصدير. - التصدير على Raspberry Pi: لا يتحقق التصدير إلا من Linux وPython من 3.10 إلى 3.12، لذا لا يتوقف على Raspberry Pi OS Bookworm مع Python 3.11، لكن لم يُجرَ الاختبار لهذه الصفحة؛ وتتجاوز مجموعة اختبارات Ultralytics تصدير IMX على Raspberry Pi بسبب نفاد الذاكرة على Raspberry Pi 5 بذاكرة 16 GB. أجرِ التصدير على حاسوب Linux آخر وانسخ
packerOut.zipوlabels.txtإلى Raspberry Pi.
للاطلاع على الأخطاء الأخرى، راجع دليل المشكلات الشائعة.
المعايير المرجعية#
لم تتوفر كاميرا Raspberry Pi AI Camera لهذه الصفحة، لذا لم تُعَد قياسات سرعة النماذج ودقتها على IMX500. تعرض الجداول أدناه القياسات التي أجراها فريق Ultralytics على كاميرا Raspberry Pi AI Camera لإصدارات سابقة من هذه الصفحة، وقد نُقلت كما هي. أُعيد قياس صفوف الكشف، وأُضيفت صفوف تقدير الوضع، باستخدام تصدير تقدير الوضع الذي صدر لأول مرة في ultralytics 8.3.167؛ وأُضيفت صفوف التصنيف مع تصدير التصنيف الذي صدر لأول مرة في 8.3.222.
زمن الاستدلال على كاميرا Raspberry Pi AI Camera، بالمللي ثانية لكل صورة.
| النموذج | imgsz | زمن الاستدلال على AI Camera (مللي ثانية/صورة) |
|---|---|---|
| YOLOv8n | 640 | 58.79 |
| YOLO11n | 640 | 58.82 |
| YOLOv8n-pose | 640 | 58.79 |
| YOLO11n-pose | 640 | 62.50 |
| YOLOv8n-cls | 224 | 33.31 |
| YOLO11n-cls | 224 | 33.31 |
دقة النماذج المُصدّرة على كاميرا Raspberry Pi AI Camera.
| النموذج | بيانات التحقق | mAP50-95(B) |
|---|---|---|
| YOLOv8n | COCO128 | 0.470 |
| YOLO11n | COCO128 | 0.517 |
| YOLOv8n-pose | COCO8-Pose | 0.687 |
| YOLO11n-pose | COCO8-Pose | 0.788 |
| النموذج | بيانات التحقق | دقة Top-1 | دقة Top-5 |
|---|---|---|---|
| YOLOv8n-cls | ImageNet10 | 0.25 | 0.5 |
| YOLO11n-cls | ImageNet10 | 0.25 | 0.417 |
حجم packerOut.zip بالميغابايت، وفقًا لما سُجّل بهذه الإصدارات.
| النموذج | packerOut.zip (ميغابايت) |
|---|---|
| YOLOv8n | 2.1 |
| YOLO11n | 2.2 |
| YOLOv8n-pose | 2.0 |
| YOLO11n-pose | 2.1 |
| YOLOv8n-cls | 2.3 |
| YOLO11n-cls | 2.3 |
- استُخدمت COCO128 لصفوف الكشف، وهي أول 128 صورة من COCO train2017، ودُرّبت النماذج عليها؛ لذا تكون قيمها أعلى من قيم صور التحقق: على جهاز التصدير المضيف، حقق نموذجا PyTorch YOLOv8n وYOLO11n قيمتي 0.450 و0.511 mAP50-95 على COCO128. تتجاوز قيم الكاميرا للنموذجين، 0.470 و0.517، قيم PyTorch هذه؛ ولا تتوفر سجلات
confوبيانات المعايرة الخاصة بعمليات التصدير تلك، كما تعذرت إعادة تشغيل الكاميرا لهذه الصفحة، لذا لم يُحدَّد السبب. - استُخدمت ImageNet10 لصفوف التصنيف، وتضم 12 صورة للتحقق. وعلى جهاز التصدير المضيف، حقق نموذجا PyTorch YOLOv8n-cls وYOLO11n-cls قيم دقة Top-1 وTop-5 نفسها التي حققتها الكاميرا: 0.25 و0.5 و0.417؛ لذا تُظهر هذه الصفوف أن الكاميرا طابقت PyTorch على 12 صورة، لا دقة النماذج. على صور التحقق الـ102 في
imagenet100، حقق YOLO11n-cls دقة Top-1 بنسبة 40.2% باستخدام PyTorch و36.3% بوصفهmodel_imx.onnxللتصدير الافتراضي، بينما حقق YOLOv8n-cls 40.2% و34.3%. - تضم COCO8-Pose، المستخدمة لصفوف تقدير الوضع، 4 صور للتحقق؛ وحقق نموذجا PyTorch YOLOv8n-pose وYOLO11n-pose عليها قيمتي mAP50-95 لمربعات الإحاطة 0.666 و0.743 على جهاز التصدير المضيف.
- الحجم: تُدرج ملفات
packerOut.zipالخاصة بصادرات هذه الصفحة في المهام المدعومة.
الدقة على جهاز التصدير المضيف#
يقارن الجدول دقة model_imx.onnx، أي النموذج المكَمَّم في التصدير، عند تشغيله بواسطة YOLO() على CPU الخاص بجهاز التصدير المضيف، وهو خادم AMD EPYC 9655، بدقة نموذج PyTorch وتصدير ONNX الخاص به بتنسيق FP32. يشغّل IMX500 الصيغة المُجمّعة من النموذج نفسه بتنسيق INT8؛ ولم تُقَس دقته على الكاميرا لهذه الصفحة.
قيمة mAPval 50-95 على 500 صورة من COCO val2017؛ الأعلى أفضل. وفي التجزئة وتقدير الوضع، تشير القيمة إلى دقة مربعات الإحاطة والأقنعة أو النقاط المفتاحية. تختلف أعمدة IMX في صور المعايرة وconf الخاص بالتصدير، انظر المعايرة والعتبات في النموذج. تظهر أفضل قيمة IMX في كل صف بخط عريض، وفي حال التعادل تُبرز القيمتان.
| النموذج | PyTorch | ONNX FP32 | IMX، افتراضي (4 صور، conf 0.25) | IMX، 4 صور، conf=0.001 | IMX، 500 صورة، conf 0.25 | IMX، 500 صورة، conf=0.001 |
|---|---|---|---|---|---|---|
| YOLO11n | 40.3 | 40.3 | 30.3 | 37.4 | 33.0 | 38.3 |
| مربع إحاطة YOLO11n-seg | 40.0 | 40.0 | 31.6 | 37.0 | 31.8 | 37.0 |
| قناع YOLO11n-seg | 33.2 | 33.2 | 27.7 | 32.1 | 28.0 | 31.7 |
| مربع إحاطة YOLO11n-pose | 72.1 | 72.1 | 64.7 | 69.3 | 64.3 | 68.4 |
| تقدير وضع YOLO11n-pose | 52.1 | 52.1 | 40.0 | 41.5 | 40.2 | 44.4 |
| YOLOv8n | 38.6 | 38.6 | 29.0 | 35.5 | 29.7 | 36.3 |
| مربع إحاطة YOLOv8n-seg | 38.0 | 38.0 | 23.8 | 34.3 | 23.9 | 33.7 |
| قناع YOLOv8n-seg | 31.7 | 31.7 | 21.3 | 29.9 | 21.5 | 29.8 |
| مربع إحاطة YOLOv8n-pose | 71.1 | 71.1 | 58.5 | 66.2 | 58.3 | 64.9 |
| تقدير وضع YOLOv8n-pose | 53.2 | 53.2 | 41.5 | 46.3 | 40.5 | 43.4 |
- ONNX FP32 أعطى القيم نفسها التي أعطاها PyTorch في كل صف.
confالخاص بالتصدير يفسر معظم الفرق في التصدير الافتراضي، باستثناء النقاط المفتاحية لكلا نموذجي تقدير الوضع: رفعconf=0.001الدقة بمقدار 1.5 إلى 10.5 نقطة. وباستخدامه، كان نموذج INT8 أقل من PyTorch بمقدار 1.1 إلى 10.6 نقطة، وكان الفرق الأكبر في النقاط المفتاحية لـYOLO11n-pose.- كان أداء 500 صورة معايرة مع
conf=0.001أقل من PyTorch بمقدار 1.5 إلى 9.8 نقطة.
أُجريت القياسات باستخدام ultralytics 8.4.220 وmodel-compression-toolkit 2.5.1 وimx500-converter 3.19.2 وPyTorch 2.15.0 وONNX Runtime 1.32.0 (مع protobuf 7.36.2) على Python 3.11 في batch=1. شُغّل model_imx.onnx ونماذج ONNX FP32 باستخدام موفر تنفيذ CPU، باستثناء YOLOv8n-seg FP32 الذي شُغّل باستخدام موفر تنفيذ CUDA؛ وشُغّل PyTorch على وحدة GPU من طراز RTX PRO 6000 باستخدام rect=False، وبمدخلات 640x640 نفسها المستخدمة للنماذج المُصدّرة. الدقة محسوبة على آخر 500 صورة من COCO val2017 بترتيب الفرز، وفي تقدير الوضع على آخر 500 صورة تحتوي أشخاصًا؛ لذا تختلف عن قيم مجموعة التحقق الكاملة في صفحة نموذج YOLO11. صور المعايرة الـ500 هي أول 500 صورة من COCO train2017 بترتيب الفرز، وفي تقدير الوضع أول 500 صورة تحتوي أشخاصًا. يمثّل كل عمود IMX عملية تصدير واحدة؛ وتختلف نتائج عمليات التصدير المتكررة، انظر القيود واستكشاف الأخطاء وإصلاحها.
نبذة عن Sony IMX500#
يُجري مستشعر الرؤية الذكي IMX500 من Sony معالجة الذكاء الاصطناعي على المستشعر نفسه، بحيث تستطيع الكاميرا إرسال نتائج الاستدلال كبيانات وصفية مع كل إطار، أو إرسال البيانات الوصفية وحدها بدلًا من الصور فقط. يُكمّم مجموعة أدوات ضغط النماذج (MCT) من Sony النموذج ليتوافق مع المستشعر، انظر منشور مدونة Ultralytics عن MCT، ويُجمّع محوّل IMX500 النموذج المكَمَّم؛ وعلى Raspberry Pi، تحوّل أداة تجميع الحزم الخاصة بأدوات imx500-all ملف packerOut.zip إلى ملف البرنامج الثابت الذي تحمّله الكاميرا.
الأسئلة الشائعة#
لا: لا يدعم تصدير Ultralytics IMX500 إلا YOLO11n وYOLOv8n، إضافةً إلى YOLO11s-cls وYOLOv8s-cls للتصنيف؛ ويفشل نموذج YOLO26 للكشف أو التجزئة أو التصنيف أو تقدير الوضع مع
IMX export only supported for YOLOv8n and YOLO11n models.، بينما تفشل نماذج التجزئة الدلالية والعمق وOBB في مرحلة أسبق مع رسالة المهمة الخاصة بها. تستخدم Ultralytics إعدادات MCT المصممة لطبقات هذين النموذجين. درّب نموذج YOLO11n أو YOLOv8n على بياناتك أو حسّنه عليها لنشره على Raspberry Pi AI Camera، انظر المهام المدعومة.نعم: يشغّل
YOLO("yolo11n_imx_model")الملف المكَمَّمmodel_imx.onnxالذي يكتبه تصدير Ultralytics بجوارpackerOut.zipعلى CPU في حاسوب Linux أو Mac، لذا يمكنك إجراء التنبؤ والتحقق من نموذج INT8 قبل نسخه إلى الكاميرا، انظر النشر. يختبر ذلك التكميم، لا IMX500؛ فلم تُقَس سرعة الكاميرا ولا نتائجها لهذه الصفحة.يكون تصدير Ultralytics IMX500 بتنسيق INT8، ويُبقي NMS فيه افتراضيًا على الاكتشافات التي تتجاوز درجاتها 0.25، وهو ما يحسبه
valضده: على 500 صورة من COCO على جهاز التصدير المضيف، كان التصدير الافتراضي أقل من PyTorch بمقدار 5.5 إلى 14.2 نقطة mAP50-95، بينما كان التصدير باستخدامconf=0.001أقل منه بمقدار 1.1 إلى 10.6 نقطة، انظر المعايير. عاير باستخدام صور من بياناتك عبرdata، وأجرِ التصدير معconf=0.001لقياس أثر التكميم، وأبقِconfالافتراضي أو عتبة تطبيقك للكاميرا، انظر العتبات في النموذج.لا يعمل تصدير Ultralytics IMX500 إلا على Linux مع Python من 3.10 إلى 3.12؛ ويتوقف على Mac مع
Export only supported on Linux. See https://developer.aitrios.sony-semicon.com/en/docs/raspberry-pi-ai-camera/imx500-converter?version=3.17.3&progLang=. أما على Raspberry Pi، فلا يتوقف على Raspberry Pi OS Bookworm مع Python 3.11، لكن لم يُجرَ الاختبار لهذه الصفحة، وتتجاوز اختبارات Ultralytics التصدير هناك بسبب نفاد الذاكرة على Raspberry Pi 5 بذاكرة 16 GB. أجرِ التصدير على حاسوب Linux أو باستخدام منصة Ultralytics، وانسخpackerOut.zipوlabels.txtإلى Raspberry Pi، انظر القيود واستكشاف الأخطاء وإصلاحها.
التعليقات86
اطرح سؤالًا، وشارك نتائجك، أو ساعد شخصًا آخر.
Chad Walshwhere is the best place to get support on the IMX500. I am running into multiple issues: i. my first yolo11n model built fine and exported to imx500, no problem, but my second model with a LOT more training images build fine but crashed the imx500 export. ii. the output of the imx500 during inference is giving a lot of none outputs between solid recognitions. it seems like there is something interfering with or disrupting the inference outputs (e.g., good output, none, none, none, none, good output, ...). where is the best place to get help with these issues?
Glenn JocherUltralyticsPlease continue the discussion here so the Ultralytics team can help; for the export crash, share the exact export command, full text traceback, and output from
yolo checks, and for intermittentNoneresults include a minimal inference script, confidence threshold, and a short reproducible input sample. Note that IMX export uses the calibration dataset specified bydataand defaults to the full dataset, so testing a smallerfractionmay help isolate resource-related failures.
leeprevost
I've made considerable progress by moving conducting this model compression process with a Container using dtcooper/raspberrypi-os:python3.11 after considerable problems with dependencies. Now getting a container most of the way through the process of compressing my yolov11s model and its trained best.pt weights.
At the end of the process - I get a simple "killed" after the Calculation of quantization parameters step. I see memory spiking close to 100% on top and think I'm hitting OOM with my pi4 8gb.
root@a5e132f6b333:/app# yolo export model=./models/yolov11/best.pt data='Billfish-Breeds-1/data.yaml' format=imx verbos> Ultralytics 8.3.221 🚀 Python-3.11.14 torch-2.9.0+cpu CPU (aarch64) WARNING ⚠️ IMX export requires nms=True, setting nms=True. YOLO11s summary (fused): 100 layers, 9,413,187 parameters, 0 gradients, 21.3 GFLOPs PyTorch: starting from 'models/yolov11/best.pt' with input shape (1, 3, 640, 640) BCHW and output shape(s) ((1, 8400, 4> IMX: collecting INT8 calibration images from 'data=Billfish-Breeds-1/data.yaml' Fast image access ✅ (ping: 0.1±0.0 ms, read: 16.1±2.7 MB/s, size: 16.4 KB) Scanning /app/Billfish-Breeds-1/valid/labels.cache... 268 images, 0 backgrounds, 0 corrupt: 100% ━━━━━━━━━━━━ 268/268 1> WARNING ⚠️ IMX: >300 images recommended for INT8 calibration, found 268 images. IMX: starting export with model_compression_toolkit 2.4.4... representative_data_gen generates a batch size of 1 which can be slow for optimization: consider increasing the batch s> WARNING:Model Compression Toolkit:OperatorSetNames.DEPTHWISE_CONV is not in model. Statistics Collection: 268it [1:01:26, 13.76s/it] Calculating quantization parameters: 100%|█████████████████████████████████████████████████████| 294/294 [12:44<00:00, > KilledWould appreciate any suggestion around this but think it probably pushes me over the edge to order my pi5? Or do I try to train on the yolov8 or yolov11n? I've not had very good success with the nano models. I've convinced myself the tradeoffs to the small is well worth it but that may be incompatible with this process?
leeprevost
@glenn-jocher am I posting at the right place? Put this in issues on gh?
Glenn JocherUltralytics@leeprevost you’re in the right place for discussion, but the OOM during IMX export is a new issue—please open a new issue for visibility. In the issue, include: the exact export command and full log,
yolo checksoutput (orultralytics.utils.checks.collect_system_info()), Java version (java --version), and the versions of IMX toolchain (pip freeze | grep -E "imx500|model-compression|sony-custom"). As immediate workarounds: export on a Linux x86_64 machine with more RAM, target YOLO11n/YOLOv8n (the IMX path is tuned for “n” models), and reduce calibration load withfraction(e.g., 0.25). Example:yolo export model=best.pt format=imx data=your.yaml imgsz=640 fraction=0.25IMX-specific knobs are summarized in the IMX500 export arguments here: Sony IMX500 export guide – Export arguments, and the exporter function requirements here: export_imx reference.
leeprevost
Thank you. I'll dig into the logs and see if I can add anything before opening new issue.
leeprevost
a few more questions and I will open an issue:
- Note that I was using a model trained on yolov11s rather than n as I've seen large degradation in the number of false positives in my model.
- I assume by "full log" you mean the output from the yolo export command with verbose at default (true). In other words, what I posted above?
- For some reason, I thought I read int he docs that i had to perform the model compression on the target machine. for me, the ultimate target is RpiZero2 but no way the model will export on that footprint . so, I went to the largest pi I have which is a Rpi4 -- that resulted in the OOM. So, am unsure by your guidance pointing me to the larger x86 linux machine. How will the process know the device limits if I perform it on that?
Trying to read these guides as best I can. I have not spent much time on the Sony site yet. If you'll point me, I don't want to start an issue that isn't an issue.
leeprevost
I opened an issue: https://github.com/ultralytics/ultralytics/issues/22512
Just tried the export again with the fraction=0.25 argument and got to "Optimal Solution Found" with objective measure of 0.94, then died with error:
Error x IMX: export failure 12662.7s: No module named 'onnxscript'
leeprevost
https://github.com/pytorch/pytorch/issues/166352 -- adding to my requirements.txt pointed to by Containerfile.
Glenn JocherUltralytics(تم التعديل)@leeprevost great progress. IMX export/quantization does not need to run on the target; it cross-compiles for IMX500, so doing it on a larger Linux host is recommended. “Full log” means the complete stdout/stderr from the export run.
The “No module named 'onnxscript'” failure is a missing dependency. Current Ultralytics installs the IMX toolchain (including
imx500-converterandmodel-compression-toolkit) itself, so upgrade withpip install -U ultralyticsand re-run the export rather than pinning old versions by hand. Let’s continue the deep-dive in the issue you opened for traceability.leeprevost
Ok -- @glenn-jocher: am moving this to my opened issue. Still trying this on my pi4 but can move to my dev machine with plenty of RAM + Cuda. Got further but still died with a torch error -- will post there.
Glenn JocherUltralyticsThanks—let’s continue in the issue for traceability. On the larger Linux host, try GPU-assisted export to reduce RAM pressure and speed up calibration; if needed, temporarily lower
imgszto validate the pipeline:yolo export model=path/to/best.pt format=imx data=path/to/data.yaml device=0 imgsz=640 # if memory is still tight during calibration yolo export model=path/to/best.pt format=imx data=path/to/data.yaml device=0 imgsz=512For a concise list of export options and behavior, see the Export mode docs at Ultralytics YOLO — Export.
leeprevost
Much thanks for posting this guide. Thank you.
I am having very solid success running the standard detection models right out of the box on the RpiZero 2 which is my target platform. I'm actually amazed at the power draw (ran detection/streaming for about 175 minutes on a 4400mahr battery using about 60% of its capacity). Also, very solid top/htop scores showing less than 1/8 of CPU utilization. Memory is still such a problem on a rpiz2 but not any more so than what is being used with streaming only on the pi. Still have about 50% of memory left over as I recall. I've got screen shots of top screens if needed.
But, I need to get a trained model working on my RpiZ2 and am running into problems. As the guide seemed to indicate (or perhaps Sony's), I need to do most of the quantization on my target platform. I assumed that meant my zero. I have a very good model trained with yolov11m or large. I've tried to reduce that to a nano but I'm getting too much loss of MAP scores and too much false positive rates. So, am now trying to get a yolov11s to work. On my quantization process (it was not clear how to do this with a custom model) but am first loading the yolov11s.pt and then loading my best.pt on top of that. Ultralytics successfully loads my data, gives me a warning prompt about my 290 images (< 300 not ideal) and then another about processing speed with 1 batch. The program then goes off the rails with no UI messages. I assume I'm running out of memory on the piz2. So, my next steps seem to be either:
- Start over and try with nano model.
- Do my quantization on a larger pi (i've got a spare pi4).
I guess another option would be to spend more time understanding Sony's under the hood tools to optimize those settings?
Would appreciate some guidance here down the right path.
leeprevost
One thing that would be very helpful is to show how to do this on something other than the target platform. i'm trying to get a small detection model to run on a rpi zero2 and hate to have to download all of my training data to the zero to do the quantization.
Idea: Have a step that allows collection of the "target_platform_capabilities" information using Sony's model compression toolkit you are using under the hood, pickle it, and then use that object to drive the model compression on a larger machine.
I could probably dig in and try to follow your code and follow the "imx" part of your export process...
bohlebots
Wie schaffe ich es, dass das Modell im Speicher des IMX500 bleibt? Die PICAM wurde ja angepriesen mit der Aussage, dass sie selbst an einem Pi zero-2 mit gleicher Geschwindigkeit läuft und in der Tat, das täte sie, aber das Modell muss jedes Mal neu aufgeladen werden, und das dauert beim Pi Zero ewig, ja selbst mit einem Pi5 dauert es Minuten. Grundsätzlich muss die imx500 aber ein Modell auch bei ausgeschaltetem Strom im Speicher halten können, so dass nach dem Anschalten das letzte Modell direkt zur Verfügung steht. Wie bekomme ich das hin?
Gruß Roland
Teo-treny
Hello ! When running object detection (step 5), I get the following error :
Exception in thread Thread-2 (_process_requests_func): Traceback (most recent call last): File "/home/pi/.pyenv/versions/3.11.9/lib/python3.11/threading.py", line 1045, in _bootstrap_inner self.run() File "/home/pi/.pyenv/versions/3.11.9/lib/python3.11/threading.py", line 982, in run self._target(*self._args, **self._kwargs) File "/home/pi/Desktop/imx_test/venv/lib/python3.11/site-packages/modlib/devices/ai_camera/ai_camera.py", line 193, in _process_requests_func callback() File "/home/pi/Desktop/imx_test/venv/lib/python3.11/site-packages/modlib/devices/ai_camera/ai_camera.py", line 207, in _process_requests self._parse_request(req) File "/home/pi/Desktop/imx_test/venv/lib/python3.11/site-packages/modlib/devices/ai_camera/ai_camera.py", line 256, in _parse_request detections = self.model.post_process(outputs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/pi/Desktop/imx_test/Test_1.py", line 23, in post_process return pp_od_yolo_ultralytics(output_tensors) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/pi/Desktop/imx_test/venv/lib/python3.11/site-packages/modlib/models/post_processors/post_processors.py", line 129, in pp_od_yolo_ultralytics n_detections = int(output_tensors[3]) ^^^^^^^^^^^^^^^^^^^^^^ TypeError: only length-1 arrays can be converted to Python scalarsI'm running Python 3.11.9 and installed all the dependencies following the guide. My Raspberry PI is a 3B+ model with Bookworm 64 bits and is up to date.
aytacsekmen
In the official IMX500 documentation provided by Sony (https://developer.sony.com/tinyml-23/developer-tools/documentation/imx500-evaluation-kit-user-guide?version=2023-11-28&progLang=), they describe the process of generating the network.fpk and network_info.txt files that will be used to deploy the model to IMX500, using the Packager.sh script. However, when I attempt to apply the same procedure to the packerOut.zip file I created by following the tutorial on https://docs.ultralytics.com/integrations/sony-imx500, I am unable to run the model on the IMX500. Also I couldn't run your implementation because it says that some packages are not found which I believe is related to the version of the OS. Currently I use the Pi OS that is provided by SONY for compatibility issues. I could run some other deep learning models following the steps in the (https://developer.sony.com/tinyml-23/developer-tools/documentation/imx500-evaluation-kit-user-guide?version=2023-11-28&progLang=), but I believe, there must be something different related to the creation of packerOut.zip file.
Could you assist in resolving this issue with the conversion process? @glenn-jocher
HelloCigar
Hello, per picamera2 docs, creating apps with "a camera window embedded into the GUI is through Qt", is there no other way to embed the video feed in other GUI frameworks?
skim-sony
Hi, I followed the steps in this page to convert the yolov8n model with imx500 converter and tested it with raspberry ai camera. But I get 29.5 ms for the inference time with 640x640 input tensor size. So I wonder why my inference time is better than your result (58.82ms). Which version of imx500 converter did you use?
skim-sony
Also, how did you measure the inference time? Did you use imx500.get_kpi_info(metadata) or calculate the elapsed time of picam2.capture_metadata()?
Glenn JocherUltralytics(تم التعديل)@skim-sony congratulations on the faster result! Our documented figure (58.82 ms for YOLO11n, see the Benchmarks) was measured by the Ultralytics team on a Raspberry Pi AI Camera with the
imxformat. Differences can come from the converter version, firmware, hardware (Pi 5 vs Pi 4) or how the time is measured. Would you mind sharing which converter version and Raspberry Pi model you're using? This could help other community members.skim-sony(تم التعديل)
Hi, I have used Pi5 and tried both 3.14.3 and 3.16.1 for imx500-converter. And both produces 29.5ms for inference time. It seems like you also use Pi5, so I wonder why our results are different. I'd like to reproduce your results 58.82 ms to learn what improves the inference time. So it would be helpful if you could share some info how to sync with your environment. Thanks!
Glenn JocherUltralytics(تم التعديل)@skim-sony that's interesting you're seeing better performance! The discrepancy could be due to several factors:
- Measurement methodology: end-to-end time (pre/post-processing + inference) differs from model-only inference time
- Firmware and converter versions
- Image resolution and resizing
- Test conditions: background processes, temperature, and power settings
Our published numbers are in the Benchmarks. If you'd like to share more details about your implementation, the community would certainly benefit.
fracipriano
Hello, I'm trying to run the standard YOLOv8n model on a Raspberry Pi AI Camera. I followed the exemple in the documentation
from ultralytics import YOLO # Load a YOLOv8n PyTorch model model = YOLO("yolov8n.pt") # Export the model model.export(format="imx", data="coco8.yaml") # exports with PTQ quantization by default # Load the exported model imx_model = YOLO("yolov8n_imx_model") # Run inference results = imx_model("https://ultralytics.com/images/bus.jpg")I got a bunch of warnings during the execution (export_log.txt), but the imx_model seemed to work properly in the end.
I then packaged it via IMX500 Packager and test it using the imx500_object_detection_demo.py. The Network Firmware gets uploaded, the application starts, but I get no detection. I tried to lower the detection threshold, but it didn't help. Any idea on what could be the problem? Any suggestion would be much appreciated.
Glenn JocherUltralyticsThank you for the detailed issue. Let's troubleshoot step by step. First, ensure your Raspberry Pi AI Camera is correctly connected and recognized by running
libcamera-helloin the terminal. If the camera works, verify that thelabels.txtpath in your demo command matches the exported file. You can also try inference on a static image first withimx_model.predict("test.jpg")to isolate live feed issues. For further assistance, please share the full export log and a screenshot of your camera output.For additional guidance, refer to the Sony IMX500 and AITRIOS integration blog post which demonstrates successful deployment steps.
fracipriano
Hello @glenn-jocher,
libcamera-hello works fine as does the imx500_object_detection_demo.py when using the default model ("/usr/share/imx500-models/imx500_network_ssd_mobilenetv2_fpnlite_320x320_pp.rpk").
There seems to be no problem with the labels.txt file as, if a run the imx500_object_detection_demo.py specifying the path to my label.txt, it works fine.
The imx_model also works fine before the packaging.
Here a screenshot of the camera output:
You can find the full export log file in my first post. Do you think any of the errors and/or warnings there could cause any problem with the packaging process via the IMX500-Packager?
Glenn JocherUltralyticsThank you for sharing these details. The warnings in your export log about "No BN layers to fold" and quantization parameters are normal during IMX conversion and shouldn't affect packaging. Since your camera feed works with the default model but not your custom export, please verify:
- Your
imx500-packagecommand uses the exactpackerOut.zipfromyolov8n_imx_model - The input tensor shape in your exported model matches IMX500 expectations (640x640 by default)
If issues persist, we recommend trying the IMX500 conversion process with our pretrained YOLOv8n model from https://github.com/ultralytics/assets/releases as a validation step.
- Your
fracipriano
Hello @glenn-jocher , thank you for your answer.
- Yes, I'm the one specifying the packerOut.zip path when running imx500-package
- I think so. Here is the content of the dnnParams.xml file generated by the export function
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <dnnParams> <networks> <network name="yolov8n_new_imx" ordinal="0" type=""> <inputTensors> <inputTensor persistency="0" ordinal="0" name="Placeholder.input.uid1:0" l2Offset="260480" numOfDimensions="3" bitsPerElement="8" shift="0" scale="0.00390625" format="unsigned"> <dimensions> <dimension size="3" serializationOrder="2" ordinal="0" padding="0"/> <dimension size="640" serializationOrder="1" ordinal="1" padding="0"/> <dimension size="640" serializationOrder="0" ordinal="2" padding="0"/> </dimensions> </inputTensor> </inputTensors> <outputTensors> <outputTensor ordinal="1" name="transform-83-/MultiClassNMS:0" l2Offset="281984" numOfDimensions="1" bitsPerElement="8" shift="0" scale="0.00390625" format="unsigned"> <dimensions> <dimension size="300" serializationOrder="0" ordinal="0" padding="0"/> </dimensions> </outputTensor> <outputTensor ordinal="2" name="transform-84-/MultiClassNMS:0" l2Offset="280960" numOfDimensions="1" bitsPerElement="16" shift="0" scale="1.0" format="signed"> <dimensions> <dimension size="300" serializationOrder="0" ordinal="0" padding="0"/> </dimensions> </outputTensor> <outputTensor ordinal="3" name="transform-85-/MultiClassNMS:0" l2Offset="279936" numOfDimensions="1" bitsPerElement="16" shift="0" scale="1.0" format="signed"> <dimensions> <dimension size="1" serializationOrder="0" ordinal="0" padding="0"/> </dimensions> </outputTensor> <outputTensor ordinal="0" name="transform-86-/MultiClassNMS:0" l2Offset="260480" numOfDimensions="2" bitsPerElement="16" shift="0" scale="0.03125" format="signed"> <dimensions> <dimension size="300" serializationOrder="0" ordinal="0" padding="0"/> <dimension size="4" serializationOrder="1" ordinal="1" padding="0"/> </dimensions> </outputTensor> </outputTensors> </network> </networks> <l2memory totalSize="8388480" coefficientsSize="2604544" reservedMemorySize="1024" networksRuntimeSize="5523456"/> </dnnParams>I downloaded the yolov8n.pt file from the Sep 29, 2024 Release and repeated the process from the beginning. Same result.
I'm adding here the terminal outputs I get when running the imx500-package: imx500-package_log.txt
Glenn JocherUltralytics(تم التعديل)Thanks for sharing the details. The
dnnParams.xmlshows correct 640x640 input dimensions. Since the default Mobilenet model works but your YOLOv8 export doesn't, please verify that your output tensor dimensions and ordering match the demo's expectations. YOLO IMX exports have a different output layout from Mobilenet, so the demo's post-processing must match. The deployment section of the IMX500 guide uses thepp_od_yolo_ultralyticspost-processor from the AITRIOS module library for Ultralytics YOLO IMX exports.fracipriano
Okay. So the problem was actually related to the output. The ordering is fine, as the scores and the classes. The problem are the bboxes. The values that I obtain are completely out of scale.
Example:
detection label: cup (0.56) detection box: (396100, 107520, 0, 0)whereas I would expect something like this:
detection label: cup (0.56) detection box: (39, 459, 440, 177)I'm not sure how to interpret this results. Is (396100, 107520, 0, 0) supposed to be the raw output of YOLOv8n? Also, in the dnnParams.xml posted above, I see that there is a scale="0.00390625" associated with the component of the output tensor relative to the bboxes. Should I renormalize my output using this factor?
Thank you for any insight you can provide.
Glenn JocherUltralytics(تم التعديل)The raw IMX500 outputs are quantized and need post-processing. Rather than decoding them by hand, use the
pp_od_yolo_ultralyticspost-processor shown in the deployment section of the IMX500 guide.fracipriano
Hello @glenn-jocher, a code snippet would be much appreciated for double-checking. Also, I can't find the documentation you mentioned—could you link it to me, please?
Glenn JocherUltralytics(تم التعديل)The IMX500 outputs are decoded for you by the AITRIOS module library, as shown in the deployment section of the IMX500 guide:
from modlib.models.post_processors import pp_od_yolo_ultralytics def post_process(self, output_tensors): return pp_od_yolo_ultralytics(output_tensors)Let us know if this resolves the coordinate scaling issue!
fracipriano
I think there’s been a misunderstanding. I thought there were other changes to be made besides rescaling. Scaling alone cannot be the solution since (396100, 107520, 0, 0) cannot become (39, 459, 440, 177) just by a scalar multiplication.
Also, I cannot find the "What's Under the Hood?" section anywhere here https://developer.sony.com/imx500. Could you be more precise about where I should look?
Glenn JocherUltralytics(تم التعديل)The "What's Under the Hood?" section refers to our Ultralytics IMX500 documentation, not Sony's site, but it describes the quantization and conversion toolchain, not output decoding. For box decoding use the post-processor from the deployment section:
from modlib.models.post_processors import pp_od_yolo_ultralytics def post_process(self, output_tensors): return pp_od_yolo_ultralytics(output_tensors)fracipriano
Hi @glenn-jocher , thank you very much for all the support. It finally works! There was no need to rescale the boxes by 0.03125. I was missing the --bbox-normalization flag when launching the script.
Once I added the flag, everything worked fine.
Glenn JocherUltralytics(تم التعديل)Great to hear you resolved it! For the current deployment workflow, including post-processing of the model outputs, see the IMX500 deployment guide. Happy detecting with your Raspberry Pi setup! 🚀