Introduction
Read moreThis is an example based on Coral USB that performs Image Classification on Raspberry Pi. This example uses TensorFlow Lite with Python on a Raspberry Pi to perform real-time image classification using images streamed from the Pi Camera. It also uses HyperPixel 4.0 Display as the display output.
Features- Real-time Image classification
- Small and compact demo
- Connect Raspberry Pi Camera v1.3 to the Raspberry Pi
- Connect the Coral Accelerator USB to the Raspberry Pi via USB
- Connect the HyperPixel 4.0 via RPI 40-pin
- Before you begin, you need to set up your Raspberry Pi with Raspbian (preferably updated to Buster).
- Configure the camera as follow:
- Update the firmware using the following in the terminal:
sudo apt update
sudo apt full-upgrade
- Configure camera support, use
sudo raspi-config
, select Interface Options and select Camera and Enable the Camera options. - Install the TensorFlow Lite runtime:
pip3 install https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp37-cp37m-linux_armv7l.whl
- Download the Example file from Coral:
git clone https://github.com/tensorflow/examples --depth 1
- Use the script to install python packages and download models and labels:
cd examples/lite/examples/image_classification/raspberry_pi
# The script takes an argument specifying where you want to save the model files
bash download.sh /tmp
Coral USB Accelerating- Follow Coral to install Coral USB into the Raspberry Pi
Now, open classify_picamera.py
file and change as follow:
- Add the following line at the top:
from tflite_runtime.interpreter import load_delegate
- And then find the line that initializes the Interpreter, which looks like this:
interpreter = Interpreter(args.model)
And change it to specify the Edge TPU delegate:
interpreter = Interpreter(args.model,
experimental_delegates=[load_delegate('libedgetpu.so.1.0')])
and save the changes.
- Run the Example!
python3 classify_picamera.py \
--model /tmp/mobilenet_v1_1.0_224_quant.tflite \
--labels /tmp/labels_mobilenet_quant_v1_224.txt
Display on HyperPixelRun the one-line installer:
curl -sSL https://get.pimoroni.com/hyperpixel4 | bash
And choose Raspberry Pi 3B+ model.
Comments