Google's Coral USB Accelerator greatly speeds up the processing of Deep Learning models. In this article I'll introduce the Coral USB Accelerator and show how to combine it with the Raspberry Pi 3B+ and TensorFlow Lite to implement real time object detection and video annotation!
A key challenge for the Internet of Things is enabling Edge Devices to exploit Artificial Intelligence (AI). That Edge Devices often lack processing power further complicates this issue.
One solution to this problem is to have Edge Devices delegate AI to Cloud based services, but this then raises the issues of privacy and latency, in addition to requiring internet access.
An alternative is the use of co-processers such as the Movidius NCS v1 and most recently the Coral USB Accelerator. Such co-processers plug into your Edge Device (such as a Raspberry Pi) and take care of the AI processing. No need for uploading data to the Cloud!
The Coral USB Accelerator was originally announced in the summer of 2018. After a slight delay it was quietly launched in March 2019. I ordered a couple straight away, at a cost of $75 per unit. After a couple of weeks they arrived.
The Coral USB Accelerator's dimensions are 65mm x 30mm x 8mm, making it slightly smaller than the Movidius NCS v1. On the hardware side it contains an Edge TensorFlow Processing Unit (TPU) which provides fast Deep Learning inferencing with low power consumption.
Currently the Coral USB Accelerator works only with Linux Debian derivatives, such as Raspbian and Ubuntu. It performs best when connected to devices with a USB 3.0 port, so it will perform slower when connected to the Raspberry Pi's USB 2.0 ports.
In addition to the Coral USB Accelerator Google have also launched (at the time of writing):
Note that the entire Coral "range" is in Beta. This can mean big changes over the next few months.
Setting up the Coral USB Accelerator was pain free. I simply flashed a new SD Card with the latest edition of Raspbian, switched on my Raspberry Pi 3B+ and then followed Google's installation Guide. Within 30 minutes I was running some demos!
The software included with the Coral USB Accelerator includes APIs and demos for:
In addition you can download a set of pre-trained TensorFlow Lite models ready for use with the Coral USB Accelerator.
One of the first things I found out was that the Coral USB Accelerator currently only supports quantized TensorFlow Lite models with the following architectures:
If you have a pre-existing model that supports one of these architectures then you can use the Egde TPU Model Compiler to compile it for use with the Coral USB Accelerator. This only takes a minute or so.
The plan is to allow for more architectures, but at the time of writing there is no timeline for when this will be done.
My first project for the Coral USB Accelerator was to use a TensorFlow model to find objects in a Raspberry Pi video stream. I would then annotate the video stream showing which objects had been found, along with the confidence score for each object.
This would require me to process each frame of video as follows:
The result of this project was as follows:
Demo with a USB Camera
Here you are seeing real time annotated video at a frame rate of 10 frames per second on the Raspberry Pi!
Read on to find out how you can reproduce this!
Here is the setup that I used.
Note that both the Raspberry Pi Camera Module and the USB Camera delivered comparable performance. For comparisons sake, here is a demo with the Raspberry Pi Camera Module performing the image capture:
Demo with Raspberry Pi Camera Module
In addition to installing the standard software for the Coral USB Accelerator you'll need to go through the following steps.
-------
EDIT 13 April 2019: Note that Google are actively developing the Coral Software. This may mean that some of the paths and API's listed below have changed.
-------
sudo apt-get update
sudo apt-get dist-upgrade
My solution uses OpenCV for image processing. Here is a receipe for quickly instaling OpenCV on a Raspberry Pi. It's an old version of OpenCV but it works fine.
sudo apt-get install python-opencv
sudo pip3 install opencv-python==3.3.0.10
sudo apt-get install libjasper-dev
sudo apt-get install libqtgui4
sudo apt-get install libqt4-test
sudo apt-get install libatlas-base-dev
sudo apt-get install libcblas-dev
Adrian Rosebrock's awesome www.bouvet.no/bouvet-deler/utbrudd/smarten-up-your-pi-zero-web-camera-with-image-analysis-and-amazon-web-services-part-1e.
sudo pip3 install imutils
If you are using the Pi Camera Module, ensure that your PiCamera software is up to date (and don't forget to enable the camewww.bouvet.no/bouvet-deler/adding-ai-to-edge-devices-with-the-movidius-neural-compute-stickpip3 install "picamera[array]"
cdwww.theverge.com/circuitbreaker/2019/3/6/18253106/google-ai-developer-new-tools-dev-board-usb-accelerator-camera-coral_ssd_v2_coco_quant_postprocess_edgetpu.tflite
wget storage.googleapis.com/cloud-iot-edge-pretrained-models/canned_models/coco_labels.txt
Use the following link to download my code, again to Raspbian's "Downloads" directory.:
cd ~/Downloads/
wget www.dropbox.com/s/i8mdgys2wav7ooa/coral-live-object-detector-v2.py
Now you are ready to run the code. From the Raspbian Desktop, open a terminal window, navigate to the Raspbian's "Downloads" directory and run:
python3 coral-live-object-detector-v2.py
www.bouvet.no/bouvet-deler/adding-ai-to-edge-devices-with-the-movidius-neural-compute-stick>--model: Absolute path to the TensorFlow Lite model file (if different to that specified over).
Note that this code is provided as-is and is only meant tcoral.withgoogle.com/tutorials/camera-datasheet take much to add some kind of warning when a person is detected, making it easy to enhance this demo to be a fully fledged security camera.....
So far I am very impressed with the Coral USB Accelerator! Compared to the Movidius NCS v1 it was very easy to get started with and I had www.raspberrypi.org/downloads/raspbiantion" project up and running in just a few hours.
Performance wise I found tcoral.withgoogle.com/tutorials/acceleratoretter than that Movidius NCS v1 for the specific use case described in this article, clocking in at up to 10 Frames Per Second (Movidius managed 5 FPS). Note that I was running the Coral USB Accelerator at it's maximum operating frequency, but didn't notice any overheating of the unit.
My next step will be to try out my "Real Time Object Detection and Video Annotation" project on the Raspberry Pi Zero W. If I get this working then I will share my experiences in a new articcoral.withgoogle.com/models 13 April 2019: Trying to install Coral USB support on the PiZero resulting in the following message.
This is disappointing, but hopefully PiZero support will come soon. I'll write a new blog if and when that happens.
-------
Questions? Comments? Feel free to contact me on Twitter under the handle @markawest.