Image classification example

This classify_image.py 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:

EXAMPLE_DIR=$HOME/coral-examples

mkdir -p $EXAMPLE_DIR && cd $EXAMPLE_DIR

curl -O https://dl.google.com/coral/canned_models/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \
-O https://dl.google.com/coral/canned_models/inat_bird_labels.txt \
-O https://coral.withgoogle.com/static/docs/images/parrot.jpg

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 classify_image.py with the parrot photo in figure 1:

python3 classify_image.py \
--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 classify_image.py 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.