forked from fastmachinelearning/hls4ml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert-onnx-models.sh
executable file
·79 lines (70 loc) · 2.12 KB
/
convert-onnx-models.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
#!/bin/bash
models_var=HLS4ML_ONNX_MODELS
models_file=
exec=echo
dir=
function print_usage {
echo "Usage: `basename $0` [OPTION]"
echo ""
echo "Reads the model names from the ${models_var} environment variable"
echo "or provided file name and optionally starts the conversion."
echo ""
echo "Options are:"
echo " -f FINENAME"
echo " File name to read models from. If not specified, reads from ${models_var}"
echo " environment variable."
echo " -x"
echo " Execute the commands instead of just printing them."
echo " -d DIR"
echo " Output directory passed to onnx-to-hls script."
echo " -h"
echo " Prints this help message."
}
while getopts ":f:xd:h" opt; do
case "$opt" in
f) models_file=$OPTARG
;;
x) exec=eval
;;
d) dir="-d $OPTARG"
;;
h)
print_usage
exit
;;
:)
echo "Option -$OPTARG requires an argument."
exit 1
;;
esac
done
if [ -z ${models_file} ]; then
if [ -z ${!models_var+x} ] ; then
echo "No file provided and ${models_var} variable not set. Nothing to do."
exit 1
else
IFS=";" read -ra model_line <<< "${!models_var}"
fi
else
readarray model_line < "${models_file}"
fi
for line in "${model_line[@]}"
do
params=("" "" "" "" "" "")
if [[ ${line} = *[![:space:]]* ]] && ! [[ "${line}" = \#* ]] ; then
IFS=" " read -ra model_def <<< "${line}"
for (( i=1; i<"${#model_def[@]}"; i++ ));
do
if [[ "${model_def[$i]}" == x:* ]] ; then params[0]="-x ${model_def[$i]:2} "; fi
if [[ "${model_def[$i]}" == c:* ]] ; then params[1]="-c ${model_def[$i]:2} "; fi
if [[ "${model_def[$i]}" == io:s ]] ; then params[2]="-s "; fi
if [[ "${model_def[$i]}" == r:* ]] ; then params[3]="-r ${model_def[$i]:2} "; fi
if [[ "${model_def[$i]}" == i:* ]] ; then params[4]="-t ${model_def[$i]:2} "; fi
done
params[5]=${model_def[0]}
cmd="./onnx-to-hls.sh ${dir} ${params[0]}${params[1]}${params[2]}${params[3]}${params[4]}${params[5]}"
${exec} "${cmd}"
fi
done
#cd "${rundir}"
exit ${failed}