Last edited 2 weeks ago

How to reproduce an example using PyCoral API

Applicable for STM32MP13x lines, STM32MP15x lines, STM32MP25x lines

This article explains how to reproduce an example using the PyCoral API[1]. The PyCoral is a Python™ API, which is used for three main purposes:

  • Inferencing: facilitates the implementation of neural network inference on Coral Edge TPU™
  • Pipelining: provides functions to pipeline a model on multiple Coral Edge TPUs
  • Transfer learning: enables on device transfer learning

This API is the Python™ equivalent of the C/C++ libcoral API[2].

Several examples can be found on the PyCoral GitHub[3]. This article only shows how to build a semantic segmentation example from scratch. The method used here can easily be applied for other examples.

1. Description[edit source]

This example is based on a semantic segmentation model, which allows identifying and clustering together the pixels of an image belonging to a same class representing an object.

PyCoral API semantic segmentation example

The purpose of this example is beyond the semantic segmentation aspect to demonstrate how to use the PyCoral API to easily realize inferences on Google Coral Edge TPU™[4]

The model used with this example is a deeplabv3 downloaded from the Coral GitHub testing models[5].

2. Installation[edit source]

2.1. Install from the OpenSTLinux AI package repository[edit source]

Warning white.png Warning
The software package is provided AS IS, and by downloading it, you agree to be bound to the terms of the software license agreement (SLA0048). The detailed content licenses can be found here.

After having configured the AI OpenSTLinux package, you can install the X-LINUX-AI components for this example:

 x-linux-ai -i pycoral

2.2. Source code location[edit source]

The Python™ script of this example is located in the PyCoral API examples GitHub [6].

3. How to use the example[edit source]

3.1. Download the example[edit source]

As mentioned before, the Python™ script must be downloaded from the PyCoral API examples GitHub [6].

Clone the PyCoral GitHub:

 git clone
 cd pycoral/examples

To download all the files required by the example, a script named is provided in the examples directory. This script is very easy to use; only the filename must be passed in argument to automatically download all the needed files:


3.2. launch the application[edit source]

Copy the Python™ script and the test data directory onto the board:

 scp -r  ../test_data/ root@<board_ip>:/path/
 scp root@<board_ip>:/path/
Info white.png Information
The Coral Edge TPU™ must be plugged on the board before launching the script.

Launch the example:

 python3 --model test_data/deeplabv3_mnv2_pascal_quant_edgetpu.tflite  --input test_data/bird.bmp
Done. Results saved at semantic_segmentation_result.jpg

Get the results of the segmentation:

 scp root@<board_ip>:/path/semantic_segmentation_result.jpg .

4. References[edit source]