aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHongmei Gou2020-02-28 16:39:56 -0600
committerHongmei Gou2020-02-28 16:39:56 -0600
commitbd6a429c21f96d5112e0b6dea44a13b748eefd74 (patch)
tree51590e9733493a606d9206f655de04f07c82d8c0
parent42ce5181fe682d53088bc11a46999198460bd620 (diff)
parent48b79a09b76f05b3417e6f67b65c84e4a465b054 (diff)
downloadtensorflow-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--README14
-rwxr-xr-xscripts/run_classification.sh25
-rwxr-xr-xscripts/run_segmentation.sh8
-rwxr-xr-xscripts/run_tidl_compiler.sh43
-rwxr-xr-xscripts/run_tidl_compiler1.sh45
5 files changed, 135 insertions, 0 deletions
diff --git a/README b/README
index b788fbc..90142b9 100644
--- a/README
+++ b/README
@@ -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
55Demos 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
3cd /usr/share/tensorflow-lite/demos
4
5echo -e "-----------------------------------------------------------------"
6echo -e "Running classification using mobilenet_v1_1.0_224.tflite model..."
7echo -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
14echo -e
15echo -e "--------------------------------------------------------------------------------------------"
16echo -e "Running classification using the TIDL compiled model mobilenet_v1_1.0_224_tidl_am5.tflite..."
17echo -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.
23cd /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
3cd /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
10cd /usr/share/ti/tidl/utils
11mkdir -p ./test/testvecs/config/tflite_models
12mkdir -p ./test/testvecs/config/tidl_models/tflite/
13cp /usr/share/tensorflow-lite/demos/mobilenet_v1_1.0_224.tflite ./test/testvecs/config/tflite_models
14
15#2. Run tidl_model_import.out
16tidl_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
22ls -l /usr/share/ti/tidl/utils/test/testvecs/config/tidl_models/tflite
23ls -l /usr/share/ti/tidl/utils/test/testvecs/config/tflite_models
24
25echo "Creating subgraph0.cfg at /usr/share/tensorflow-lite/demos..."
26echo "subgraph0.cfg will be used by TIDL API for the run-time offload"
27subgraph0_cfg_path=/usr/share/tensorflow-lite/demos/subgraph0.cfg
28# Specify TIDL network files
29echo "netBinFile = "/usr/share/ti/tidl/utils/test/testvecs/config/tidl_models/tflite/tidl_net_tflite_mobilenet_v1_1.0_224.bin"" > $subgraph0_cfg_path
30echo "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]
33echo "inConvType = 0" >> $subgraph0_cfg_path
34echo "inIsSigned = 1" >> $subgraph0_cfg_path
35echo "inScaleF2Q = 128" >> $subgraph0_cfg_path
36echo "inIsNCHW = 0" >> $subgraph0_cfg_path
37# The output is in NHWC format and ranges [0,1]
38echo "outConvType = 0" >> $subgraph0_cfg_path
39echo "outIsSigned = 0" >> $subgraph0_cfg_path
40echo "outScaleF2Q = 255.0" >> $subgraph0_cfg_path
41echo "outIsNCHW = 0" >> $subgraph0_cfg_path
42echo "subgraph0.cfg:"
43cat $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
10cd /usr/share/ti/tidl/utils
11mkdir -p ./test/testvecs/config/tflite_models
12mkdir -p ./test/testvecs/config/tidl_models/tflite/
13cp /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).
18tidl_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
24ls -l /usr/share/ti/tidl/utils/test/testvecs/config/tidl_models/tflite
25ls -l /usr/share/ti/tidl/utils/test/testvecs/config/tflite_models
26
27echo "Creating subgraph0.cfg at /usr/share/tensorflow-lite/demos..."
28echo "subgraph0.cfg will be used by TIDL API for the run-time offload"
29subgraph0_cfg_path=/usr/share/tensorflow-lite/demos/subgraph0.cfg
30# Specify TIDL network files
31echo "netBinFile = "/usr/share/ti/tidl/utils/test/testvecs/config/tidl_models/tflite/tidl_net_tflite_mobilenet_v1_1.0_224.bin"" > $subgraph0_cfg_path
32echo "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]
35echo "inConvType = 0" >> $subgraph0_cfg_path
36echo "inIsSigned = 1" >> $subgraph0_cfg_path
37echo "inScaleF2Q = 128" >> $subgraph0_cfg_path
38echo "inIsNCHW = 0" >> $subgraph0_cfg_path
39# The output is in NHWC format and ranges [0,6]
40echo "outConvType = 0" >> $subgraph0_cfg_path
41echo "outIsSigned = 0" >> $subgraph0_cfg_path
42echo "outScaleF2Q = 42.5" >> $subgraph0_cfg_path
43echo "outIsNCHW = 0" >> $subgraph0_cfg_path
44echo "subgraph0.cfg:"
45cat $subgraph0_cfg_path