Skip to content

Commit e1e96a6

Browse files
committed
[Example][EMNIST] Fix APplication build and update wordong in readmes/tutorial
1 parent 198a940 commit e1e96a6

File tree

5 files changed

+374
-398
lines changed

5 files changed

+374
-398
lines changed

examples/tutorial_emnist_tflm/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ if (ARC)
2828
-Hxcheck
2929
-Hcrt_initbss
3030
)
31+
get_filename_component(TCF_FILE_NAME ${ARC_CFG_TCF_PATH} NAME_WE)
3132
else()
3233
set(EXAMPLE_FLAGS)
3334
endif()
@@ -41,7 +42,7 @@ add_executable(${TARGET}
4142
./src/test_samples.cc
4243
)
4344

44-
target_link_libraries(${TARGET} PUBLIC $ENV{TENSORFLOW_DIR}/tensorflow/lite/micro/tools/make/downloads/arc_mli_$ENV{TCF_FILE_NAME}_mli20/bin/arc/libmli.a)
45+
target_link_libraries(${TARGET} PUBLIC $ENV{TENSORFLOW_DIR}/tensorflow/lite/micro/tools/make/downloads/arc_mli_${TCF_FILE_NAME}_mli20/bin/arc/libmli.a)
4546
target_link_libraries(${TARGET} PRIVATE tensorflow-microlite)
4647

4748
target_include_directories(${TARGET} PRIVATE

examples/tutorial_emnist_tflm/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ ifeq ($(TENSORFLOW_DIR),)
1313
$(error cannot find tensorflow -- TENSORFLOW_DIR variable must be set)
1414
endif
1515

16+
BUILD_TARGET = tutorial_emnist_tflm
1617
BUILD_SUBDIR = examples$(PS)tutorial_emnist_tflm
1718
BIN_PATH = $(BUILD_DIR)$(PS)$(BUILD_SUBDIR)$(PS)bin
1819

1920
ifndef TCF_FILE
2021
RUN_APP_CMD =
2122
else
22-
RUN_APP_CMD = mdb -cl -nsim -cmd=run -off=cr_for_more -cmd=exit -tcf=$(TCF_FILE)
23+
RUN_APP_CMD = mdb64 -cl -nsim -cmd=run -off=cr_for_more -cmd=exit -tcf=$(TCF_FILE)
2324
BIN_EXT = .elf
2425
endif
2526

26-
export TCF_FILE_NAME = $(basename $(notdir $(TCF_FILE)))
2727
app: build
2828

2929
run:
30-
$(RUN_APP_CMD) $(BIN_PATH)$(PS)tutorial_emnist_tflm$(BIN_EXT) $(RUN_ARGS)
30+
$(RUN_APP_CMD) $(BIN_PATH)$(PS)$(BUILD_TARGET)$(BIN_EXT) $(RUN_ARGS)
3131

3232
.PHONY: app
Lines changed: 45 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
EMNIST Example: Tensorflow Lite Micro Usage
2-
========================================================================
3-
This example shows how to use Tensorflow Lite Micro together with embARC MLI application. It consists of two parts:
1+
# EMNIST Example: Tensorflow Lite Micro Usage
2+
3+
This example shows how to use Tensorflow Lite Micro together with an embARC MLI application. It consists of two parts:
44

55
1) Example application. It demonstrates how to use the tflite-micro API and guides you through the building aspects of the application and libraries.
66

77
2) Conversion Tutorial. An independent part showing how the NN model for the application was converted into tflite format and adapted to be MLI compatible.
88

9-
The first part is disclosed in this readme. The details of the conversion tutorial are covered in the separate [readme](/examples/tutorial_emnist_tflm/conversion_tutorial/README.md) in the [*conversion_tutorial*](/examples/tutorial_emnist_tflm/conversion_tutorial) directory. Passing the second part is not necessary to run the example application.
10-
9+
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*](/examples/tutorial_emnist_tflm/conversion_tutorial) directory. Passing the second part is not necessary to run the example application.
1110

1211
**Important notes:**
13-
* Example is supported only for VPX configurations with guard bits. For EM/HS, please use [MLI 1.1 release version](https://github.com/foss-for-synopsys-dwc-arc-processors/embarc_mli/tree/Release_1.1/examples/tutorial_emnist_tflm).
1412

15-
16-
# Building and Running
13+
* Example is supported only for VPX configurations with guard bits. For EM/HS, please use [MLI 1.1 release version](https://github.com/foss-for-synopsys-dwc-arc-processors/embarc_mli/tree/Release_1.1/examples/tutorial_emnist_tflm).
1714

1815
## Generate Tensorflow Lite Micro Library
1916

@@ -23,40 +20,36 @@ Tensorflow Lite for Microcontrollers is a separate project with specific set of
2320

2421
git clone https://github.com/foss-for-synopsys-dwc-arc-processors/tflite-micro.git
2522

26-
The fork has been updating periodically from the [upstream repo](https://github.com/tensorflow/tflite-micro) using states that are stable in relation to ARC target:
23+
The fork has been updating periodically from the [upstream repo](https://github.com/tensorflow/tflite-micro) using states that are stable in relation to ARC target.
2724

28-
Please first familiarize yourself with [TFLM ARC specific details](https://github.com/foss-for-synopsys-dwc-arc-processors/tflite-micro/blob/main/tensorflow/lite/micro/tools/make/targets/arc/README.md) and make sure that your environment is set up appropriately.
25+
Please first familiarize yourself with [TFLM ARC specific details](https://github.com/foss-for-synopsys-dwc-arc-processors/tflite-micro/blob/main/tensorflow/lite/micro/tools/make/targets/arc/README.md) and make sure that your environment is set up appropriately.
2926

30-
Important information is listed inside [make tool section](https://github.com/foss-for-synopsys-dwc-arc-processors/tflite-micro/tree/main/tensorflow/lite/micro/tools/make/targets/arc#make-tool) of the referred document.
31-
The main message is that native *nix environment is required to build the TFLM library.
32-
For Windows users there are no officially supported flow.
27+
Important information is listed inside [make tool section](https://github.com/foss-for-synopsys-dwc-arc-processors/tflite-micro/tree/main/tensorflow/lite/micro/tools/make/targets/arc#make-tool) of the referred document.
28+
The main message is that native *nix environment is required to build the TFLM library.
29+
For Windows users there are no officially supported flow.
3330
You still may consider projects like [WSL](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux) at your own risk.
3431

35-
To build **tflite-micro** library please find the corresponding section in documentation specified for a [custom ARC platform](https://github.com/foss-for-synopsys-dwc-arc-processors/tflite-micro/tree/main/tensorflow/lite/micro/tools/make/targets/arc#Custom-ARC-EMHSVPX-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).
36-
32+
To build **tflite-micro** library please find the corresponding section in documentation specified for a [custom ARC platform](https://github.com/foss-for-synopsys-dwc-arc-processors/tflite-micro/tree/main/tensorflow/lite/micro/tools/make/targets/arc#Custom-ARC-EMHSVPX-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).
3733

38-
## Building and running example
34+
For the following example application build you should set ``TENSORFLOW_DIR``
35+
environment variable to point to the cloned tflite-micro repository:
3936

40-
Before building the application you should set ``TENSORFLOW_DIR`` environment variable to point to your Tensorflow top folder:
37+
# For Windows
38+
set TENSORFLOW_DIR=<your-path-to-tflite-micro>
4139

42-
```bash
43-
# For Windows
44-
set TENSORFLOW_DIR=\{your-path-to-tflite-micro\}
40+
# For Linux
41+
export TENSORFLOW_DIR=<your-path-to-tflite-micro>
4542

46-
# For Linux
47-
export TENSORFLOW_DIR=\{your-path-to-tflite-micro\}
48-
```
43+
## Building and Running Example
4944

50-
After that you need to configure and build the library project for the desired VPX
51-
configuration.
52-
Please read the corresponding section on [building the package](/README.md#building-the-package).
53-
54-
**Known Issue:** To successfully build this example you need to invoke build process from the */examples/tutorial_emnist_tflm* folder.
45+
After you've passed ["Generate Tensorflow Lite Micro Library"](#generate-tensorflow-lite-micro-library) step
46+
you need to configure and build the library project for the desired VPX
47+
configuration. Please read the corresponding section on [building the package](/README.md#building-the-package). **Also make sure you didn't forget to set ``TENSORFLOW_DIR`` environment variable.**
5548

5649
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.
5750

58-
After you've built and configured the whole library project, you can proceed with the following steps.
59-
You need to replace `<options>` placeholder in commands below with the same options list you used for the library configuration and build.
51+
After you've built and configured the whole library project, you can proceed with the following steps.
52+
You need to replace `<options>` placeholder in commands below with the same [build configuration options](README.md#build-configuration-options) list you used for the library configuration and build.
6053

6154
1. Open command line in the root of the embARC MLI repo and change working directory to './examples/tutorial_emnist_tflm/'
6255

@@ -66,51 +59,36 @@ You need to replace `<options>` placeholder in commands below with the same opti
6659

6760
gmake <options> clean
6861

69-
3. Build the example. This is an optional step as you may go to the next step which automatically invokes the build process.
62+
3. Build the example. This is an optional step as you may go to the next step which automatically invokes the build process.
7063

7164
gmake <options> build
7265

7366
4. Run the example
7467

7568
gmake <options> run
7669

77-
## ARC VPX Build Process Example
70+
## ARC VPX Build Process Example
7871

79-
Assuming your environment satisfies all build requirements for ARC VPX platform, you can use the following script to build and run application using the nSIM simulator.
72+
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.
8073
The first step is to open a command line and change working directory to the root of the embARC MLI repo.
8174

8275
1. Clean all previous artifacts for all platforms
83-
```bash
84-
gmake cleanall
85-
```
86-
87-
2. Generate recommended TCF file for VPX
88-
```bash
89-
tcfgen -o ./hw/vpx5_integer_full.tcf -tcf=vpx5_integer_full -iccm_size=0x80000 -dccm_size=0x40000
90-
```
91-
92-
3. Change working directory and build project using generated TCF and appropriate built-in runtime library for it. Use multithreaded build process (4 threads):
93-
```bash
94-
cd ./examples/tutorial_emnist_tflm
95-
gmake TCF_FILE=../../hw/vpx5_integer_full.tcf BUILDLIB_DIR=vpx5_integer_full JOBS=4 build
96-
```
97-
98-
4. Build the example:
99-
```bash
100-
gmake TCF_FILE=../../hw/vpx5_integer_full.tcf BUILDLIB_DIR=vpx5_integer_full build
101-
```
102-
103-
5. Run the example w/o input arguments for all supported data types:
104-
```bash
105-
gmake TCF_FILE=../../hw/vpx5_integer_full.tcf BUILDLIB_DIR=vpx5_integer_full run
106-
```
107-
<!--
108-
Now you can build the example using MetaWare Development Tools:
109-
```bash
110-
gmake app TCF_FILE=<path_to_vpx_tcf_file>
111-
```
112-
And run the example with DesignWare ARC nSIM simulator:
113-
```bash
114-
gmake run TCF_FILE=<path_to_vpx_tcf_file>
115-
```
116-
-->
76+
77+
gmake cleanall
78+
79+
1. Generate recommended TCF file for VPX
80+
81+
tcfgen -o ./hw/vpx5_integer_full.tcf -tcf=vpx5_integer_full -iccm_size=0x80000 -dccm_size=0x40000
82+
83+
1. Build project using generated TCF and appropriate built-in runtime library for it. Use multithreaded build process (4 threads):
84+
85+
gmake TCF_FILE=../../hw/vpx5_integer_full.tcf BUILDLIB_DIR=vpx5_integer_full JOBS=4 build
86+
87+
1. Change working directory and build the example:
88+
89+
cd ./examples/tutorial_emnist_tflm
90+
gmake TCF_FILE=../../hw/vpx5_integer_full.tcf BUILDLIB_DIR=vpx5_integer_full build
91+
92+
1. Run the example:
93+
94+
gmake TCF_FILE=../../hw/vpx5_integer_full.tcf BUILDLIB_DIR=vpx5_integer_full run
Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,39 @@
1-
Model Conversion Tutorial for EMNIST Example
2-
========================================================================
3-
This tutorial shows how to convert EMNIST Tensorflow model into Tensorflow Lite Micro format to furhter usage in application together with embARC MLI.
1+
# Model Conversion Tutorial for EMNIST Example
2+
3+
This tutorial shows how to convert EMNIST Tensorflow model into Tensorflow Lite Micro format for further usage in application together with embARC MLI.
44

55
## Requirements
66

7-
The following dependencies must be installed in your environment.
7+
The following dependencies must be installed in your environment:
8+
89
* Python 3.7
910
* Dependencies from the [requirements.txt](/examples/tutorial_emnist_tflm/conversion_tutorial/requirements.txt) file
10-
* NumPy 1.19.2
11-
* Matplotlib
12-
* Jupyter Lab / Notebook
13-
* TensorFlow 2.5.1
14-
* Keras
15-
* emnist
11+
* NumPy 1.19.2
12+
* Matplotlib
13+
* Jupyter Lab / Notebook
14+
* TensorFlow 2.5.1
15+
* Keras
16+
* emnist
1617

17-
If you are looking for instruction to set-up a compatible environment, then consider the comprehended guide on [TensorFlow](https://www.tensorflow.org/install) installation. We recommend to follow ["Install TensorFlow with pip"](https://www.tensorflow.org/install/pip) and not ignore recommendation on usage of the virtual environment.
18+
If you are looking for instruction to set-up a compatible environment, then consider the comprehensive guide on [TensorFlow](https://www.tensorflow.org/install) installation. We recommend to follow ["Install TensorFlow with pip"](https://www.tensorflow.org/install/pip) and not ignore recommendation on usage of the virtual environment.
1819

1920
Make sure you have installed required version of dependencies listed in the *requirements.txt* file. In case you followed our recommendation on install TensorFlow with pip, for [step 3](https://www.tensorflow.org/install/pip#3.-install-the-tensorflow-pip-package) you can use the following commands instead the proposed ones. First change working directory in terminal to the [conversion_tutorial](/examples/tutorial_emnist_tflm/conversion_tutorial).
2021

21-
```bash
22-
pip3 install -r ./requirements.txt
23-
python3 -c "import emnist; emnist.ensure_cached_data();"
24-
```
22+
pip3 install -r ./requirements.txt
23+
python3 -c "import emnist; emnist.ensure_cached_data();"
2524

2625
## Running Conversion Tutorial
2726

28-
To convert the model, run the Jupyter Notebook:
27+
To convert the model, run the Jupyter Notebook (change working directory in terminal to the [conversion_tutorial](/examples/tutorial_emnist_tflm/conversion_tutorial) if you haven't done it):
2928

30-
```bash
31-
jupyter notebook conversion_tutorial/model_conversion.ipynb
32-
```
29+
jupyter notebook model_conversion.ipynb
3330

34-
After completing the tutorial you should have model and test samples generated.
31+
After completing the tutorial, you should have model and test samples generated.
3532

3633
Please make sure you don't forget to use [Model Adaptation Tool](https://github.com/foss-for-synopsys-dwc-arc-processors/tflite-micro/blob/main/tensorflow/lite/micro/tools/make/targets/arc/adaptation_tool.py) to convert `emnist_model_int8.tflite` you got before saving it as C array.
3734

3835
## Using Converted Model in Application
3936

40-
See [EMNIST example part](/examples/tutorial_emnist_tflm) on how a converted model might be used in application together with TFLM and embARC MLI. It already contains converted model, hence this ste is optional.
41-
42-
To use generated models in the example you need to copy */examples/tutorial_emnist_tflm/conversion_tutorial/generated/model.h* and */examples/tutorial_emnist_tflm/conversion_tutorial/generated/test_samples.cc* to */examples/tutorial_emnist_tflm/src* folder. Make sure that name of buffers and constants in copied files are aligned with the former ones and change them if not. Afterward you can clean, beald and run example application according to instructions.
43-
44-
37+
See [EMNIST example part](/examples/tutorial_emnist_tflm) on how a converted model might be used in application together with TFLM and embARC MLI. The example already contains converted model, hence this step is optional.
4538

39+
To use generated models in the example you need to copy */examples/tutorial_emnist_tflm/conversion_tutorial/generated/model.h* and */examples/tutorial_emnist_tflm/conversion_tutorial/generated/test_samples.cc* to */examples/tutorial_emnist_tflm/src* folder. Make sure that names of buffers and constants in copied files are aligned with the former ones and change them if not. Afterward you can clean, build and run example application according to instructions.

0 commit comments

Comments
 (0)