-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_tf2_to_trt_TEMPLATE.sh
105 lines (79 loc) · 2.33 KB
/
convert_tf2_to_trt_TEMPLATE.sh
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
#!/bin/bash
###
# Functions
###
get_model_name()
{
MYFILENAME=`basename "$0"`
MODELNAME=`echo $MYFILENAME | sed 's/convert_tf2_to_trt_//' | sed 's/.sh//'`
echo Selected model: $MODELNAME
}
get_width_and_height()
{
elements=(${MODELNAME//_/ })
#$(echo $MODELNAME | tr "_" "\n")
#echo $elements
resolution=${elements[2]}
res_split=(${resolution//x/ })
height=${res_split[0]}
width=${res_split[1]}
echo batch processing height=$height and width=$width
}
convert_to_trt()
{
python3 $SCRIPTPREFIX/hardwaremodules/nvidia/convert_tf2_to_trt.py \
--tensorflow_model=exported-models/$MODELNAME/saved_model \
--batch_size=8 \
--image_size="[$height, $width]" \
--precision=$PRECISION \
--dtype=uint8 \
--data_dir=./images/validation \
--output_dir=./exported-models-trt/$MODELNAME\_TRT$PRECISION
}
###
# Main body of script starts here
###
echo #==============================================#
echo # CDLEML Process TF2 Object Detection API
echo #==============================================#
echo INFO: EXECUTE SCRIPT IN TARGET BASE FOLDER, e.g. samples/starwars_reduced
# Constant Definition
#MODELNAME=tf2oda_efficientdet_512x384_pedestrian_D0_LR02
PYTHONENV=tf24
BASEPATH=`pwd`
SCRIPTPREFIX=../../scripts-and-guides/scripts
MODELSOURCE=jobs/*.config
HARDWARENAME=IntelNUC
LABELMAP=pedestrian_label_map.pbtxt
#Extract model name from this filename
get_model_name
#Setup environment
#setup_env
#echo "Start training of $MODELNAME on EDA02" | mail -s "Start training of $MODELNAME" $USEREMAIL
#echo "Setup task spooler socket."
#. ~/init_eda_ts.sh
echo Apply to model $MODELNAME
get_width_and_height
#Get image resolution from model name
alias python=python3
echo #==============================================#
echo # Convert a TF2 model to trt
echo #==============================================#
#PRECISION=INT8
PRECISIONLIST="INT8 FP16 FP32"
for PRECISION in $PRECISIONLIST
do
#echo "$f"
#MODELNAME=`basename ${f%%.*}`
echo $PRECISION
convert_to_trt
done
#python3 $SCRIPTPREFIX/hardwaremodules/nvidia/convert_tf2_to_trt.py \
#--tensorflow_model=exported-models/$MODELNAME/saved_model \
#--batch_size=32 \
#--image_size="[$height, $width]" \
#--precision=$PRECISION \
#--dtype=uint8 \
#--data_dir=./images/validation \
#--output_dir=./exported-models-trt/$MODELNAME\_TRT$PRECISION