[1.9.1][one-cmds] Fix invalid input arguments (#4203)
authorSaeHie Park <saehie.park@gmail.com>
Fri, 11 Sep 2020 03:19:52 +0000 (12:19 +0900)
committerGitHub <noreply@github.com>
Fri, 11 Sep 2020 03:19:52 +0000 (12:19 +0900)
* [1.9.1][one-cmds] Fix invalid input arguments

This will fix error handling of invalid input arguments for import-tf, import-tflite and pack

ONE-DCO-1.0-Signed-off-by: SaeHie Park <saehie.park@gmail.com>

* Update compiler/one-cmds/one-import-tf

Co-authored-by: Sung-Jae Lee <sjlee@mail.com>
Co-authored-by: Sung-Jae Lee <sjlee@mail.com>
compiler/one-cmds/one-import-tf
compiler/one-cmds/one-import-tflite
compiler/one-cmds/one-pack

index 58c6868..2156e19 100644 (file)
@@ -38,6 +38,41 @@ version()
   exit 255
 }
 
+input_not_set()
+{
+  echo "Error: input_path not set"
+  echo ""
+  usage
+}
+
+output_not_set()
+{
+  echo "Error: output_path not set"
+  echo ""
+  usage
+}
+
+input_arrays_not_set()
+{
+  echo "Error: input_arrays not set"
+  echo ""
+  usage
+}
+
+input_shapes_not_set()
+{
+  echo "Error: input_shapes not set"
+  echo ""
+  usage
+}
+
+output_arrays_not_set()
+{
+  echo "Error: output_arrays not set"
+  echo ""
+  usage
+}
+
 TF_INTERFACE="--v1"
 
 # Parse command-line arguments
@@ -54,22 +89,37 @@ while [ "$#" -ne 0 ]; do
       ;;
     '--input_path')
       export INPUT_PATH="$2"
+      if [ $# -lt 2 ]; then
+        input_not_set
+      fi
       shift 2
       ;;
     '--output_path')
       export OUTPUT_PATH="$2"
+      if [ $# -lt 2 ]; then
+        output_not_set
+      fi
       shift 2
       ;;
     '--input_arrays')
       export INPUT_ARRAYS="$2"
+      if [ $# -lt 2 ]; then
+        input_arrays_not_set
+      fi
       shift 2
       ;;
     '--input_shapes')
       export INPUT_SHAPES="$2"
+      if [ $# -lt 2 ]; then
+        input_shapes_not_set
+      fi
       shift 2
       ;;
     '--output_arrays')
       export OUTPUT_ARRAYS="$2"
+      if [ $# -lt 2 ]; then
+        output_arrays_not_set
+      fi
       shift 2
       ;;
     '--v2')
@@ -94,6 +144,20 @@ if [ -z ${INPUT_PATH} ] || [ ! -e ${INPUT_PATH} ]; then
   exit 2
 fi
 
+if [ -z ${INPUT_ARRAYS} ]; then
+  input_arrays_not_set
+fi
+
+# INPUT_SHAPES is optional
+
+if [ -z ${OUTPUT_PATH} ]; then
+  output_not_set
+fi
+
+if [ -z ${OUTPUT_ARRAYS} ]; then
+  output_arrays_not_set
+fi
+
 FILE_BASE=$(basename ${OUTPUT_PATH})
 MODEL_NAME="${FILE_BASE%.*}"
 
index 053489c..0d5cef1 100644 (file)
@@ -34,6 +34,20 @@ version()
   exit 255
 }
 
+input_not_set()
+{
+  echo "Error: input_path not set"
+  echo ""
+  usage
+}
+
+output_not_set()
+{
+  echo "Error: output_path not set"
+  echo ""
+  usage
+}
+
 # Parse command-line arguments
 #
 while [ "$#" -ne 0 ]; do
@@ -48,10 +62,16 @@ while [ "$#" -ne 0 ]; do
       ;;
     '--input_path')
       export INPUT_PATH="$2"
+      if [ $# -lt 2 ]; then
+        input_not_set
+      fi
       shift 2
       ;;
     '--output_path')
       export OUTPUT_PATH="$2"
+      if [ $# -lt 2 ]; then
+        output_not_set
+      fi
       shift 2
       ;;
     *)
@@ -67,6 +87,10 @@ if [ -z ${INPUT_PATH} ] || [ ! -e ${INPUT_PATH} ]; then
   usage
 fi
 
+if [ -z ${OUTPUT_PATH} ]; then
+  output_not_set
+fi
+
 # remove previous log
 rm -rf "${OUTPUT_PATH}.log"
 
index 023b0a8..fe9f1bc 100644 (file)
@@ -34,6 +34,20 @@ version()
   exit 255
 }
 
+input_not_set()
+{
+  echo "Error: input path not set"
+  echo ""
+  usage
+}
+
+output_not_set()
+{
+  echo "Error: output path not set"
+  echo ""
+  usage
+}
+
 # Parse command-line arguments
 #
 while [ "$#" -ne 0 ]; do
@@ -51,10 +65,16 @@ while [ "$#" -ne 0 ]; do
       ;;
     '-i')
       export INPUT_PATH="$2"
+      if [ $# -lt 2 ]; then
+        input_not_set
+      fi
       shift 2
       ;;
     '-o')
       export OUTPUT_PATH="$2"
+      if [ $# -lt 2 ]; then
+        output_not_set
+      fi
       shift 2
       ;;
     *)
@@ -70,6 +90,10 @@ if [ -z ${INPUT_PATH} ] || [ ! -e ${INPUT_PATH} ]; then
   usage
 fi
 
+if [ -z ${OUTPUT_PATH} ]; then
+  output_not_set
+fi
+
 INPUT_FILE=$(basename "${INPUT_PATH}")
 LOG_FILE="${INPUT_FILE%.*}.pack.log"