[tf2nnpkg] Introduce --use-tf2circle option (#8793)
author박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 7 Nov 2019 06:48:23 +0000 (15:48 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 7 Nov 2019 06:48:23 +0000 (15:48 +0900)
This commit introduces --use-tf2circle option to tf2nnpkg. When a user
passes --user-tf2circle, tf2nnpkg internally invokes tf2circle instead
of tf2tflite and tflite2circle script.

Please note that this commit does not change the default behavior.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
infra/packaging/res/tf2nnpkg

index cbb0181..e1db6e8 100644 (file)
@@ -14,6 +14,8 @@ usage()
   exit 0
 }
 
+USE_TF2CIRCLE=0
+
 # Parse command-line arguments
 #
 while [ "$#" -ne 0 ]; do
@@ -35,6 +37,10 @@ while [ "$#" -ne 0 ]; do
       export OUTPUT_DIR="$2"
       shift 2
       ;;
+    '--use-tf2circle')
+      USE_TF2CIRCLE=1
+      shift 1
+      ;;
     *)
       echo "${CUR}"
       shift
@@ -55,18 +61,24 @@ fi
 FILE_BASE=$(basename ${GRAPHDEF_FILE})
 MODEL_NAME="${FILE_BASE%.*}"
 
-export flatc=$(which flatc)
-export tflite_schema="${ROOT}/res/tflite_schema.fbs"
-export circle_schema="${ROOT}/res/circle_schema.fbs"
+if [[ ${USE_TF2CIRCLE} -eq 0 ]]; then
+  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
+  if ! command_exists $flatc; then
+    echo "Please make sure flatc is in path"
+    exit 2
+  fi
 fi
 
 TMPDIR=$(mktemp -d)
 trap "{ rm -rf $TMPDIR; }" EXIT
 
-"${ROOT}/bin/tf2tflite" "${INFO_FILE}" "${GRAPHDEF_FILE}" "${TMPDIR}/${MODEL_NAME}.tflite"
-"${ROOT}/bin/tflite2circle.sh" -o "${TMPDIR}" "${TMPDIR}/${MODEL_NAME}.tflite"
+if [[ ${USE_TF2CIRCLE} -eq 0 ]]; then
+  "${ROOT}/bin/tf2tflite" "${INFO_FILE}" "${GRAPHDEF_FILE}" "${TMPDIR}/${MODEL_NAME}.tflite"
+  "${ROOT}/bin/tflite2circle.sh" -o "${TMPDIR}" "${TMPDIR}/${MODEL_NAME}.tflite"
+else
+  "${ROOT}/bin/tf2circle" "${INFO_FILE}" "${GRAPHDEF_FILE}" "${TMPDIR}/${MODEL_NAME}.circle"
+fi
 "${ROOT}/bin/model2nnpkg.sh" -o "${OUTPUT_DIR}" "${TMPDIR}/${MODEL_NAME}.circle"