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

Coral Edge TPU on a Raspberry Pi with Ultralytics YOLO11 🚀

كمبيوتر Raspberry Pi أحادي اللوحة مزود بحافة USB TPU مسرع

ما هي حافة المرجان TPU?

The Coral Edge TPU is a compact device that adds an Edge TPU coprocessor to your system. It enables low-power, high-performance ML inference for TensorFlow Lite models. Read more at the Coral Edge TPU home page.



شاهد: How to Run Inference on Raspberry Pi using Google Coral Edge TPU

تعزيز أداء نموذج راسبيري باي مع حافة المرجان TPU

Many people want to run their models on an embedded or mobile device such as a Raspberry Pi, since they are very power efficient and can be used in many different applications. However, the inference performance on these devices is usually poor even when using formats like ONNX or OpenVINO. The Coral Edge TPU is a great solution to this problem, since it can be used with a Raspberry Pi and accelerate inference performance greatly.

حافة TPU على راسبيري باي مع TensorFlow لايت (جديد) ⭐

الدليل الحالي من Coral حول كيفية استخدام Edge TPU مع Raspberry Pi قديم، ولم تعد إصدارات وقت تشغيل Coral Edge TPU الحالية تعمل مع إصدارات وقت التشغيل الحالية TensorFlow Lite. وبالإضافة إلى ذلك، يبدو أن Google قد تخلى عن مشروع كورال تماماً، ولم تكن هناك أي تحديثات بين عامي 2021 و 2024. سيوضح لك هذا الدليل كيفية جعل Edge TPU يعمل مع أحدث إصدارات وقت تشغيل TensorFlow Lite ووقت تشغيل Coral Edge TPU المحدث على كمبيوتر Raspberry Pi أحادي اللوحة (SBC).

المتطلبات المسبقه

إرشادات التثبيت

يفترض هذا الدليل أن لديك بالفعل تثبيت نظام تشغيل Raspberry Pi يعمل وقمت بتثبيته ultralytics وجميع التبعيات. للحصول على ultralytics مثبتا ، قم بزيارة دليل التشغيل السريع للحصول على الإعداد قبل المتابعة هنا.

تثبيت الحافة TPU وقت التشغيل

أولا ، نحتاج إلى تثبيت Edge TPU وقت التشغيل. هناك العديد من الإصدارات المختلفة المتاحة ، لذلك تحتاج إلى اختيار الإصدار المناسب لنظام التشغيل الخاص بك.

راسبيري باي OSوضع التردد العالينسخة للتحميل
بولسي 32 بتلاlibedgetpu1-std_ ... .bullseye_armhf.deb
بولسي 64 بتلاlibedgetpu1-std_ ... .bullseye_arm64.deb
بولسي 32 بتنعمlibedgetpu1-max_ ... .bullseye_armhf.deb
بولسي 64 بتنعمlibedgetpu1-max_ ... .bullseye_arm64.deb
دودة الكتب 32 بتلاlibedgetpu1-std_ ... .bookworm_armhf.deb
دودة الكتب 64 بتلاlibedgetpu1-std_ ... .bookworm_arm64.deb
دودة الكتب 32 بتنعمlibedgetpu1-max_ ... .bookworm_armhf.deb
دودة الكتب 64 بتنعمlibedgetpu1-max_ ... .bookworm_arm64.deb

قم بتنزيل أحدث إصدار من هنا.

بعد تنزيل الملف ، يمكنك تثبيته بالأمر التالي:

sudo dpkg -i path/to/package.deb

بعد تثبيت وقت التشغيل ، تحتاج إلى توصيل Coral Edge الخاص بك TPU في منفذ USB 3.0 على Raspberry Pi. هذا لأنه ، وفقا للدليل الرسمي ، جديد udev يجب أن تدخل القاعدة حيز التنفيذ بعد التثبيت.

مهم

إذا كان لديك بالفعل كورال إيدج TPU وقت التشغيل مثبت ، قم بإلغاء تثبيته باستخدام الأمر التالي.

# If you installed the standard version
sudo apt remove libedgetpu1-std

# If you installed the high frequency version
sudo apt remove libedgetpu1-max

تصدير النموذج الخاص بك إلى Edge TPU نموذج متوافق

لاستخدام Edge TPU ، تحتاج إلى تحويل نموذجك إلى تنسيق متوافق. يوصى بتشغيل التصدير على Google Colab، أو على جهاز لينكس x86_64، أو باستخدام حاوية Docker الرسمية Ultralytics Docker، أو باستخدام Ultralytics HUB، نظرًا لأن مترجم Edge TPU غير متوفر على ARM. راجع وضع التصدير لمعرفة الوسيطات المتاحة.

Exporting the model

from ultralytics import YOLO

# Load a model
model = YOLO("path/to/model.pt")  # Load an official model or custom model

# Export the model
model.export(format="edgetpu")
yolo export model=path/to/model.pt format=edgetpu  # Export an official model or custom model

سيتم حفظ النموذج الذي تم تصديره في <model_name>_saved_model/ مجلد بالاسم <model_name>_full_integer_quant_edgetpu.tflite. It is important that your model ends with the suffix _edgetpu.tflite, otherwise ultralytics doesn't know that you're using a Edge TPU model.

تشغيل النموذج

Before you can actually run the model, you will need to install the correct libraries.

لو tensorflow مثبت ، إلغاء التثبيت tensorflow بالأمر التالي:

pip uninstall tensorflow tensorflow-aarch64

ثم تثبيت / تحديث tflite-runtime:

pip install -U tflite-runtime

Now you can run inference using the following code:

تشغيل النموذج

from ultralytics import YOLO

# Load a model
model = YOLO("path/to/<model_name>_full_integer_quant_edgetpu.tflite")  # Load an official model or custom model

# Run Prediction
model.predict("path/to/source.png")
yolo predict model=path/to/<model_name>_full_integer_quant_edgetpu.tflite source=path/to/source.png  # Load an official model or custom model

يمكنك العثور على معلومات شاملة في صفحة التنبؤ للحصول على تفاصيل وضع التنبؤ الكاملة.

Inference with multiple Edge TPUs

If you have multiple Edge TPUs you can use the following code to select a specific TPU.

from ultralytics import YOLO

# Load a model
model = YOLO("path/to/<model_name>_full_integer_quant_edgetpu.tflite")  # Load an official model or custom model

# Run Prediction
model.predict("path/to/source.png")  # Inference defaults to the first TPU

model.predict("path/to/source.png", device="tpu:0")  # Select the first TPU

model.predict("path/to/source.png", device="tpu:1")  # Select the second TPU

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

What is a Coral Edge TPU and how does it enhance Raspberry Pi's performance with Ultralytics YOLO11?

The Coral Edge TPU is a compact device designed to add an Edge TPU coprocessor to your system. This coprocessor enables low-power, high-performance machine learning inference, particularly optimized for TensorFlow Lite models. When using a Raspberry Pi, the Edge TPU accelerates ML model inference, significantly boosting performance, especially for Ultralytics YOLO11 models. You can read more about the Coral Edge TPU on their home page.

كيف يمكنني تثبيت وقت تشغيل Coral Edge TPU على جهاز Raspberry Pi؟

لتثبيت وقت تشغيل Coral Edge TPU على جهاز Raspberry Pi الخاص بك، قم بتنزيل .deb حزمة لإصدار نظام التشغيل Raspberry Pi OS الخاص بك من هذا الرابط. بمجرد تنزيله، استخدم الأمر التالي لتثبيته:

sudo dpkg -i path/to/package.deb

تأكد من إلغاء تثبيت أي إصدارات سابقة من وقت تشغيل Coral Edge TPU باتباع الخطوات الموضحة في قسم إرشادات التثبيت.

Can I export my Ultralytics YOLO11 model to be compatible with Coral Edge TPU?

Yes, you can export your Ultralytics YOLO11 model to be compatible with the Coral Edge TPU. It is recommended to perform the export on Google Colab, an x86_64 Linux machine, or using the Ultralytics Docker container. You can also use Ultralytics HUB for exporting. Here is how you can export your model using Python and CLI:

Exporting the model

from ultralytics import YOLO

# Load a model
model = YOLO("path/to/model.pt")  # Load an official model or custom model

# Export the model
model.export(format="edgetpu")
yolo export model=path/to/model.pt format=edgetpu  # Export an official model or custom model

لمزيد من المعلومات، راجع وثائق وضع التصدير.

ماذا يجب أن أفعل إذا كان TensorFlow مثبتًا بالفعل على جهاز Raspberry Pi الخاص بي ولكنني أريد استخدام tflite-runtime بدلاً من ذلك؟

إذا كان لديك TensorFlow مثبتًا على جهاز Raspberry Pi وتحتاج إلى التبديل إلى tflite-runtime، ستحتاج إلى إلغاء تثبيت TensorFlow أولاً باستخدام:

pip uninstall tensorflow tensorflow-aarch64

بعد ذلك، قم بتثبيت أو تحديث tflite-runtime باستخدام الأمر التالي:

pip install -U tflite-runtime

بالنسبة لعجلة معينة، مثل TensorFlow 2.15.0 2.15.0 tflite-runtimeيمكنك تنزيله من هذا الرابط وتثبيته باستخدام pip. تتوافر تعليمات مفصلة في القسم الخاص بتشغيل النموذج تشغيل النموذج.

How do I run inference with an exported YOLO11 model on a Raspberry Pi using the Coral Edge TPU?

After exporting your YOLO11 model to an Edge TPU-compatible format, you can run inference using the following code snippets:

تشغيل النموذج

from ultralytics import YOLO

# Load a model
model = YOLO("path/to/edgetpu_model.tflite")  # Load an official model or custom model

# Run Prediction
model.predict("path/to/source.png")
yolo predict model=path/to/edgetpu_model.tflite source=path/to/source.png  # Load an official model or custom model

يمكن الاطلاع على تفاصيل شاملة حول ميزات وضع التنبؤ الكاملة على صفحة Predict.

📅 Created 8 months ago ✏️ Updated 4 days ago

التعليقات