-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenvino_inf_eval_yolo_onnx_TEMPLATE.sh
171 lines (140 loc) · 5.27 KB
/
openvino_inf_eval_yolo_onnx_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
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
169
170
#!/bin/bash
###
# Functions
###
setup_env()
{
# Environment preparation
#echo Activate environment $PYTHONENV
#call conda activate %PYTHONENV%
#Environment is put directly in the nuc home folder
. ./init_env_openvino.sh
echo "Setup task spooler socket."
. ./init_ts.sh
alias python=python3.8
}
get_model_name()
{
MYFILENAME=`basename "$0"`
MODELNAME=`echo $MYFILENAME | sed 's/openvino_inf_eval_yolo_onnx_//' | sed 's/.sh//'`
echo Selected model based on folder name: $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
}
infer()
{
echo Apply to model $MODELNAME with type $HARDWARETYPE
echo '===================================='
echo ' Infer with OpenVino'
echo '===================================='
echo "Start latency inference"
python $SCRIPTPREFIX/hardwaremodules/intel/run_pb_bench_sizes.py \
-openvino_path $OPENVINOINSTALLDIR \
-hw $HARDWARETYPE \
-batch_size 1 \
-api $APIMODE \
-niter 1000 \
-nireq 1 \
-xml ./exported-models-openvino/$MODELNAME/$MODELNAME.xml \
-output_dir="results/$MODELNAME/$HARDWARENAME/openvino"
#python $OPENVINOINSTALLDIR/deployment_tools/tools/benchmark_tool/benchmark_app.py \
#--path_to_model "exported-models-openvino/$MODELNAME/saved_model_simple.xml" \
#-niter 10 \
#-nireq 1 \
#-d $HARDWARETYPE
echo '===================================='
echo ' Convert Latencies'
echo '===================================='
echo "Add measured latencies to result table"
python3 $SCRIPTPREFIX/hardwaremodules/intel/openvino_latency_parser.py \
--avg_rep results/$MODELNAME/$HARDWARENAME/openvino/benchmark_average_counters_report_$HARDWARETYPE\_$APIMODE.csv \
--inf_rep results/$MODELNAME/$HARDWARENAME/openvino/benchmark_report_$HARDWARETYPE\_$APIMODE.csv \
--output_path results/latency_$HARDWARENAME.csv \
--hardware_name $HARDWARENAME \
--index_save_file="./tmp/index.txt"
#::--save_new #False: Always append
echo '===================================='
echo ' Infer with OpenVino'
echo '===================================='
echo "Start accuracy/performance inference"
python $SCRIPTPREFIX/hardwaremodules/intel/test_write_results_yolov_3and5.py \
-i $DATASET/images/val \
-m ./exported-models-openvino/$MODELNAME/$MODELNAME.xml \
-d $HARDWARETYPE \
--detections_out results/$MODELNAME/$HARDWARENAME\_$HARDWARETYPE/detections.csv \
--input_source onnx \
--prob_threshold 0.5 \
--iou_threshold 0.4 \
--no-show \
--labels $DATASET/annotations/labels.txt
echo '===================================='
echo ' Convert to Pycoco Tools JSON Format'
echo '===================================='
echo "Convert TF CSV to Pycoco Tools csv"
python $SCRIPTPREFIX/conversion/convert_tfcsv_to_pycocodetections.py \
--annotation_file=results/$MODELNAME/$HARDWARENAME\_$HARDWARETYPE/detections.csv \
--output_file=results/$MODELNAME/$HARDWARENAME\_$HARDWARETYPE/coco_detections.json
echo '===================================='
echo ' Evaluate with Coco Metrics'
echo '===================================='
python $SCRIPTPREFIX/inference_evaluation/eval_pycocotools.py \
--groundtruth_file=$DATASET/annotations/coco_val_annotations.json \
--detection_file=results/$MODELNAME/$HARDWARENAME\_$HARDWARETYPE/coco_detections.json \
--output_file=results/performance_$HARDWARENAME.csv \
--model_name=$MODELNAME \
--hardware_name=$HARDWARENAME\_$HARDWARETYPE \
--index_save_file=./tmp/index.txt
echo '===================================='
echo ' Merge results to one result table'
echo '===================================='
echo merge latency and evaluation metrics
python3 $SCRIPTPREFIX/inference_evaluation/eval_merge_results.py \
--latency_file=results/latency_$HARDWARENAME.csv \
--coco_eval_file=results/performance_$HARDWARENAME.csv \
--output_file=results/combined_results_$HARDWARENAME.csv
}
###
# Main body of script starts here
###
echo #==============================================#
echo # CDLEML Process TF2 Object Detection API for OpenVino
echo #==============================================#
# Constant Definition
#MODELNAME=tf2oda_efficientdet_512x384_pedestrian_D0_LR02
SCRIPTPREFIX=../../eml-tools
HARDWARENAME=IntelNUC
DATASET=../../../datasets/dataset-oxford-pets-val-debug
#DATASET=../../datasets/pedestrian_detection_graz_val_only_debug
#Openvino installation directory for the inferrer (not necessary the same as the model optimizer)
#OPENVINOINSTALLDIR=/opt/intel/openvino_2021
OPENVINOINSTALLDIR=/opt/intel/openvino_2021.4.582
APIMODE=sync
HARDWARETYPELIST="CPU GPU MYRIAD"
#HARDWARETYPELIST="CPU"
echo Extract model name from this filename
get_model_name
echo Extract height and width from model
get_width_and_height
echo Setup environment
setup_env
#echo "Start training of $MODELNAME on EDA02" | mail -s "Start training of $MODELNAME" $USEREMAIL
#Setup openvino environment
echo "Setup Openvino environment and variables"
source $OPENVINOINSTALLDIR/bin/setupvars.sh
for HARDWARETYPE in $HARDWARETYPELIST
do
#echo "$f"
#MODELNAME=`basename ${f%%.*}`
echo $HARDWARETYPE
infer
done