|
| 1 | +EMNIST Convolution Neural Network Example |
| 2 | +======================================================================== |
| 3 | +This example shows how to convert EMNIST Tensorflow model into Tensorflow Lite Micro format and use it in embARC MLI application. |
| 4 | + |
| 5 | +## Requirements |
| 6 | +--------------- |
| 7 | +* MetaWare Development Tools |
| 8 | + * [Order the ARC MetaWare Development Toolkit](https://www.synopsys.com/dw/ipdir.php?ds=sw_metaware) |
| 9 | + * [Evaluation license](https://eval.synopsys.com/) |
| 10 | +* gmake (pre-installed as a part of MetaWare tools) |
| 11 | +* embARC MLI Library |
| 12 | + * `git clone https://github.com/foss-for-synopsys-dwc-arc-processors/embarc_mli` |
| 13 | +* Tensorflow Lite for Microcontrollers (part of Tensorflow) |
| 14 | + * `git clone https://github.com/tensorflow/tensorflow.git` |
| 15 | +* Text Editor |
| 16 | + |
| 17 | +Installation process of the following dependencies is described in [Getting Started](#getting-started) section: |
| 18 | +* Python 3.7 |
| 19 | +* virtualenv (optional) |
| 20 | +* Dependencies from requirements.txt |
| 21 | + * NumPy 1.16.4 |
| 22 | + * Matplotlib |
| 23 | + * Jupyter Lab / Notebook |
| 24 | + * tf-nightly 2.3 |
| 25 | + * Keras |
| 26 | + * emnist |
| 27 | + |
| 28 | +## Getting started |
| 29 | +--------------- |
| 30 | + |
| 31 | +## Install Python and create a virtual environment |
| 32 | + |
| 33 | +0. It is recommended that you uninstall your previous Python distribution. |
| 34 | +1. Download official [Python 3.7 distribution](https://www.python.org/ftp/python/3.7.4/python-3.7.4-amd64.exe). |
| 35 | +2. Install py launcher and pip. Do not add Python to the PATH. After this, the `py` command in command line is your entry point to Python interpreter. |
| 36 | +3. (optional) Install virtualenv with `py -m pip install --upgrade pip virtualenv` |
| 37 | +4. (optional) Create virtual environment with `py -m virtualenv py_env`. |
| 38 | +5. (optional) Activate virtual environment with `./py_env/Scripts/activate`. |
| 39 | +6. Execute ` cd ./embarc_mli/examples/tutorial_emnist_tflm`. |
| 40 | + |
| 41 | +## Install pip requirements |
| 42 | +```bash |
| 43 | +pip install --upgrade pip setuptools |
| 44 | +pip install -r requirements.txt |
| 45 | +python -c "import emnist; emnist.ensure_cached_data(); |
| 46 | +``` |
| 47 | +## Generate Tensorflow Lite Micro library |
| 48 | +Open root directory of tensorflow in terminal (use Cygwin or MinGW terminal if you're on Windows). Run: |
| 49 | +```bash |
| 50 | +make -f tensorflow/lite/micro/tools/make/Makefile TARGET_ARCH=arc microlite |
| 51 | +``` |
| 52 | +Generated library *libtensorflow-microlite.a* can be found in *<tensorflow-dir>/tensorflow/lite/micro/tools/make/gen/<target>/lib*. Copy it to third_party directory of this example. |
| 53 | +
|
| 54 | +## Convert the model |
| 55 | +To convert the model, run the Jupyter Notebook: |
| 56 | +```bash |
| 57 | +jupyter notebook conversion_tutorial/model_conversion.ipynb |
| 58 | +``` |
| 59 | +After completing the tutorial you should have model and test samples generated. Copy *conversion_tutorial/generated/model.h* and *conversion_tutorial/generated/test_samples.cc* to *src* folder. |
| 60 | +
|
| 61 | +Now you can build and run the example with DesignWare ARC nSIM simulator: |
| 62 | +```bash |
| 63 | +gmake app run |
| 64 | +``` |
| 65 | +
|
0 commit comments