guides/coral-edge-tpu-on-raspberry-pi/ #8398
Replies: 14 comments 57 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.
-
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