Skip to content

Commit

Permalink
[1.9.1][one-cmds] Fix invalid input arguments (#4203)
Browse files Browse the repository at this point in the history
* [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 <[email protected]>

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

Co-authored-by: Sung-Jae Lee <[email protected]>

Co-authored-by: Sung-Jae Lee <[email protected]>
  • Loading branch information
seanshpark and lemmaa authored Sep 11, 2020
1 parent 571d072 commit 4ccaa83
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
64 changes: 64 additions & 0 deletions compiler/one-cmds/one-import-tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand All @@ -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%.*}"

Expand Down
24 changes: 24 additions & 0 deletions compiler/one-cmds/one-import-tflite
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
;;
*)
Expand All @@ -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"

Expand Down
24 changes: 24 additions & 0 deletions compiler/one-cmds/one-pack
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
;;
*)
Expand All @@ -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"

Expand Down

0 comments on commit 4ccaa83

Please sign in to comment.