|
|
@@ -0,0 +1,70 @@
|
|
|
+#!/bin/bash
|
|
|
+
|
|
|
+
|
|
|
+root=$(cd $(dirname ${0})/..; pwd)
|
|
|
+build=${root}/build
|
|
|
+src=${root}/src
|
|
|
+tools=${root}/tools
|
|
|
+third_party=${root}/third_party
|
|
|
+
|
|
|
+identifier=tflite
|
|
|
+virtualenv=${build}/virtualenv/${identifier}
|
|
|
+
|
|
|
+python=${python:-python}
|
|
|
+pip=${pip:-pip}
|
|
|
+
|
|
|
+git_sync () {
|
|
|
+ mkdir -p "${third_party}"
|
|
|
+ if [ -d "${third_party}/${1}" ]; then
|
|
|
+ git -C "${third_party}/${1}" fetch -p --quiet
|
|
|
+ git -C "${third_party}/${1}" reset --quiet --hard origin/master
|
|
|
+ else
|
|
|
+ echo "Clone ${2}..."
|
|
|
+ git -C "${third_party}" clone --recursive ${2}
|
|
|
+ fi
|
|
|
+}
|
|
|
+
|
|
|
+sync() {
|
|
|
+ git_sync flatbuffers https://github.com/google/flatbuffers.git
|
|
|
+ git_sync tensorflow https://github.com/tensorflow/tensorflow.git
|
|
|
+}
|
|
|
+
|
|
|
+build() {
|
|
|
+ echo "Build flatbuffers..."
|
|
|
+ pushd "${third_party}/flatbuffers" > /dev/null
|
|
|
+ cmake -G "Unix Makefiles"
|
|
|
+ make
|
|
|
+ popd > /dev/null
|
|
|
+ virtualenv --quiet -p ${python} ${virtualenv}
|
|
|
+}
|
|
|
+
|
|
|
+schema() {
|
|
|
+ echo "Generate '../src/tflite-schema.js'"
|
|
|
+ cp ${third_party}/tensorflow/tensorflow/lite/schema/schema.fbs ${tools}/metadata/tflite.schema.fbs
|
|
|
+ sed -i 's/namespace tflite\;/namespace tflite_schema\;/' ${tools}/metadata/tflite.schema.fbs
|
|
|
+ ${third_party}/flatbuffers/flatc --no-js-exports --js ${tools}/metadata/tflite.schema.fbs
|
|
|
+ mv ./tflite.schema_generated.js ${src}/tflite-schema.js
|
|
|
+ rm ${tools}/metadata/tflite.schema.fbs
|
|
|
+cat <<EOT >> ${src}/tflite-schema.js
|
|
|
+if (typeof module !== 'undefined' && typeof module.exports === 'object') {
|
|
|
+ module.exports = tflite_schema;
|
|
|
+}
|
|
|
+EOT
|
|
|
+}
|
|
|
+
|
|
|
+visualize() {
|
|
|
+ source ${virtualenv}/bin/activate
|
|
|
+ ${pip} install --quiet tensorflow
|
|
|
+ python ${third_party}/tensorflow/tensorflow/lite/tools/visualize.py $@
|
|
|
+ deactivate
|
|
|
+}
|
|
|
+
|
|
|
+while [ "$#" != 0 ]; do
|
|
|
+ command="$1" && shift
|
|
|
+ case "${command}" in
|
|
|
+ "sync") sync;;
|
|
|
+ "build") build;;
|
|
|
+ "schema") schema;;
|
|
|
+ "visualize") visualize ${1} ${2} && shift && shift;;
|
|
|
+ esac
|
|
|
+done
|