guides/coral-edge-tpu-on-raspberry-pi/ #8398
Replies: 24 comments 145 replies
-
Exactly the file I was looking for to reignite the Coral TPU dream. |
Beta Was this translation helpful? Give feedback.
-
If I understood right, this code only converts YOLO model for from ultralytics import YOLO
# Load a model
model = YOLO('path/to/model.pt') # Load a official model or custom model
# Export the model
model.export(format='edgetpu') But after, it says to run the model with YOLO, with following code: from ultralytics import YOLO
# Load a model
model = YOLO('path/to/edgetpu_model.tflite') # Load a official model or custom model
# Run Prediction
model.predict("path/to/source.png") So then we are not running the model on Coral, but on our local device, right? If that is true, please say if we need to use that exported model with something like |
Beta Was this translation helpful? Give feedback.
-
Hello, i would also add a question here, since i am running a yolov8 model on a Raspberry Pi 4, baught a Coral TPU Accelerator, installed everything like described, but the following code runs into the following issue. Since there is no real pycoral support anymore, i try my luck here, maybe someone has an idea how to fix that.
And the output is:
Greetings Markus |
Beta Was this translation helpful? Give feedback.
-
Hi Glenn, and thanks a lot for your reply. I implemented your suggested fix and this leads to the following:
Good hint with the versions. I often read about that and the currently installed versions are: Name: pycoral Python 3.9.2 Raspberry Pi 4: Debian GNU/Linux 11 (bullseye) And the way i exported the yolov8 to .tflite, was with this code snippet:
Is this the proper way of exporting a yolov8 --> .tflite? I am thankful for every hint, which i will follow. |
Beta Was this translation helpful? Give feedback.
-
Hi Glenn, Of course i tried your suggestions, so i used Google Colab to compile the .tflite model to a "edgetpu.tflite" model, but now the following error occurs by running the (not changed) code:
If you have another hint for that i will try, but to be honest i don't feel fun with Google's Coral TPU Accelerator. I had a simple code, using YOLOv8 and the predict() method, but this unfortunately uses too much CPU on the Raspberry Pi. That is why i thought Google Coral could be it, but hm ... maybe not. Thanks for your help and if you have a clue why this error now occurs, feel free to tell me, otherwise i think i will send the Coral back to Amazon :-( |
Beta Was this translation helpful? Give feedback.
-
I followed the instructions above but still have problems getting it to work. After installing Ultralytics in an environment I run following: wget https://github.com/feranick/libedgetpu/releases/download/16.0TF2.16.1-1/libedgetpu1-std_16.0tf2.16.1-1.bookworm_arm64.deb
sudo dpkg -i libedgetpu1-std_16.0tf2.16.1-1.bookworm_arm64.deb
wget https://github.com/feranick/libedgetpu/releases/download/16.0TF2.16.1-1/libedgetpu-dev_16.0tf2.16.1-1.bookworm_arm64.deb
sudo dpkg -i libedgetpu-dev_16.0tf2.16.1-1.bookworm_arm64.deb
#https://github.com/JungLearnBot/RPi5_yolov8/blob/main/Readme.RPi5.coral_tpu.picam.qt.md
wget https://github.com/oberluz/pycoral/releases/download/2.13.0/pycoral-2.13.0-cp311-cp311-linux_aarch64.whl
pip install pycoral-2.13.0-cp311-cp311-linux_aarch64.whl --no-deps
pip install tflite-runtime==2.14.0 export always fails: Ultralytics YOLOv8.1.43 🚀 Python-3.11.2 torch-2.2.2 CPU (Cortex-A76)
YOLOv8n summary (fused): 168 layers, 3151904 parameters, 0 gradients, 8.7 GFLOPs
�[34m�[1mPyTorch:�[0m starting from 'yolov8n.pt' with input shape (1, 3, 640, 640) BCHW and output shape(s) (1, 84, 8400) (6.2 MB)
�[34m�[1mTensorFlow SavedModel:�[0m starting export with tensorflow 2.16.1...
WARNING ⚠️ tensorflow<=2.13.1 is required, but tensorflow==2.16.1 is currently installed https://github.com/ultralytics/ultralytics/issues/5161
�[34m�[1mONNX:�[0m starting export with onnx 1.16.0 opset 17...
�[34m�[1mONNX:�[0m simplifying with onnxsim 0.4.36...
�[34m�[1mONNX:�[0m export success ✅ 2.6s, saved as 'yolov8n.onnx' (12.3 MB)
�[34m�[1mTensorFlow SavedModel:�[0m starting TFLite export with onnx2tf 1.17.5...
�[07mAutomatic generation of each OP name started�[0m ========================================
�[32mAutomatic generation of each OP name complete!�[0m
�[07mModel loaded�[0m ========================================================================
�[07mModel conversion started�[0m ============================================================
�[33mWARNING:�[0m The optimization process for shape estimation is skipped because it contains OPs that cannot be inferred by the standard onnxruntime.
�[33mWARNING:�[0m module 'onnx' has no attribute '_serialize'
�[31mERROR:�[0m The trace log is below.
Traceback (most recent call last):
File "/home/pi/yolo_env/lib/python3.11/site-packages/onnx2tf/utils/common_functions.py", line 288, in print_wrapper_func
result = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/yolo_env/lib/python3.11/site-packages/onnx2tf/utils/common_functions.py", line 361, in inverted_operation_enable_disable_wrapper_func
result = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/yolo_env/lib/python3.11/site-packages/onnx2tf/ops/Conv.py", line 246, in make_node
input_tensor = get_padding_as_op(
^^^^^^^^^^^^^^^^^^
File "/home/pi/yolo_env/lib/python3.11/site-packages/onnx2tf/utils/common_functions.py", line 2009, in get_padding_as_op
return tf.pad(x, padding)
^^^^^^^^^^^^^^^^^^
File "/home/pi/yolo_env/lib/python3.11/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/home/pi/yolo_env/lib/python3.11/site-packages/keras/src/backend/common/keras_tensor.py", line 91, in __tf_tensor__
raise ValueError(
ValueError: A KerasTensor cannot be used as input to a TensorFlow function. A KerasTensor is a symbolic placeholder for a shape and dtype, used when constructing Keras Functional models or Keras Functions. You can only use it as input to a Keras layer or a Keras operation (from the namespaces `keras.layers` and `keras.operations`). You are likely doing something like:
x = Input(...)
class MyLayer(Layer): x = MyLayer()(x)
I ran the export in colab and the export worked, even though it errors out there too. So I used the colab exports and copied them to the RPi5, created the python file with make_interpreter, but get this error as described here too: Traceback (most recent call last):
File "/home/pi/tpu_detect.py", line 13, in <module>
detections = detect.get_objects(interpreter, scale)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pi/yolo_env/lib/python3.11/site-packages/pycoral/adapters/detect.py", line 210, in get_objects
count = int(interpreter.tensor(signature['outputs']['output_0'])()[0])
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: 'output_0' What am I missing? Has anyone applied this to an RPi5 successfully? |
Beta Was this translation helpful? Give feedback.
-
I encountered similar challenges and ultimately developed a "solution". I contribute to a PyPI package designed to support the Ultralytics community, specifically for Raspberry Pi users employing the EDGE TPU USB Accelerator. This package simplifies the setup process by ensuring the correct versions of necessary runtimes are installed with just a single pip and setup command. It also provides several default YOLO models for immediate download and experimentation. I hope this information is useful to you. GitHub:https://github.com/DAVIDNYARKO123/edge-tpu-silva PyPi:https://pypi.org/project/edge-tpu-silva/ YouTube:https://www.youtube.com/watch?v=sOxQTRRh9tw I just posted the video above after seeing this post. |
Beta Was this translation helpful? Give feedback.
-
Is this also supported for M.2 Accelerator A+E key instead of USB? I am currently connecting directly to that interface on my RPi 5. |
Beta Was this translation helpful? Give feedback.
-
Hi @pderrenger: Hi @DAVIDNYARKO123: |
Beta Was this translation helpful? Give feedback.
-
@DAVIDNYARKO123: |
Beta Was this translation helpful? Give feedback.
-
Hello my friends from Earth. |
Beta Was this translation helpful? Give feedback.
-
Hi there everyone! Any stable solution for using Coral Accelerator USB? Thanks in advanced! |
Beta Was this translation helpful? Give feedback.
-
to get it working (USB Asselerator) on raspberry pi 4b (Bullseye or Bookworm):
follow official https://coral.ai/docs/accelerator/get-started/#requirements to install on Linux. After that: Download pycoral-2.0.0-cp39-cp39-linux_aarch64.whl and tflite_runtime-2.5.0.post1-cp39-cp39-linux_aarch64.whl from https://github.com/google-coral/pycoral/releases/tag/v2.0.0
you can also see example with picamera2 on Bullseye - https://youtu.be/37PwrRVP9j4
Have a nice day. |
Beta Was this translation helpful? Give feedback.
-
can anyone share metrics of FPS for Ultralytics models on Coral.AI USD TPU? |
Beta Was this translation helpful? Give feedback.
-
Hello, I moved ahead with your manual, thank you so much for that, but finally spent already few days, and still haven't receive any positive result
RAspberryPi5, RAM-8
my pip list
+(test1) ildaron@raspberrypi:~ $ pip list
+Package Version
+------------------ -----------
+certifi 2024.7.4
+charset-normalizer 3.3.2
+contourpy 1.2.1
+cycler 0.12.1
+filelock 3.15.4
+fonttools 4.53.1
+fsspec 2024.6.1
+idna 3.7
+Jinja2 3.1.4
+kiwisolver 1.4.5
+MarkupSafe 2.1.5
+matplotlib 3.9.2
+mpmath 1.3.0
+networkx 3.3
+numpy 1.26.4
+opencv-python 4.10.0.84
+packaging 24.1
+pip 23.0.1
+psutil 6.0.0
+py-cpuinfo 9.0.0
+pyparsing 3.1.2
+python-dateutil 2.9.0.post0
+pytz 2024.1
+PyYAML 6.0.2
+requests 2.32.3
+scipy 1.14.1
+setuptools 66.1.1
+six 1.16.0
+sympy 1.13.2
+torch 2.4.0
+torchvision 0.19.0
+tqdm 4.66.5
+typing_extensions 4.12.2
+tzdata 2024.1
+ultralytics 8.2.79
+ultralytics-thop 2.0.5
+urllib3 2.2.2
2. Information about RAaspberry
-PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
-NAME="Debian GNU/Linux"
-VERSION_ID="12"
-VERSION="12 (bookworm)"
-VERSION_CODENAME=bookworm
-ID=debian
-HOME_URL="https://www.debian.org/"
-SUPPORT_URL="https://www.debian.org/support"
-BUG_REPORT_URL="https://bugs.debian.org/"
ildaron@raspberrypi:~ $
ildaron@raspberrypi:~ $ uname -a
-Linux raspberrypi 6.6.31+rpt-rpi-2712 #1 SMP PREEMPT Debian 1:6.6.31-1+rpt1 (2024-05-29) aarch64 GNU/Linux
3.
When I want to install the library, I receive the next error, I tried all versions that I found in GitHub in different environments but the result always was negative, can you give me some advice on what I can do?
(test1) ildaron@raspberrypi:~ $ sudo dpkg -i ~/Downloads/libedgetpu-dev_16.0tf2.17.0-1.bookworm_arm64.deb
dpkg: warning: downgrading libedgetpu-dev from 16.0tf2.17.0-1.bullseye to 16.0tf2.17.0-1.bookworm
(Reading database ... 268821 files and directories currently installed.)
Preparing to unpack .../libedgetpu-dev_16.0tf2.17.0-1.bookworm_arm64.deb ...
Unpacking libedgetpu-dev (16.0tf2.17.0-1.bookworm) over (16.0tf2.17.0-1.bullseye) ...
dpkg: dependency problems prevent configuration of libedgetpu-dev:
libedgetpu-dev depends on libedgetpu1-std (= 16.0tf2.17.0-1.bookworm) | libedgetpu1 (= 16.0tf2.17.0-1.bookworm); however:
Package libedgetpu1 is not installed.
dpkg: error processing package libedgetpu-dev (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:
libedgetpu-dev
|
Beta Was this translation helpful? Give feedback.
-
Hi @zoldaten in the link that you provided I tuck in the next step, do you know how I can fix it
|
Beta Was this translation helpful? Give feedback.
-
I'm not using RaspberryPi, but I appear to have succesfully converted s couple of yolov8 models and seem to be running them on the TPU. I get ~45mS inference time with the nano model and ~335ms with the small model, presumably becasuse it is too large for the TPU. I have multiple TPUs, can I specify which to use when i do:
My goal is to use one TPU for MobilenetSSD_v2 and the other for yolo8 , so I can run on lessor hardware, (Celeron or Atom class) right now it needs either an 8th generation iGPU or a system with NVidia GPU. My project is here: |
Beta Was this translation helpful? Give feedback.
-
Hello, @Skillnoob really, thank you so much for your support, I hope in this time you also will help me, I was sure that all my problems were solved but now I have an unusual situation. Shortly just repeat my message from 2 weeks ago about what I did "start repeat the last message"
In RaspberryPi
launch python.py with yolov8n_full_integer_quant.tflite model and you have 7 FPS Why is strange, because just Yolo model works, directly in RaspberryPi in format - ".pt" I can detect objects in low FPS, so I can confirm that ".pt" is correct But after I converted the model to Coral format (I used really all available models for Coral )
I receive the next result. So again everything works for 100 images but didn't work for 600 images Probably need a clear memory or something? Because it's very strange, it all worked for a small dataset, also the YOLO model definitely works, but the conversion is incorrect now. |
Beta Was this translation helpful? Give feedback.
-
Hi @Skillnoob finally it works. I used exactly the same scripts in Google Colab (for training and convert model), and removed ultralytics after that I installed !pip install ultralytics==8.0.134 which didn't help It definitely doesn't make sense to me because for a few days I used these scripts without any results and I believe it is not necessary to reinstall the library for Google Colab because after disconnecting from Google Drive, let say, RAM is erasing for all installed libraries, so don't what happened |
Beta Was this translation helpful? Give feedback.
-
It would be fantastic to have something as straightforward for Hailo. While Hailo is theoretically superior to Coral in nearly every aspect, working with it has proven to be quite a challenge for me. |
Beta Was this translation helpful? Give feedback.
-
(detect) jinxin@raspberrypi: F driver/usb/usb_driver.cc:857] transfer on tag 1 failed. Abort. Deadline exceeded: USB transfer error 2 [LibUsbDataOutCallback] |
Beta Was this translation helpful? Give feedback.
-
In ultralytics==8.3.23 I'm finding an issue when trying to run model.predict. The issue appears during preprocessing, the preprocessor is trying to put the image in the device ":0" and that obviously fails.
|
Beta Was this translation helpful? Give feedback.
-
Hello, I noticed the compatible hardware is only limited to pi 4B or 5 recommended. Would this run on a pi zero 2W? The original coral docs shows it is compatible but I was curious if so with YOLO11. |
Beta Was this translation helpful? Give feedback.
-
first of all thank you for the amazing instructions for both creating the .tflite using colab and running inference on the raspberry pi. I'm waiting on delivery of my 8Gb rPI5 but in the interim I ran the following tests using a 2Gb rPI4 and found that Yolov8n outperformed Yolov11n. YOLOV8 0: 640x640 1 person, 145.8ms 0: 640x640 1 person, 142.8ms 0: 640x640 1 person, 115.8ms YOLOV11 0: 640x640 1 person, 422.6ms 0: 640x640 1 person, 430.1ms 0: 640x640 1 person, 382.6ms Any insights into why the older version is faster? |
Beta Was this translation helpful? Give feedback.
-
guides/coral-edge-tpu-on-raspberry-pi/
Guide on how to use Ultralytics with a Coral Edge TPU on a Raspberry Pi for increased inference performance.
https://docs.ultralytics.com/guides/coral-edge-tpu-on-raspberry-pi/
Beta Was this translation helpful? Give feedback.
All reactions