Install and Test of Yolov8 on Raspberry Pi5 with USB Coral TPU
To just install yolov8 on Raspberry Pi5 with TPU simply type:
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get autoremove -y
python3 -m venv yolo_env
source yolo_env/bin/activate
pip3 install ultralytics
There is also a shell scrip available for download, which includes the same lines above and the additional download of the GardenCam vodeos and models plus test runs:
wget https://github.com/StefansAI/Yolov8_Rpi5_CoralUSB/raw/main/scripts/yolov8_install.sh
chmod +x yolov8_install.sh
./yolov8_install.sh
============================================================================
To run the Coral TPU with the Raspberry Pi 5 I had to research a lot, since nothing was straight forward. One reason is, that Google stopped supporting their software support for their TPU long time ago. But Python has evolved and the old Google installations don't work anymore.
I mainly followed this article: Coral Edge TPU on a Raspberry Pi with Ultralytics YOLOv8, but also JungLearnBot/RPi5_yolov8/Coral_TPU and of course Get started with the USB Accelerator.
It took me some time, where I could not get any exported model to run on the TPU at all. Finally, after some debugging, I had to find out, that there is an implicit name convention mentioned nowhere. Here is the export as recommended:
yolo export model=yolov8n.pt format=edgetpu
Despite the format=edgetpu, this export function creates file names like this for instance:
yolov8n_integer_quant.tflite
But this will never be directed to the TPU. To run it on the TPU, it has to have a name with "_edgetpu.tflite" in the name, like
yolov8n_integer_quant_edgetpu.tflite
So, you'll have to rename all exported files or make a copy to that name to compare both.
I tried to follow the Ultralytics article and in addition installed the edge_tpu_silva-version in a python 3.9 venv for comparison. Overall, both installation test results were the same and disappointing. There is a speed increase from *.pt models to *.tflite models through the optimization, but no difference between CPU and TPU execution. For 640 size the TPU execution even exceeded the CPU time.
Image Size | Model | RPi5-CPU/TPU | RPi5-Execution | Jetson Nano Execution |
---|---|---|---|---|
640 | *.pt | CPU | 385.2ms | 64.4ms |
*int8.ftlite | CPU | 380.3ms | ||
*int8_edgetpu.ftlite | TPU | 383.3ms | ||
320 | *.pt | CPU | 110.5ms | 38.5ms |
*int8.ftlite | CPU | 68.4ms | ||
*int8_edgetpu.ftlite | TPU | 68.2ms | ||
224 | *.pt | CPU | 64.9ms | 37.9ms |
*int8.ftlite | CPU | 27.6ms | ||
*int8_edgetpu.ftlite | TPU | 27.7ms |
To verify that the edgetpu version is really executed on the TPU, I unplugged the USB cable and observed the USB transfer error and the immediate abortion of the execution. The non-edgetpu model kept running when unplugging, so it must have been executed on the CPU only.
To verify the results and install yolov8 plus USB Coral TPU, download an run the script:
wget https://github.com/StefansAI/Yolov8_Rpi5_CoralUSB/raw/main/scripts/yolov8_coral_install.sh
chmod +x yolov8_coral_install.sh
./yolov8_coral_install.sh
This script performs the installation, performs the exports of the yolo models and copying to "_edgetpu.tflite" versions. At the end of the script, the GardenCam videos and the GardenCam models are downloaded to demo the installation for few seconds each. The average python code then calculates the average exeution times for each run and displays the results.