From f2e58939c33c51c80ac5728216807bf3cd9ab091 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=EC=83=81=EA=B7=9C/On-Device=20Lab=28SR=29/Princip?= =?utf8?q?al=20Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Thu, 29 Aug 2019 16:02:38 +0900 Subject: [PATCH] [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 --- tools/nnpackage_tool/nncc-tc-to-nnpkg-tc/README.md | 26 +++++++ .../nncc-tc-to-nnpkg-tc/nncc-tc-to-nnpkg-tc.sh | 84 ++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 tools/nnpackage_tool/nncc-tc-to-nnpkg-tc/README.md create mode 100755 tools/nnpackage_tool/nncc-tc-to-nnpkg-tc/nncc-tc-to-nnpkg-tc.sh 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 0000000..9e5ae29 --- /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 0000000..01ce147 --- /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; + -- 2.7.4