Search This Blog

Thursday, September 30, 2021

Coral TPU for Computer Vision on Raspberry Pi

 The CORAL TPU can be used to speed up Tensorflow on the RPi to give a fairly reasonable rate for computer vision tasks such as object detection, pose estimation, speech recognition.

For examples see:  https://coral.ai/models/object-detection/ 




Assuming Python3 is already installed.....

Install Tensorflow Lite

echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install python3-tflite-runtime

Source info: https://www.tensorflow.org/lite/guide/python


Install Python Coral

sudo apt-get install python3-pycoral


Clone the Coral Examples into a new folder

mkdir pycoral

cd pycoral

git clone https://github.com/google-coral/pycoral.git

source: https://github.com/google-coral/pycoral 


Clone the test data:

git clone https://github.com/google-coral/test_data.git


Give it a go with an image:

pi@pi3:~/code/pycoral/pycoral $ python3 examples/detect_image.py   --model test_data/ssd_mobilenet_v2_coco_quant_postprocess_edgetpu.tflite   --labels test_data/coco_labels.txt   --input ~/images/20211001/images/A21100100192512.jpg



----INFERENCE TIME----

Note: The first inference is slow because it includes loading the model into Edge TPU memory.

274.20 ms

81.01 ms

91.19 ms

72.09 ms

69.50 ms

-------RESULTS--------

car

  id:     2

  score:  0.671875

  bbox:   BBox(xmin=-6, ymin=138, xmax=697, ymax=560)

car

  id:     2

  score:  0.6171875

  bbox:   BBox(xmin=97, ymin=220, xmax=1165, ymax=975)