blob: cf3e544061db176ecf62d134f389690358ad4223 (
plain)
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
|
#!/bin/bash
set -eu
progname=$(basename "${BASH_SOURCE[0]}")
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
model2nnpkg=${model2nnpkg:-"$script_dir"/../model2nnpkg/model2nnpkg.sh}
# Need to install nncc package & set path to tf2nnpkg
tf2nnpkg=$(which tf2nnpkg)
indir="."
outdir="."
usage() {
echo "Usage: $progname [options] nncc_tc_name"
echo "Convert nncc testcase to nnpackage testcase."
echo ""
echo "Options:"
echo " -h show this help"
echo " -i set input directory (default=$indir)"
echo " -o set nnpackage testcase output directory (default=$outdir)"
echo ""
echo "Env:"
echo " model2nnpkg path to model2nnpkg tool (default={this_script_home}/../model2nnpkg)"
echo ""
echo "Examples:"
echo " $progname -i build/compiler/tf2tflite UNIT_Add_000"
echo " => create nnpackage testcase in $outdir/ from build/compiler/tf2tflite/UNIT_Add_000.*"
echo " $progname -o out UNIT_Add_000"
echo " => create nnpackage testcase in out/ using $indir/UNIT_Add_000.*"
exit 1
}
if [ $# -eq 0 ]; then
echo "For help, type $progname -h"
exit 1
fi
while getopts "hi:o:" OPTION; do
case "${OPTION}" in
h) usage;;
i) indir=$OPTARG;;
o) outdir=$OPTARG;;
?) exit 1;;
esac
done
shift $((OPTIND-1))
if [ $# -ne 1 ]; then
echo "error: wrong argument (no argument or too many arguments)."
echo "For help, type $progname -h"
exit 1
fi
tcname=$1
supported_model_types="
pb
circle
tflite
"
model_type=""
for ext in $supported_model_types; do
[ -e "$indir/$tcname"."$ext" ] && model_type=$ext
done;
if [[ "$model_type" == "" ]]; then
echo "error: No modelfile is found in $indir/$tcname*"
exit 1
fi
if [[ "$model_type" == "pb" ]]; then
$tf2nnpkg --info "$indir/$tcname".info --graphdef "$indir/$tcname"."$model_type" -o "$outdir"
else
$model2nnpkg -o "$outdir" "$indir/$tcname"."$model_type"
fi
extensions="
expected.h5
input.h5
"
destdir="$outdir/$tcname/metadata/tc"
mkdir -p "$destdir"
for ext in $extensions; do
cp "$indir/$tcname.$ext" "$destdir/$ext"
done;
|