Demo App: Image Labeling

The Image Labeling (Label Image) application demonstrates how to integrate TFLite for image classification tasks on Genio platforms. This utility provides a practical example of loading models, processing images, and delegating execution to hardware accelerators.

IoT Yocto includes two versions of this application:

  • Online Inference: Utilizes the standard TFLite Interpreter to dispatch workloads.

  • Offline Inference: Executes pre-compiled hardware binaries (DLA) directly via the Neuron runtime.

Online Inference Path

The system includes a Python-based image recognition demo in the /usr/share/label_image directory. This application adapts the upstream label_image.py for the Genio environment.

cd /usr/share/label_image
ls -l

-rw-r--r-- 1 root root   940650 Mar  9  2018 grace_hopper.bmp
-rw-r--r-- 1 root root    61306 Mar  9  2018 grace_hopper.jpg
-rw-r--r-- 1 root root    10479 Mar  9  2018 imagenet_slim_labels.txt
-rw-r--r-- 1 root root 95746802 Mar  9  2018 inception_v3_2016_08_28_frozen.pb
-rw-r--r-- 1 root root     4388 Mar  9  2018 label_image.py
-rw-r--r-- 1 root root    10484 Mar  9  2018 labels_mobilenet_quant_v1_224.txt
-rw-r--r-- 1 root root  4276352 Mar  9  2018 mobilenet_v1_1.0_224_quant.tflite

Basic commands for running the demo with different delegates are as follows.

  • Execute on CPU

cd /usr/share/label_image
python3 label_image.py --label_file labels_mobilenet_quant_v1_224.txt --image grace_hopper.jpg --model_file mobilenet_v1_1.0_224_quant.tflite
  • Execute on GPU, with GPU delegate

cd /usr/share/label_image
python3 label_image.py --label_file labels_mobilenet_quant_v1_224.txt --image grace_hopper.jpg --model_file mobilenet_v1_1.0_224_quant.tflite -e /usr/lib/gpu_external_delegate.so

Note

The Stable Delegate demo with python will be released by Yocto v26.0.

Offline Inference Path

The /usr/share/demo_dla directory contains the offline version of the image recognition demo.

cd /usr/share/demo_dla
ls -l
-rw-r--r-- 1 root root   61306 Mar  9  2018 grace_hopper.jpg
-rw-r--r-- 1 root root   10479 Mar  9  2018 imagenet_slim_labels.txt
-rw-r--r-- 1 root root    1402 Mar  9  2018 label_image.py
-rw-r--r-- 1 root root 4276352 Mar  9  2018 mobilenet_v1_1.0_224_quant.tflite

Execute the demo by running python3 label_image.py. The application converts the mobilenet_v1_1.0_224_quant.tflite model into a DLA binary and performs NPU-accelerated inference on the grace_hopper.jpg image. The script outputs the classification result, typically identified as “military uniform”.

cd /usr/share/demo_dla
python3 label_image.py
/usr/share/demo_dla/mobilenet_v1_1.0_224_quant.dla
/usr/share/demo_dla/grace_hopper.bin
WARNING: dlopen failed: libcmdl_ndk.mtk.vndk.so and libcmdl_ndk.mtk.so not found
WARNING: CmdlLibManager cannot get dlopen handle.
[apusys][info]apusysSession: Session(0xaaaaf9d4eb80): thd(runtime_api_sam) version(3) log(0)
The required size of the input buffer is 150528
The required size of the output buffer is 1001
[apusys][info]run: Cmd v2(0xaaaaf9d737e0): run
[apusys][info]run: Cmd v2(0xaaaaf9d737e0): run done(0)
The top index is 653
The image: military uniform

Note

The label_image.py script performs AI inference by calling runtime_api_sample through a Python API wrapper. The runtime_api_sample component itself is implemented as a C/C++ program that uses the Neuron Runtime API. The Neuron Runtime API does not provide an official Python interface. The Python script in this image acts only as a convenience wrapper for benchmarking.