Image classification example

This example performs image classification with the ClassificationEngine API, using the given classification model, labels file, and image.

In this example, we're using a MobileNet model trained with the iNaturalist birds dataset, so it's great at identifying different types of birds.

Before you begin, you must have already set up your Dev Board or USB Accelerator.

Get the files

Download the files needed for this example:


mkdir -p $EXAMPLE_DIR && cd $EXAMPLE_DIR

curl -O \
-O \

Run the code

First, navigate to the directory with the demos:

# If using the Dev Board:
cd /usr/lib/python3/dist-packages/edgetpu/demo

# If using the USB Accelerator with Debian/Ubuntu:
cd /usr/local/lib/python3.6/dist-packages/edgetpu/demo

# If using the USB Accelerator with Raspberry Pi:
cd /usr/local/lib/python3.5/dist-packages/edgetpu/demo

Now execute with the parrot photo in figure 1:

python3 \
--model $EXAMPLE_DIR/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \
--label $EXAMPLE_DIR/inat_bird_labels.txt \
--image $EXAMPLE_DIR/parrot.jpg
Figure 1. parrot.jpg

You should see results like this:

Ara macao (Scarlet Macaw)
Score :  0.761719

See the source here.

To create your own classification model, read the tutorial about how to Retrain an image classification model.

parrot.jpg is licensed under Creative Commons by Tony Hisgett.