5 progname=$(basename "${BASH_SOURCE[0]}")
6 script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
7 nnfw_root="$( cd "${script_dir%*/*/*/*}" && pwd )"
9 flatc=${flatc:-"$nnfw_root/build/externals/FLATBUFFERS/build/flatc"}
10 tflite_schema=${tflite_schema:-"$nnfw_root/externals/TENSORFLOW-1.12/tensorflow/contrib/lite/schema/schema.fbs"}
11 circle_schema=${circle_schema:-"$nnfw_root/nnpackage/schema/circle_schema.fbs"}
13 if ! [ -x "$flatc" ]; then
14 echo "Please make sure `flatc` is in path."
18 if ! { [ -e "$tflite_schema" ] && [ -e "$circle_schema" ]; }; then
19 echo "Please make sure that the `*.fbs` paths are set properly."
24 echo "Usage: $progname [options] tflite"
25 echo "Convert tflite to circle"
29 echo " non-zero failure"
32 echo " -h show this help"
33 echo " -o set output directory (default=$outdir)"
35 echo "Environment variables:"
36 echo " flatc path to flatc"
37 echo " (default=./build/externals/FLATBUFFERS/build/flatc)"
38 echo " tflite_schema path to tflite schema (i.e. schema.fbs)"
39 echo " (default=./externals/TENSORFLOW-1.12/tensorflow/contrib/lite/schema/schema.fbs)"
40 echo " circle_schema path to circle schema"
41 echo " (default=./nnpackage/schema/circle_schema.fbs)"
44 echo " $progname Add_000.tflite => convert Add_000.tflite into Add_000.circle"
45 echo " $progname -o my/circles Add_000 => convert Add_000.tflite into my/circles/Add_000.circle"
50 echo "For help, type $progname -h"
54 while getopts "ho:" OPTION; do
65 echo "error: wrong argument (no argument or too many arguments)."
66 echo "For help, type $progname -h"
70 tflite_base=$(basename "$1")
71 name=${tflite_base%.*}
76 ${flatc} -o ${outdir} --defaults-json --strict-json -t ${tflite_schema} -- $1
77 ${script_dir}/tflitejson2circlejson.py "${outdir}/${name}.json" > "${outdir}/${name}.circle"
78 ${flatc} -o ${outdir} -b ${circle_schema} "${outdir}/${name}.circle"
79 rm -f ${outdir}/${name}.json