Skip to content
Branch: master
Find file History
dmitriykovalev Change --image to --input in
PiperOrigin-RevId: 275334724
Latest commit b233aa3 Oct 17, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information. Change --image to --input in Oct 17, 2019 Rename folders to classification and detection. Oct 16, 2019 Make --labels parameter optional Oct 17, 2019 Minor updates to bash scripts. Oct 16, 2019

Image classification example on Coral with TensorFlow Lite

This example uses TensorFlow Lite with Python to run an image classification model with acceleration on the Edge TPU, using a Coral device such as the USB Accelerator or Dev Board.

The Python script takes arguments for the model, labels file, and image you want to process. It then prints the model's prediction for what the image is to the terminal screen.

Set up your device

  1. First, be sure you have completed the setup instructions for your Coral device.

    Importantly, you should have the latest TensorFlow Lite runtime installed (as per the Python quickstart

  2. Clone this Git repo onto your computer:

    mkdir google-coral && cd google-coral
    git clone --depth 1
  3. Install this example's dependencies:

    cd tflite/python/examples/classification

Run the code

Use this command to run image classification with the model and photo downloaded by the above script (photo shown in figure 1):

python3 \
  --model models/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \
  --labels models/inat_bird_labels.txt \
  --input images/parrot.jpg

Figure 1. parrot.jpg

You should see results like this:

Initializing TF Lite interpreter...
INFO: Initialized TensorFlow Lite runtime.
Note: The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory.
Ara macao (Scarlet Macaw): 0.76562

To demonstrate varying inference speeds, the example repeats the same inference five times. Your inference speeds might be different based on your host platform and whether you're using the USB Accelerator with a USB 2.0 or 3.0 connection.

To compare the performance when not using the Edge TPU, try running it again with the model that's not compiled for the Edge TPU:

python3 \
  --model models/mobilenet_v2_1.0_224_inat_bird_quant.tflite \
  --labels models/inat_bird_labels.txt \
  --input images/parrot.jpg
You can’t perform that action at this time.