summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
author이상규/On-Device Lab(SR)/Principal Engineer/삼성전자 <sg5.lee@samsung.com>2019-08-29 16:02:38 +0900
committer오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>2019-08-29 16:02:38 +0900
commitf2e58939c33c51c80ac5728216807bf3cd9ab091 (patch)
treed0e1feed193b3129e04c26fe45ba31b7862b0081 /tools
parent5b64611c4488bdd182353d2be41d32279ed7948f (diff)
downloadnnfw-f2e58939c33c51c80ac5728216807bf3cd9ab091.tar.gz
nnfw-f2e58939c33c51c80ac5728216807bf3cd9ab091.tar.bz2
nnfw-f2e58939c33c51c80ac5728216807bf3cd9ab091.zip
[nnpkg_tool] Introduce nncc-tc-to-nnpkg-tc (#7005)
Introduce tool for converting nncc testcase to nnpkg testcase. Please read README.md for usage. Signed-off-by: Sanggyu Lee <sg5.lee@samsung.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/nnpackage_tool/nncc-tc-to-nnpkg-tc/README.md26
-rwxr-xr-xtools/nnpackage_tool/nncc-tc-to-nnpkg-tc/nncc-tc-to-nnpkg-tc.sh84
2 files changed, 110 insertions, 0 deletions
diff --git a/tools/nnpackage_tool/nncc-tc-to-nnpkg-tc/README.md b/tools/nnpackage_tool/nncc-tc-to-nnpkg-tc/README.md
new file mode 100644
index 000000000..9e5ae2938
--- /dev/null
+++ b/tools/nnpackage_tool/nncc-tc-to-nnpkg-tc/README.md
@@ -0,0 +1,26 @@
+# nncc-tc-to-nnpkg-tc
+
+`model2nnpkg` is a tool to convert model (either `tflite` or `circle`) to `nnpackage`.
+
+It takes `modelfile` as input and generates `nnpackage`.
+
+## Usage
+
+```
+Usage: nncc-tc-to-nnpkg-tc.sh [options] nncc_tc_name
+Convert nncc testcase to nnpackage testcase.
+
+Options:
+ -h show this help
+ -i set input directory (default=.)
+ -o set nnpackage testcase output directory (default=.)
+
+Env:
+ model2nnpkg path to model2nnpkg tool (default={this_script_home}/../model2nnpkg)
+
+Examples:
+ nncc-tc-to-nnpkg-tc.sh -i build/compiler/tf2tflite UNIT_Add_000
+ => create nnpackage testcase in ./ from build/compiler/tf2tflite/UNIT_Add_000.*
+ nncc-tc-to-nnpkg-tc.sh -o out UNIT_Add_000
+ => create nnpackage testcase in out/ using ./UNIT_Add_000.*
+```
diff --git a/tools/nnpackage_tool/nncc-tc-to-nnpkg-tc/nncc-tc-to-nnpkg-tc.sh b/tools/nnpackage_tool/nncc-tc-to-nnpkg-tc/nncc-tc-to-nnpkg-tc.sh
new file mode 100755
index 000000000..01ce1476f
--- /dev/null
+++ b/tools/nnpackage_tool/nncc-tc-to-nnpkg-tc/nncc-tc-to-nnpkg-tc.sh
@@ -0,0 +1,84 @@
+#!/bin/bash
+
+set -eu
+
+progname=$(basename "${BASH_SOURCE[0]}")
+script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+model2nnpkg=${model2nnpkg:-"$script_dir"/../model2nnpkg/model2nnpkg.sh}
+
+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="
+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
+
+$model2nnpkg -o "$outdir" "$indir/$tcname"."$model_type"
+
+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;
+