-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathrun_demo.sh
More file actions
168 lines (151 loc) · 4.85 KB
/
run_demo.sh
File metadata and controls
168 lines (151 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/bin/bash
# Show usage
function show_usage() {
cat <<EOF
Usage: run_demo.sh
-h, --help
Display this help message.
--model MODEL
Set name of paddle model.
--device DEVICE
Set device to run.
EOF
}
while (( $# )); do
case "$1" in
-h|--help)
show_usage
exit 0
;;
--model)
if [ $# -gt 1 ]
then
export MODEL_NAME="$2"
shift 2
else
echo 'ERROR: --model requires a non-empty argument' >&2
show_usage >&2
exit 1
fi
;;
--device)
if [ $# -gt 1 ]
then
export DEVICE="$2"
shift 2
else
echo 'ERROR: --device requires a non-empty argument' >&2
show_usage >&2
exit 1
fi
;;
-*|--*)
echo "Error: Unknown flag: $1" >&2
show_usage >&2
exit 1
;;
esac
done
echo "Device name is $DEVICE"
if [ "$DEVICE" == "cortex-m55" ]; then
RUN_DEVICE_NAME="M55"
VHT_Platform="VHT_MPS3_Corstone_SSE-300"
TVM_TARGET="cortex-m55"
elif [ "$DEVICE" == "cortex-m85" ]; then
RUN_DEVICE_NAME="M85"
VHT_Platform="VHT_Corstone_SSE-310"
TVM_TARGET="cortex-m85"
else
echo 'ERROR: --device only support cortex-m55/cortex-m85' >&2
exit 1
fi
# download paddle model
echo "Model name is $MODEL_NAME"
if [ "$MODEL_NAME" == "MobileNetV1" ]; then
wget "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/MobileNetV1_x0_25_infer.tar"
tar -xf MobileNetV1_x0_25_infer.tar
rm MobileNetV1_x0_25_infer.tar
mv MobileNetV1_x0_25_infer "${PWD}/model"
INPUT_NODE_NAME="inputs"
elif [ "$MODEL_NAME" == "MobileNetV3" ]; then
wget "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/MobileNetV3_small_x0_35_ssld_infer.tar"
tar -xf MobileNetV3_small_x0_35_ssld_infer.tar
rm MobileNetV3_small_x0_35_ssld_infer.tar
mv MobileNetV3_small_x0_35_ssld_infer/inference "${PWD}/model"
rm -rf MobileNetV3_small_x0_35_ssld_infer
INPUT_NODE_NAME="x"
elif [ "$MODEL_NAME" == "PP_LCNet" ]; then
wget "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/inference/PPLCNet_x0_75_infer.tar"
tar -xf PPLCNet_x0_75_infer.tar
rm PPLCNet_x0_75_infer.tar
mv PPLCNet_x0_75_infer "${PWD}/model"
INPUT_NODE_NAME="x"
else
echo 'ERROR: --model only support MobileNetV1/MobileNetV3/PP_LCNet' >&2
exit 1
fi
# convert paddle model to onnx model
paddle2onnx --model_dir "${PWD}/model" \
--model_filename inference.pdmodel \
--params_filename inference.pdiparams \
--save_file inference.onnx
rm -rf "${PWD}/model"
if [ "$DEVICE" != "x" ]; then
python rename_onnx_model.py --model inference.onnx \
--origin_names ${INPUT_NODE_NAME} \
--new_names x \
--save_file inference.onnx
fi
# convert onnx model to tvm model
python3 -m tvm.driver.tvmc compile --target=cmsis-nn,c \
--target-cmsis-nn-mcpu=$TVM_TARGET \
--target-c-mcpu=$TVM_TARGET \
--runtime=crt \
--executor=aot \
--executor-aot-interface-api=c \
--executor-aot-unpacked-api=1 \
--pass-config tir.usmp.enable=1 \
--pass-config tir.usmp.algorithm=hill_climb \
--pass-config tir.disable_storage_rewrite=1 \
--pass-config tir.disable_vectorize=1 \
inference.onnx \
--output-format=mlf \
--model-format=onnx \
--input-shapes x:[1,3,224,224] \
--module-name=cls \
--output=cls.tar
rm inference.onnx
# decompression cls.tar
mkdir -p "${PWD}/cls"
tar -xvf cls.tar -C "${PWD}/cls"
rm cls.tar
# create input and output head file
python3 ./convert_labels.py ./labels/labels.txt
python3 ./convert_image.py ./image/ILSVRC2012_val_00020010.jpg
# build
csolution list packs -s object_classification.csolution.yml -m > packs.txt
cpackget update-index
cpackget add -f packs.txt
PROJECT_FILE_NAME="object_classification+PaddleClas$RUN_DEVICE_NAME.cprj"
echo "Project file name is $PROJECT_FILE_NAME"
cbuild -p "$PROJECT_FILE_NAME"
rm -rf "${PWD}/cls"
rm "${PWD}/include/inputs.h"
rm "${PWD}/include/outputs.h"
rm "${PWD}/include/labels.h"
# run
$VHT_Platform -C cpu0.CFGDTCMSZ=15 \
-C cpu0.CFGITCMSZ=15 \
-C mps3_board.uart0.out_file=\"-\" \
-C mps3_board.uart0.shutdown_tag=\"EXITTHESIM\" \
-C mps3_board.visualisation.disable-visualisation=1 \
-C mps3_board.telnetterminal0.start_telnet=0 \
-C mps3_board.telnetterminal1.start_telnet=0 \
-C mps3_board.telnetterminal2.start_telnet=0 \
-C mps3_board.telnetterminal5.start_telnet=0 \
"out/object_classification/PaddleClas$RUN_DEVICE_NAME/object_classification.axf" \
--stat
# clean
rm -rf out
rm -rf tmp
rm -rf packs.txt