summaryrefslogtreecommitdiff
path: root/infra/packaging/res/tf2nnpkg.20200220
diff options
context:
space:
mode:
Diffstat (limited to 'infra/packaging/res/tf2nnpkg.20200220')
-rw-r--r--infra/packaging/res/tf2nnpkg.2020022089
1 files changed, 89 insertions, 0 deletions
diff --git a/infra/packaging/res/tf2nnpkg.20200220 b/infra/packaging/res/tf2nnpkg.20200220
new file mode 100644
index 000000000..0875bad2f
--- /dev/null
+++ b/infra/packaging/res/tf2nnpkg.20200220
@@ -0,0 +1,89 @@
+#!/bin/bash
+
+set -e
+
+ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+
+command_exists() {
+ if [ "$#" -le 0 ]; then
+ return 1
+ fi
+ command -v "$@" > /dev/null 2>&1
+}
+
+usage()
+{
+ echo "Convert TensorFlow model to nnpackage."
+ echo "Usage: tf2nnpkg --info <path/to/info> --graphdef <path/to/pb> [OPTION] -o <path/to/nnpkg/directory>"
+ echo "option:"
+ echo " --customop <path/to/customop.conf>"
+ exit 0
+}
+
+# Parse command-line arguments
+#
+while [ "$#" -ne 0 ]; do
+ CUR="$1"
+
+ case $CUR in
+ '--help')
+ usage
+ ;;
+ '--info')
+ export INFO_FILE="$2"
+ shift 2
+ ;;
+ '--graphdef')
+ export GRAPHDEF_FILE="$2"
+ shift 2
+ ;;
+ '--customop')
+ export CUSTOMOP_CONF_FILE="$2"
+ shift 2
+ ;;
+ '-o')
+ export OUTPUT_DIR="$2"
+ shift 2
+ ;;
+ '--use-tf2circle')
+ echo "WARNING! --use-tf2circle is deprecated"
+ shift 1
+ ;;
+ *)
+ echo "${CUR}"
+ shift
+ ;;
+ esac
+done
+
+if [ -z ${GRAPHDEF_FILE} ] || [ ! -e ${GRAPHDEF_FILE} ]; then
+ echo "pb is not found. Please check --graphdef is correct."
+ exit 2
+fi
+
+if [ -z ${INFO_FILE} ] || [ ! -e ${INFO_FILE} ]; then
+ echo "info is not found. Please check --info is correct."
+ exit 2
+fi
+
+# optional param
+if [ ${CUSTOMOP_CONF_FILE} ]; then
+ if [ ! -e ${CUSTOMOP_CONF_FILE} ]; then
+ echo "customop.conf is not found. Please check --customop is correct."
+ exit 2
+ fi
+fi
+
+FILE_BASE=$(basename ${GRAPHDEF_FILE})
+MODEL_NAME="${FILE_BASE%.*}"
+TMPDIR=$(mktemp -d)
+trap "{ rm -rf $TMPDIR; }" EXIT
+
+if [ ${CUSTOMOP_CONF_FILE} ]; then
+ "${ROOT}/bin/tf2circle" "${INFO_FILE}" "${GRAPHDEF_FILE}" "${TMPDIR}/${MODEL_NAME}.circle" \
+ "--customop" "${CUSTOMOP_CONF_FILE}"
+else
+ "${ROOT}/bin/tf2circle" "${INFO_FILE}" "${GRAPHDEF_FILE}" "${TMPDIR}/${MODEL_NAME}.circle"
+fi
+
+"${ROOT}/bin/model2nnpkg.sh" -o "${OUTPUT_DIR}" "${TMPDIR}/${MODEL_NAME}.circle"