[tf2nnpk] check existence and provide help (#8499)
author이상규/On-Device Lab(SR)/Principal Engineer/삼성전자 <sg5.lee@samsung.com>
Mon, 28 Oct 2019 06:23:18 +0000 (15:23 +0900)
committer오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 28 Oct 2019 06:23:18 +0000 (15:23 +0900)
It will show help with `--help`.
It will check existence of flatc, graphdef and info file.

Signed-off-by: Sanggyu Lee <sg5.lee@samsung.com>
infra/packaging/res/tf2nnpkg

index e502dda..cbb0181 100644 (file)
@@ -1,14 +1,28 @@
 #!/bin/bash
 
+set -e
+
 ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
 
+command_exists() {
+  command -v "$@" > /dev/null 2>&1
+}
+
+usage()
+{
+  echo "Usage: tf2nnpkg --info <path/to/info> --graphdef <path/to/pb> -o <path/to/nnpkg/directory>"
+  exit 0
+}
+
 # Parse command-line arguments
 #
-# --info <path/to/info> --graphdef <path/to/pb> -o <path/to/nnpkg/directory>
 while [ "$#" -ne 0 ]; do
   CUR="$1"
 
   case $CUR in
+    '--help')
+      usage
+      ;;
     '--info')
       export INFO_FILE="$2"
       shift 2
@@ -28,12 +42,15 @@ while [ "$#" -ne 0 ]; do
   esac
 done
 
-set -e
-
-# TODO CHECK ARGUMENTS
-# TODO CHECK "flatc"
+if [ -z ${GRAPHDEF_FILE} ] || [ ! -e ${GRAPHDEF_FILE} ]; then
+  echo "pb is not found. Please check --graphdef is correct."
+  exit 2
+fi
 
-echo "ROOT is '${ROOT}'"
+if [ -z ${INFO_FILE} ] || [ ! -e ${INFO_FILE} ]; then
+  echo "info is not found. Please check --info is correct."
+  exit 2
+fi
 
 FILE_BASE=$(basename ${GRAPHDEF_FILE})
 MODEL_NAME="${FILE_BASE%.*}"
@@ -42,6 +59,11 @@ export flatc=$(which flatc)
 export tflite_schema="${ROOT}/res/tflite_schema.fbs"
 export circle_schema="${ROOT}/res/circle_schema.fbs"
 
+if ! command_exists $flatc; then
+  echo "Please make sure flatc is in path"
+  exit 2
+fi
+
 TMPDIR=$(mktemp -d)
 trap "{ rm -rf $TMPDIR; }" EXIT