diff options
author | Hongmei Gou | 2020-02-28 16:39:56 -0600 |
---|---|---|
committer | Hongmei Gou | 2020-02-28 16:39:56 -0600 |
commit | bd6a429c21f96d5112e0b6dea44a13b748eefd74 (patch) | |
tree | 51590e9733493a606d9206f655de04f07c82d8c0 | |
parent | 42ce5181fe682d53088bc11a46999198460bd620 (diff) | |
parent | 48b79a09b76f05b3417e6f67b65c84e4a465b054 (diff) | |
download | tensorflow-lite-examples-bd6a429c21f96d5112e0b6dea44a13b748eefd74.tar.gz tensorflow-lite-examples-bd6a429c21f96d5112e0b6dea44a13b748eefd74.tar.xz tensorflow-lite-examples-bd6a429c21f96d5112e0b6dea44a13b748eefd74.zip |
Merge pull request #4 in PROCESSOR-SDK/tensorflow-lite-examples from ~A0271529/tensorflow-lite-examples:demo-integration to masterHEADmaster
* commit '48b79a09b76f05b3417e6f67b65c84e4a465b054':
Add demo scripts and their usage on target in README
-rw-r--r-- | README | 14 | ||||
-rwxr-xr-x | scripts/run_classification.sh | 25 | ||||
-rwxr-xr-x | scripts/run_segmentation.sh | 8 | ||||
-rwxr-xr-x | scripts/run_tidl_compiler.sh | 43 | ||||
-rwxr-xr-x | scripts/run_tidl_compiler1.sh | 45 |
5 files changed, 135 insertions, 0 deletions
@@ -51,3 +51,17 @@ Binaries to run on target | |||
51 | --input_std, -s: input standard deviation | 51 | --input_std, -s: input standard deviation |
52 | --profiling, -p: [0|1], profiling or not | 52 | --profiling, -p: [0|1], profiling or not |
53 | --threads, -t: number of threads | 53 | --threads, -t: number of threads |
54 | |||
55 | Demos packaged with Processor SDK | ||
56 | --------------------------------- | ||
57 | * Classification demo with Arm only, full TIDL offload, and partial TIDL offload (heterogeneous execution) | ||
58 | # cd /usr/share/tensorflow-lite/demos | ||
59 | # ./run_tidl_compiler.sh [This is creating mobilenet_v1_1.0_224_tidl_am5.tflite, .bin files, and subgraph0.cfg for full TIDL offload] | ||
60 | # ./run_classification.sh [This runs Arm only classification first, and then with full TIDL offload] | ||
61 | # ./run_tidl_compiler1.sh [This is creating mobilenet_v1_1.0_224_tidl_am5.tflite, .bin files, and subgraph0.cfg for partial TIDL offload,] | ||
62 | [specifying MobilenetV1/MobilenetV1/Conv2d_13_pointwise/Relu6 as the output tensor of the TIDL subgraph] | ||
63 | # ./run_classification.sh [This runs Arm only classification first, and then with partial TIDL offload] | ||
64 | |||
65 | * Arm only segmentation demo: | ||
66 | # cd /usr/share/tensorflow-lite/demos | ||
67 | # ./run_segmentation.sh | ||
diff --git a/scripts/run_classification.sh b/scripts/run_classification.sh new file mode 100755 index 0000000..a92dde8 --- /dev/null +++ b/scripts/run_classification.sh | |||
@@ -0,0 +1,25 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd /usr/share/tensorflow-lite/demos | ||
4 | |||
5 | echo -e "-----------------------------------------------------------------" | ||
6 | echo -e "Running classification using mobilenet_v1_1.0_224.tflite model..." | ||
7 | echo -e "-----------------------------------------------------------------" | ||
8 | |||
9 | # Run tflite_classification binary with the tensorflow lite model, the input image, and the label file specified. | ||
10 | # Classification label is overlayed with the input image. Exit the application after 60 seconds. | ||
11 | ./tflite_classification -m ./mobilenet_v1_1.0_224.tflite -i ../examples/grace_hopper.bmp -l ../examples/labels.txt -p 1 & pid=$! | ||
12 | { sleep 2; kill $pid; } | ||
13 | |||
14 | echo -e | ||
15 | echo -e "--------------------------------------------------------------------------------------------" | ||
16 | echo -e "Running classification using the TIDL compiled model mobilenet_v1_1.0_224_tidl_am5.tflite..." | ||
17 | echo -e "--------------------------------------------------------------------------------------------" | ||
18 | # Run classification with the TIDL compiled tensorflow lite model | ||
19 | # (e.g., mobilenet_v1_1.0_224_tidl_am5.tflite generated from run_tidl_compiler.sh) | ||
20 | # TIDL API uses subgraph0.cfg created from run_tidl_compiler.sh to identify the TIDL network files, | ||
21 | # as well as the boundary conversion parameters between TIDL and Arm | ||
22 | # Classification label is overlayed with the input image. Right click the image display window to exit. | ||
23 | cd /usr/share/tensorflow-lite/demos | ||
24 | ./tflite_classification -m /usr/share/ti/tidl/utils/test/testvecs/config/tflite_models/mobilenet_v1_1.0_224_tidl_am5.tflite \ | ||
25 | -i ../examples/grace_hopper.bmp -l ../examples/labels.txt -p 1 | ||
diff --git a/scripts/run_segmentation.sh b/scripts/run_segmentation.sh new file mode 100755 index 0000000..5caea12 --- /dev/null +++ b/scripts/run_segmentation.sh | |||
@@ -0,0 +1,8 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | cd /usr/share/tensorflow-lite/demos | ||
4 | |||
5 | # Run tflite_segmentation binary with the model and the input image specified. | ||
6 | # The display window shows the input(resized) image, segmentation map, overlay | ||
7 | # of the former two. Right click the image display window to exit. | ||
8 | ./tflite_segmentation -m ./deeplabv3_257_mv_gpu.tflite -i ./bird_segmentation.bmp | ||
diff --git a/scripts/run_tidl_compiler.sh b/scripts/run_tidl_compiler.sh new file mode 100755 index 0000000..db6d7b6 --- /dev/null +++ b/scripts/run_tidl_compiler.sh | |||
@@ -0,0 +1,43 @@ | |||
1 | #!/bin/sh | ||
2 | # ======================================================================================================= | ||
3 | # Run tidl import tool to convert the original tensorflow lite model (e.g., mobilenet_v1_1.0_224.tflite) | ||
4 | # to TIDL netowrk. The converted TIDL network are stored into tidl_net*.bin and tidl_param_*.bin files | ||
5 | # (e.g., tidl_net_tflite_mobilenet_v1_1.0_224.bin, and tidl_param_tflite_mobilenet_v1_1.0_224.bin). | ||
6 | # The TIDL supported subgraph are grouped as single custom operator (tidl-am5-custom-op) in tensorflow lite | ||
7 | # format, and re-written into a new tensorflow lite model (e.g.,mobilenet_v1_1.0_224_tidl_am5.tflite) | ||
8 | # ======================================================================================================= | ||
9 | # 1. Prepare the input: tensorflow lite model | ||
10 | cd /usr/share/ti/tidl/utils | ||
11 | mkdir -p ./test/testvecs/config/tflite_models | ||
12 | mkdir -p ./test/testvecs/config/tidl_models/tflite/ | ||
13 | cp /usr/share/tensorflow-lite/demos/mobilenet_v1_1.0_224.tflite ./test/testvecs/config/tflite_models | ||
14 | |||
15 | #2. Run tidl_model_import.out | ||
16 | tidl_model_import.out ./test/testvecs/config/import/tflite/tidl_import_mobileNetv1.txt | ||
17 | |||
18 | #3. Check the output and create subgraph0.cfg for TIDL offload at run-time | ||
19 | |||
20 | # TIDL *.bin files are generated at /usr/share/ti/tidl/utils/test/testvecs/config/tidl_models/tflite | ||
21 | # *tidl_am5.tflite model is generated at /usr/share/ti/tidl/utils/test/testvecs/config/tflite_models | ||
22 | ls -l /usr/share/ti/tidl/utils/test/testvecs/config/tidl_models/tflite | ||
23 | ls -l /usr/share/ti/tidl/utils/test/testvecs/config/tflite_models | ||
24 | |||
25 | echo "Creating subgraph0.cfg at /usr/share/tensorflow-lite/demos..." | ||
26 | echo "subgraph0.cfg will be used by TIDL API for the run-time offload" | ||
27 | subgraph0_cfg_path=/usr/share/tensorflow-lite/demos/subgraph0.cfg | ||
28 | # Specify TIDL network files | ||
29 | echo "netBinFile = "/usr/share/ti/tidl/utils/test/testvecs/config/tidl_models/tflite/tidl_net_tflite_mobilenet_v1_1.0_224.bin"" > $subgraph0_cfg_path | ||
30 | echo "paramsBinFile = "/usr/share/ti/tidl/utils/test/testvecs/config/tidl_models/tflite/tidl_param_tflite_mobilenet_v1_1.0_224.bin"" >> $subgraph0_cfg_path | ||
31 | # Sepcify the boundary conversion parameters, see details at https://downloads.ti.com/mctools/esd/docs/tidl-api/api.html | ||
32 | # The input is in NHWC format and ranges [-1,1] | ||
33 | echo "inConvType = 0" >> $subgraph0_cfg_path | ||
34 | echo "inIsSigned = 1" >> $subgraph0_cfg_path | ||
35 | echo "inScaleF2Q = 128" >> $subgraph0_cfg_path | ||
36 | echo "inIsNCHW = 0" >> $subgraph0_cfg_path | ||
37 | # The output is in NHWC format and ranges [0,1] | ||
38 | echo "outConvType = 0" >> $subgraph0_cfg_path | ||
39 | echo "outIsSigned = 0" >> $subgraph0_cfg_path | ||
40 | echo "outScaleF2Q = 255.0" >> $subgraph0_cfg_path | ||
41 | echo "outIsNCHW = 0" >> $subgraph0_cfg_path | ||
42 | echo "subgraph0.cfg:" | ||
43 | cat $subgraph0_cfg_path | ||
diff --git a/scripts/run_tidl_compiler1.sh b/scripts/run_tidl_compiler1.sh new file mode 100755 index 0000000..f644cae --- /dev/null +++ b/scripts/run_tidl_compiler1.sh | |||
@@ -0,0 +1,45 @@ | |||
1 | #!/bin/sh | ||
2 | # ======================================================================================================= | ||
3 | # Run tidl import tool to convert the original tensorflow lite model (e.g., mobilenet_v1_1.0_224.tflite) | ||
4 | # to TIDL netowrk. The converted TIDL network are stored into tidl_net*.bin and tidl_param_*.bin files | ||
5 | # (e.g., tidl_net_tflite_mobilenet_v1_1.0_224.bin, and tidl_param_tflite_mobilenet_v1_1.0_224.bin). | ||
6 | # The TIDL supported subgraph are grouped as single custom operator (tidl-am5-custom-op) in tensorflow lite | ||
7 | # format, and re-written into a new tensorflow lite model (e.g.,mobilenet_v1_1.0_224_tidl_am5.tflite) | ||
8 | # ======================================================================================================= | ||
9 | # 1. Prepare the input: tensorflow lite model | ||
10 | cd /usr/share/ti/tidl/utils | ||
11 | mkdir -p ./test/testvecs/config/tflite_models | ||
12 | mkdir -p ./test/testvecs/config/tidl_models/tflite/ | ||
13 | cp /usr/share/tensorflow-lite/demos/mobilenet_v1_1.0_224.tflite ./test/testvecs/config/tflite_models | ||
14 | |||
15 | #2. Run tidl_model_import.out with the output tensor (other than the model output) specified for partial TIDL offload | ||
16 | # The operators after the specified output tensor will remain as tensorflow lite operators (to be executed on Arm). | ||
17 | # The beginning subgraph is represented as a single tensorflow lite custom operator (tidl-am5-custom-op) (for TIDL offload). | ||
18 | tidl_model_import.out ./test/testvecs/config/import/tflite/tidl_import_mobileNetv1.txt MobilenetV1/MobilenetV1/Conv2d_13_pointwise/Relu6 | ||
19 | |||
20 | #3. Check the output and create subgraph0.cfg for TIDL offload at run-time | ||
21 | |||
22 | # TIDL *.bin files are generated at /usr/share/ti/tidl/utils/test/testvecs/config/tidl_models/tflite | ||
23 | # *tidl_am5.tflite model is generated at /usr/share/ti/tidl/utils/test/testvecs/config/tflite_models | ||
24 | ls -l /usr/share/ti/tidl/utils/test/testvecs/config/tidl_models/tflite | ||
25 | ls -l /usr/share/ti/tidl/utils/test/testvecs/config/tflite_models | ||
26 | |||
27 | echo "Creating subgraph0.cfg at /usr/share/tensorflow-lite/demos..." | ||
28 | echo "subgraph0.cfg will be used by TIDL API for the run-time offload" | ||
29 | subgraph0_cfg_path=/usr/share/tensorflow-lite/demos/subgraph0.cfg | ||
30 | # Specify TIDL network files | ||
31 | echo "netBinFile = "/usr/share/ti/tidl/utils/test/testvecs/config/tidl_models/tflite/tidl_net_tflite_mobilenet_v1_1.0_224.bin"" > $subgraph0_cfg_path | ||
32 | echo "paramsBinFile = "/usr/share/ti/tidl/utils/test/testvecs/config/tidl_models/tflite/tidl_param_tflite_mobilenet_v1_1.0_224.bin"" >> $subgraph0_cfg_path | ||
33 | # Sepcify the boundary conversion parameters, see details at https://downloads.ti.com/mctools/esd/docs/tidl-api/api.html | ||
34 | # The input is in NHWC format and ranges [-1,1] | ||
35 | echo "inConvType = 0" >> $subgraph0_cfg_path | ||
36 | echo "inIsSigned = 1" >> $subgraph0_cfg_path | ||
37 | echo "inScaleF2Q = 128" >> $subgraph0_cfg_path | ||
38 | echo "inIsNCHW = 0" >> $subgraph0_cfg_path | ||
39 | # The output is in NHWC format and ranges [0,6] | ||
40 | echo "outConvType = 0" >> $subgraph0_cfg_path | ||
41 | echo "outIsSigned = 0" >> $subgraph0_cfg_path | ||
42 | echo "outScaleF2Q = 42.5" >> $subgraph0_cfg_path | ||
43 | echo "outIsNCHW = 0" >> $subgraph0_cfg_path | ||
44 | echo "subgraph0.cfg:" | ||
45 | cat $subgraph0_cfg_path | ||