Running Zephyr TensorFlow‐Micro EthosU Sample on EK‐RA8P1 - renesas/zephyr GitHub Wiki
Zephyr TensorFlow-Micro EthosU Sample on EK-RA8P1
Application: TensorFlow Lite for Microcontrollers on Arm Ethos-U — Zephyr Project Documentation
Generating Vela-compiled Model
1. Download the Model and Test Script
Download the following files from ARM model zoo:
cnn_s_quantized.tflitetesting_input/input/0.npytesting_output/identity/0.npy
2. Open the Bash and Create a Virtual Environment
$ cd path/to/your/model/folder
$ python3 -m venv .venv
3. Source with python virtual environment and install ethos-u-vela:
For Windows with Git bash:
$ source .venv/Scripts/activate
$ pip install ethos-u-vela
For Linux:
$ source .venv/bin/activate
$ pip install ethos-u-vela
4. Optimizing the model for Ethos-U using Vela (RA8P1 is using ETHOS U55 256 variant):
$ vela cnn_s_quantized.tflite --output-dir . --accelerator-config ethos-u55-256 --system-config Ethos_U55_High_End_Embedded --memory-mode Shared_Sram
5. Removing unnecessary header:
$ dd if=testing_input/input/0.npy of=testing_input/input/0_no-header.npy bs=1 skip=128
$ dd if=testing_output/identity/0.npy of=testing_output/identity/0_no-header.npy bs=1 skip=128
6. Converting to C array:
$ xxd -c 16 -i cnn_s_quantized.tflite cnn_s_quantized.tflite.h
$ xxd -c 16 -i cnn_s_quantized_vela.tflite cnn_s_quantized_vela.tflite.h
$ xxd -c 16 -i testing_input/input/0_no-header.npy testing_input/input/0_no-header.npy.h
$ xxd -c 16 -i testing_output/identity/0_no-header.npy testing_output/identity/0_no-header.npy.h
After execute above steps, you will get below output file
- cnn_s_quantized_vela.tflite.h
- testing_input/input/0_no-header.npy.h
- testing_output/Identity/0_no-header.npy.h
Running and verified TensorFlow EthosU sample:
1. Synchronizing to the sample (samples\modules\tflite-micro\tflm_ethosu), replace the sample C array with the output you've generated:
- cnn_s_quantized_vela.tflite.h => model.h
- testing_input/input/0_no-header.npy.h => input.h
- testing_output/Identity/0_no-header.npy.h => output.h
2. Build, flash and verify sample
$ west config manifest.project-filter -- +tflite-micro
$ west update
$ west build -p -b ek_ra8p1/r7ka8p1kflcac/cm85 samples/modules/tflite-micro/tflm_ethosu
$ west flash
Console log: