This example shows how to use Tensorflow Lite Micro together with an embARC MLI application. It consists of two parts:
-
Example application. It demonstrates how to use the tflite-micro API and guides you through the building aspects of the application and libraries.
-
Conversion Tutorial. An independent part showing how the NN model for the application was converted into tflite format and adapted to be MLI compatible.
The first part is disclosed in this readme. The details of the conversion tutorial are covered in the separate readme file in the conversion_tutorial directory. Passing the second part is not necessary to run the example application.
Important notes:
- This example can't be built for x86 platform. The example is supported only for VPX configurations with guard bits. For EM/HS, please use MLI 1.1 release version.
To build and run the example application at first you need to generate tflite-micro static library.
Tensorflow Lite for Microcontrollers is a separate project with specific set of requirements. We recommend to use embARC fork of Tensorflow Lite for Microcontrollers repository:
git clone https://github.com/foss-for-synopsys-dwc-arc-processors/tflite-micro.git
The fork has been updating periodically from the upstream repo using states that are stable in relation to ARC target.
Please first familiarize yourself with TFLM ARC specific details and make sure that your environment is set up appropriately.
Important information is listed inside make tool section of the referred document. The main message is that native *nix environment is required to build the TFLM library. For Windows users there are no officially supported flow. You still may consider projects like WSL at your own risk.
To build tflite-micro library please find the corresponding section in documentation specified for a custom ARC platform. You need to copy the generated library to the third_party directory of this example and rename it to libtensorflow-microlite.a (see the same documentation on where the generated library can be found).
For the following example application build you should set TENSORFLOW_DIR
environment variable to point to the cloned tflite-micro repository:
# For Windows
set TENSORFLOW_DIR=<your-path-to-tflite-micro>
# For Linux
export TENSORFLOW_DIR=<your-path-to-tflite-micro>
After you've passed "Generate Tensorflow Lite Micro Library" step
you need to configure and build the library project for the desired VPX
configuration. Please read the corresponding section on building the package. Also make sure you didn't forget to set TENSORFLOW_DIR
environment variable.
Build artifacts of the application are stored in the /obj/<project>/examples/tutorial_emnist_tflm
directory where <project>
is defined according to your target platform.
After you've built and configured the whole library project, you can proceed with the following steps.
You need to replace <options>
placeholder in commands below with the same build configuration options list you used for the library configuration and build.
-
Open command line in the root of the embARC MLI repo and change working directory to './examples/tutorial_emnist_tflm/'
cd ./examples/tutorial_emnist_tflm/
-
Clean previous build artifacts (optional).
gmake <options> clean
-
Build the example. This is an optional step as you may go to the next step which automatically invokes the build process.
gmake <options> build
-
Run the example
gmake <options> run
Assuming you've already built and copied libtensorflow-microlite.a and your environment satisfies all build requirements for ARC VPX platform, you can use the following script to build and run the application using the nSIM simulator. The first step is to open a command line and change working directory to the root of the embARC MLI repo.
-
Clean all previous artifacts for all platforms
gmake cleanall
-
Generate recommended TCF file for VPX
tcfgen -o ./hw/vpx5_integer_full.tcf -tcf=vpx5_integer_full -iccm_size=0x80000 -dccm_size=0x40000
-
Build project using generated TCF and appropriate built-in runtime library for it. Use multithreaded build process (4 threads):
gmake TCF_FILE=./hw/vpx5_integer_full.tcf BUILDLIB_DIR=vpx5_integer_full JOBS=4 build
-
Change working directory and build the example:
cd ./examples/tutorial_emnist_tflm gmake TCF_FILE=../../hw/vpx5_integer_full.tcf BUILDLIB_DIR=vpx5_integer_full build
-
Run the example:
gmake TCF_FILE=../../hw/vpx5_integer_full.tcf BUILDLIB_DIR=vpx5_integer_full run