- Last edited 8 months ago ago
How to reproduce an example using PyCoral API
This article explains how to reproduce an example using the PyCoral API. 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.
Several examples can be found on the PyCoral GitHub. This article only shows how to build a semantic segmentation example from scratch. The method used here can easily be applied for other examples.
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.
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™
The model used with this example is a deeplabv3 downloaded from the Coral GitHub testing models.
2.1 Install from the OpenSTLinux AI package repository
After having configured the AI OpenSTLinux package, you can install the X-LINUX-AI components for this example:
apt-get install pycoral
2.2 Source code location
The Python™ script semantic_segmentation.py of this example is located in the PyCoral API examples GitHub .
3 How to use the example
3.1 Download the example
As mentioned before, the Python™ script must be downloaded from the PyCoral API examples GitHub .
Clone the PyCoral GitHub:
git clone https://github.com/google-coral/pycoral cd pycoral/examples
To download all the files required by the example, a script named install_requirements.sh is provided in the examples directory. This script is very easy to use; only the filename semantic_segmentation.py must be passed in argument to automatically download all the needed files:
3.2 launch the application
Copy the Python™ script semantic_segmentation.py and the test data directory onto the board:
scp -r ../test_data/ root@<board_ip>:/path/ scp semantic_segmentation.py root@<board_ip>:/path/
Launch the example:
python3 semantic_segmentation.py --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 .