Skip to content

Building and Running tflite (Tensorflow Lite) on ARC

Yuriy Kolerov edited this page Aug 1, 2023 · 1 revision

TensorFlow Lite is TensorFlow’s lightweight solution for mobile and embedded devices. It enables on-device machine learning inference with low latency and a small binary size. Now it is possible to compile and run on ARC applications with tflite capabilities. This page describes steps how to build and run tflite demo applications on HSDK board.

Downloading necessary files.

Building tflite requires presence of ARC toolchain on host machine. To download and extract latest release of ARC toolchain in some work folder run:

$ wget https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/releases/download/arc-2018.03-release/arc_gnu_2018.03_prebuilt_uclibc_le_archs_linux_install.tar.gz
$ tar -xvf arc_gnu_2018.03_prebuilt_uclibc_le_archs_linux_install.tar.gz

Then in the same directory download tensorflow repository entering:

git clone https://github.com/tensorflow/tensorflow.git

After downloading is done it is necessary to choose exact branch:

cd tensorflow
git checkout v1.9.0

It is also requires to make some changes in repository, so it will be possible to build "label_image" demo application for ARC. To make this just download these patch , put it in the current tensorflow directory and apply it using command:

git am 0001-Add-build-of-label_image-example.patch

Building tflite demo applications and static library

Tflite is compiled as static library. Tensorflow repository contains some demo applications which are compiled and statically linked with tflite library.

First of all to build tflite and demo applications it is necessary to set up environment variable CC_ARC, which contains path to ARC toolchain. To set up CC_ARC enter:

export CC_ARC=${path_to_work_folder}/arc_gnu_2018.03_prebuilt_uclibc_le_archs_linux_install/bin/arc-linux-

Than from work folder run next commands:

cd tensorflow/tensorflow/contrib/lite
./download_dependencies.sh
./build_arc_lib.sh

Now in the folder gen/bin label_image demo application is stored. It can be integrated in rootfs or placed on SDcard/USB storage.

Running label_image demo application

Label_image application requires model.tflite, label.txt files and image in "bmp" format. These files can be found in this zip archive. Put them in the same directory with label_image app. To run application on HSDK board after Linux is running in folder with label_image and necessary files enter:

./label_image -i <image>.bmp 

The output will be like below:

# ./label_image -i cat.bmp 
Loaded model ./mobilenet_quant_v1_224.tflite
resolved reporter
invoked 
average time: 1360.55 ms 
0.827451: 282 tabby
0.133333: 283 tiger cat
0.0352941: 286 Egyptian cat

Where results shows the probability of presence an object on the image.

Running Linux on HSDK board.

In order to run the demo application on HSDK board you can use prepared sdcard.img, which creates two partitions on SDcard after using "dd" utility (in Linux case). For more information how to use sdcard.img file read Installation paragraph in:

https://github.com/foss-for-synopsys-dwc-arc-processors/buildroot/releases/tag/arc-2017.11-hsdk-release

Plug SDcard into HSDK board and press Reset button. Label_image app and related files are stored in /root directory.

Clone this wiki locally