Browse Source

Merge visualize and tflite script

Lutz Roeder 7 years ago
parent
commit
a558d5a2b3
6 changed files with 73 additions and 93 deletions
  1. 1 1
      test/app.js
  2. 0 20
      tools/converter/tflite-visualize
  3. 0 69
      tools/metadata/tflite-update
  4. 1 1
      tools/metadata/update
  5. 1 2
      tools/onnx
  6. 70 0
      tools/tflite

+ 1 - 1
test/app.js

@@ -229,7 +229,7 @@ function request(location, cookie, callback) {
         response.on("data", (chunk) => {
             position += chunk.length;
             if (length >= 0) {
-                var label = location.length > 70 ? location.substring(0, 67) + '...' : location; 
+                var label = location.length > 70 ? location.substring(0, 66) + '...' : location; 
                 process.stdout.write('  (' + ('  ' + Math.floor(100 * (position / length))).slice(-3) + '%) ' + label + '\r');
             }
             else {

+ 0 - 20
tools/converter/tflite-visualize

@@ -1,20 +0,0 @@
-#!/bin/bash
-
-ScriptPath="`cd $(dirname ${BASH_SOURCE[0]});pwd`"
-
-root=$(cd $(dirname ${0})/../..; pwd)
-build=${root}/build
-
-python=${python:-python}
-
-identifier=tflite
-
-virtualenv=${build}/virtualenv/${identifier}
-virtualenv -p ${python} ${virtualenv}
-source ${virtualenv}/bin/activate
-
-pip install --quiet tensorflow
-
-python ${ScriptPath}/../../third_party/tensorflow/tensorflow/lite/tools/visualize.py $@
-
-deactivate

+ 0 - 69
tools/metadata/tflite-update

@@ -1,69 +0,0 @@
-#!/bin/bash
-
-set -e
-
-if [ "$#" == 0 ]; then
-    __sync=true
-    __build=true
-    __update=true
-else
-    while test $# -gt 0
-    do
-        case "$1" in
-            sync) __sync=true;;
-            build) __build=true;;
-            update) __update=true;;
-        esac
-        shift
-    done
-fi
-
-root=$(cd $(dirname ${0})/../..; pwd)
-src=${root}/src
-tools=${root}/tools
-third_party=${root}/third_party
-
-mkdir -p ${third_party}
-
-identifier=tensorflow
-
-if [ ${__sync} ]; then
-    repository=https://github.com/google/flatbuffers.git
-    if [ -d "${third_party}/flatbuffers" ]; then
-        git -C "${third_party}/flatbuffers" fetch -p
-        git -C "${third_party}/flatbuffers" reset --hard origin/master
-    else
-        echo "Clone ${repository}..."
-        git -C "${third_party}" clone --recursive ${repository}
-    fi
-
-    repository=https://github.com/tensorflow/${identifier}.git
-    if [ -d "${third_party}/${identifier}" ]; then
-        git -C "${third_party}/${identifier}" fetch -p
-        git -C "${third_party}/${identifier}" reset --hard origin/master
-    else
-        echo "Clone ${repository}..."
-        git -C "${third_party}" clone --recursive ${repository}
-    fi
-fi
-
-if [ ${__build} ]; then
-    pushd "${third_party}/flatbuffers" > /dev/null
-    cmake -G "Unix Makefiles"
-    make
-    popd > /dev/null
-fi
-
-if [ ${__update} ]; then
-    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
-fi

+ 1 - 1
tools/metadata/update

@@ -29,7 +29,7 @@ echo "Update ONNX"
 ${tools}/onnx sync build schema metadata
 
 echo "Update TensorFlow Lite"
-${tools}/tflite-update
+${tools}/tflite sync build schema
 
 echo "Update scikit-learn"
 ${tools}/metadata/sklearn-update

+ 1 - 2
tools/onnx

@@ -72,8 +72,7 @@ convert() {
 }
 
 while [ "$#" != 0 ]; do
-    command="$1"
-    shift
+    command="$1" && shift
     case "${command}" in
         "sync") sync;;
         "build") build;;

+ 70 - 0
tools/tflite

@@ -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