usage()
{
echo "usage : $0"
- echo " --info=Information file"
- echo " --tensorflow_path=TensorFlow path (Use externals/tensorflow by default)"
- echo " --tensorflow_version=TensorFlow version (Must be entered)"
+ echo " --info=<infroamtion file>"
+ echo " [ --tensorflow_path=<path> --tensorflow_version=<version> ] (If omitted, the module installed in system will be used by default.)"
}
SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-TF_DIR="${SCRIPT_PATH}/../../externals/tensorflow"
-
for i in "$@"
do
case $i in
usage
exit 1
fi
-if [ -z "$TF_DIR" ]; then
- echo "tensorflow_path is unset or set to the empty string"
- usage
- exit 1
-fi
+
if [ -z "$TF_VERSION" ]; then
- echo "tensorflow_version is unset or set to the empty string"
- usage
- exit 1
+ if [ -z "$TF_DIR" ]; then
+ TF_VERSION=$(python -c 'import tensorflow as tf; print(tf.__version__)')
+ echo "TensorFlow version detected : $TF_VERSION"
+ else
+ echo "tensorflow_version is unset or set to the empty string"
+ usage
+ exit 1
+ fi
fi
if [ ! -x "$(command -v bazel)" ]; then
CUR_DIR=$(pwd)
{
- echo "Enter $TF_DIR"
- pushd $TF_DIR > /dev/null
+ if [ -e "$TF_DIR" ]; then
+ echo "Enter $TF_DIR"
+ pushd $TF_DIR > /dev/null
+ TFLITE_CONVERT="bazel run tensorflow/lite/python:tflite_convert -- "
+ else
+ TFLITE_CONVERT="python -m tensorflow.lite.python.tflite_convert "
+ fi
NAME_LIST=()
INPUT_SHAPE_LIST=()
for (( i=0; i < ${#NAME_LIST[@]}; ++i )); do
if [ "${TF_VERSION%%.*}" = "2" ]; then
- bazel run tensorflow/lite/python:tflite_convert -- \
+ $TFLITE_CONVERT \
--output_file="${NAME_LIST[$i]}" \
--graph_def_file="$GRAPHDEF_PATH" \
--input_arrays="$INPUT" \
--output_arrays="$OUTPUT" \
--allow_custom_ops=true
else
- bazel run tensorflow/lite/python:tflite_convert -- \
+ $TFLITE_CONVERT \
--output_file="${NAME_LIST[$i]}" \
--graph_def_file="$GRAPHDEF_PATH" \
--input_arrays="$INPUT" \
--allow_custom_ops
fi
done
- popd
+
+ if [ -e "$TF_DIR" ]; then
+ popd
+ fi
for (( i=0; i < ${#NAME_LIST[@]}; ++i )); do
echo "OUTPUT FILE : ${NAME_LIST[$i]}"