forked from bitcraze/aideck-gap8-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
46 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,64 @@ | ||
# Sample MNIST Build using GAPFlow | ||
# 构建数据集 | ||
|
||
This project includes a sample based on a simple model graph defined in Keras. | ||
- 数据集组织方式: | ||
|
||
It goes from training right through to working code on GAP8 or the same code running on the PC for | ||
debugging purposes. | ||
|
||
* It first trains the network using keras | ||
* It then exports the network to H5 format | ||
* It then converts the H5 file to a TFLITE file using TensorFlow's TFLITE converter | ||
* It then generates an nntool state file by running an nntool script with commands to adjust the tensor and activation order, fuse certain operations together and automatically quantify the graph | ||
* It then uses this state file to generate an AutoTiler graph model | ||
* It then compiles and runs the model to produce GAP8 code | ||
* Finally it builds and runs the produced code on GAP8 | ||
|
||
While this example uses Makefiles the same steps could be achieved with any build system. | ||
``` | ||
\data | ||
\train | ||
\class1 | ||
\xxx.jpg | ||
\xxx.jpg | ||
\class2 | ||
... | ||
\classn | ||
\test | ||
\xxx.jpg | ||
\xxx.jpg | ||
... | ||
\xxx.jpg | ||
``` | ||
|
||
The process can be run to quantize the model in 16 or 8 bits weights and activations. | ||
- data_dir = "训练集根目录" | ||
|
||
## Build and run without Docker | ||
*This example uses the SDK Version `3.8.1`* | ||
- 构建方式 | ||
|
||
To build and run on GAP8: | ||
``` | ||
make all run | ||
``` | ||
To build and run on GVSOC | ||
``` | ||
make all run platform=gvsoc | ||
python dataloader.py | ||
``` | ||
The input image is specified in the Makefile and loaded with the functions defined in ${GAP_SDK_HOME}/libs/gap_lib/img_io/ImgIO.c | ||
|
||
To clean the generated model and code but not the trained network type | ||
``` | ||
make clean | ||
``` | ||
To clean the trained keras save file type | ||
``` | ||
make clean_train | ||
``` | ||
To build and run the network compiled on the pc | ||
``` | ||
make -f emul.mk all | ||
``` | ||
This will produce an executable, model_emul, that can be used to evaluate files | ||
保存生成的train.npz、val.npz文件 | ||
|
||
|
||
# 环境要求 | ||
|
||
- GAP_SDK: release-v3.8.1 (docker or ubuntu) | ||
- Keras: 2.3.1 | ||
- tensorflow: 1.15.2 | ||
- numpy: 1.16.2 | ||
|
||
|
||
# 运行实例 | ||
|
||
- 在GAP8上运行 | ||
|
||
``` | ||
e.g. ./model_emul images/5558_6.pgm | ||
make clean all run' | ||
``` | ||
This mode allows the application to be run with PC tools like valgrind which is very interesting for debugging. | ||
The cluster only has one core in this mode. | ||
|
||
The build defaults to 8 bit quantization. 16 bit quantization can be selected by preceeding the build lines above with QUANT_BITS=16. | ||
- 在gvsoc虚拟平台运行 | ||
|
||
``` | ||
e.g. QUANT_BITS=16 make -f emul.mk all | ||
make clean all run platform=gvsoc | ||
``` | ||
|
||
## Build and run within the docker | ||
*This example uses the SDK Version `3.7`.* | ||
- 固化到芯片 | ||
|
||
Navigate to top-level folder of the example | ||
``` | ||
cd <path/to/ai-deck/repository>/GAP8/ai_examples/gapflow_model_extern/ | ||
``` | ||
Build and execute in Docker similar as the other examples | ||
make clean all image flash | ||
``` | ||
docker run --rm -it -v $PWD:/module/data/ --device /dev/ttyUSB0 --privileged -P gapsdk:3.7 /bin/bash -c 'export GAPY_OPENOCD_CABLE=interface/ftdi/olimex-arm-usb-tiny-h.cfg; source /gap_sdk/configs/ai_deck.sh; cd /module/data/; make clean clean_train clean_model clean_images all run' | ||
|
||
# 清理编译产物 | ||
|
||
``` | ||
make clean clean_train clean_images clean_model | ||
``` |