Ver Fonte

Update scripts

Lutz Roeder há 6 anos atrás
pai
commit
04a885da79
29 ficheiros alterados com 500 adições e 572 exclusões
  1. 1 1
      Makefile
  2. 29 39
      tools/armnn
  3. 15 26
      tools/bigdl
  4. 14 16
      tools/caffe
  5. 1 1
      tools/caffe2-script.py
  6. 8 22
      tools/chainer
  7. 14 15
      tools/cntk
  8. 30 24
      tools/coreml
  9. 6 15
      tools/darknet
  10. 12 21
      tools/dl4j
  11. 27 28
      tools/keras
  12. 1 1
      tools/keras-script.py
  13. 12 23
      tools/mlnet
  14. 2 2
      tools/mlnet-script.py
  15. 29 34
      tools/mnn
  16. 9 13
      tools/mxnet
  17. 1 1
      tools/mxnet-script.py
  18. 6 14
      tools/ncnn
  19. 41 38
      tools/onnx
  20. 2 1
      tools/onnx-script.py
  21. 13 24
      tools/paddle
  22. 41 36
      tools/pytorch
  23. 1 1
      tools/pytorch-script.py
  24. 38 34
      tools/sklearn
  25. 2 1
      tools/sklearn-script.py
  26. 85 68
      tools/tf
  27. 4 5
      tools/tf-script.py
  28. 48 47
      tools/tflite
  29. 8 21
      tools/torch

+ 1 - 1
Makefile

@@ -30,8 +30,8 @@ update:
 	@./tools/darknet sync
 	@./tools/dl4j sync
 	@./tools/keras sync install metadata
-	@./tools/mnn sync install schema
 	@./tools/mlnet sync metadata
+	@./tools/mnn sync schema
 	@./tools/mxnet sync metadata
 	@./tools/ncnn sync
 	@./tools/onnx sync install schema metadata

+ 29 - 39
tools/armnn

@@ -1,14 +1,7 @@
 #!/bin/bash
 
 set -e
-
-root=$(cd $(dirname ${0})/..; pwd)
-build=${root}/build
-src=${root}/src
-third_party=${root}/third_party
-tools=${root}/tools
-
-identifier=armnn
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
@@ -16,66 +9,63 @@ bold() {
 
 clean() {
     bold "armnn clean"
-    rm -rf ${third_party}/armnn
+    rm -rf ./third_party/armnn
 }
 
 sync() {
     bold "armnn sync"
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/armnn" ]; then
-        git -C "${third_party}/armnn" pull --quiet --prune
+    mkdir -p "./third_party"
+    if [ -d "./third_party/armnn" ]; then
+        git -C "./third_party/armnn" pull --quiet --prune
     else
-        git -C "${third_party}" clone --quiet --branch master --recursive https://github.com/ARM-software/armnn.git
+        git -C "./third_party" clone --quiet --branch master --recursive https://github.com/ARM-software/armnn.git
     fi
-    git -C "${third_party}/armnn" submodule sync --quiet
-    git -C "${third_party}/armnn" submodule update --quiet --init --recursive
 }
 
 schema() {
     bold "armnn schema"
     case "${OSTYPE}" in
         linux*)
-            FLATC_VERSION=$(curl -s https://api.github.com/repos/google/flatbuffers/releases/latest | grep tag_name | cut -f 2 -d : | cut -f 2 -d '"')
-            FLATC_DIR=$(dirname $(mktemp -u))/flatbuffers/${FLATC_VERSION}
-            if [ ! -f "${FLATC_DIR}/flatc" ]; then
-                mkdir -p "${FLATC_DIR}"
-                pushd "${FLATC_DIR}" > /dev/null
-                curl -sL https://github.com/google/flatbuffers/archive/${FLATC_VERSION}.tar.gz | tar zx --strip-components 1
+            flatc_version=$(curl -s https://api.github.com/repos/google/flatbuffers/releases/latest | grep tag_name | cut -f 2 -d : | cut -f 2 -d '"')
+            flatc_dir=$(dirname $(mktemp -u))/flatbuffers/${flatc_version}
+            if [ ! -f "${flatc_dir}/flatc" ]; then
+                mkdir -p "${flatc_dir}"
+                pushd "${flatc_dir}" > /dev/null
+                curl -sL https://github.com/google/flatbuffers/archive/${flatc_version}.tar.gz | tar zx --strip-components 1
                 cmake -G "Unix Makefiles" . &> /dev/null
                 make > /dev/null
                 popd > /dev/null
             fi
-            FLATC=${FLATC_DIR}/flatc
+            flatc=${flatc_dir}/flatc
             ;;
         darwin*)
             brew list flatbuffers > /dev/null 2>&1 || brew install flatbuffers > /dev/null
-            FLATC=flatc
+            flatc=flatc
             ;;
         msys*)
-            FLATC_VERSION=$(curl -s https://api.github.com/repos/google/flatbuffers/releases/latest | grep tag_name | cut -f 2 -d : | cut -f 2 -d '"')
-            FLATC_DIR=$(dirname $(mktemp -u))/flatbuffers/${FLATC_VERSION}
-            if [ ! -f "${FLATC_DIR}/flatc.exe" ]; then
-                mkdir -p "${FLATC_DIR}"
-                pushd "${FLATC_DIR}" > /dev/null
-                curl -sL -O https://github.com/google/flatbuffers/releases/download/${FLATC_VERSION}/flatc_windows_exe.zip
-                unzip flatc_windows_exe.zip
+            flatc_version=$(curl -s https://api.github.com/repos/google/flatbuffers/releases/latest | grep tag_name | cut -f 2 -d : | cut -f 2 -d '"')
+            flatc_dir=$(dirname $(mktemp -u))/flatbuffers/${flatc_version}
+            if [ ! -f "${flatc_dir}/flatc.exe" ]; then
+                mkdir -p "${flatc_dir}"
+                pushd "${flatc_dir}" > /dev/null
+                curl -sL -O https://github.com/google/flatbuffers/releases/download/${flatc_version}/flatc_windows_exe.zip
+                unzip flatc_windows_exe.zip > /dev/null
                 popd > /dev/null
             fi
-            FLATC=${FLATC_DIR}/flatc.exe
+            flatc=${flatc_dir}/flatc.exe
             ;;
     esac
-    ${FLATC} --no-js-exports --js ${third_party}/armnn/src/armnnSerializer/ArmnnSchema.fbs
-    mv ./ArmnnSchema_generated.js ${src}/armnn-schema.js
-    cat <<EOT >> ${src}/armnn-schema.js
+    [[ $(file ./src/armnn-schema.js) =~ CRLF ]] && crlf=1
+    ${flatc} --no-js-exports -o ./tools/. --js ./third_party/armnn/src/armnnSerializer/ArmnnSchema.fbs
+    mv ./tools/ArmnnSchema_generated.js ./src/armnn-schema.js
+    cat <<EOT >> ./src/armnn-schema.js
 if (typeof module !== 'undefined' && typeof module.exports === 'object') {
   module.exports = armnnSerializer;
 }
 EOT
-    case "${OSTYPE}" in
-        msys*)
-            unix2dos --quiet --newfile ${src}/armnn-schema.js ${src}/armnn-schema.js
-            ;;
-    esac
+    if [[ -n ${crlf} ]]; then
+        unix2dos --quiet --newfile ./src/armnn-schema.js ./src/armnn-schema.js
+    fi
 }
 
 while [ "$#" != 0 ]; do

+ 15 - 26
tools/bigdl

@@ -1,47 +1,36 @@
 #!/bin/bash
 
 set -e
-
-root=$(cd $(dirname ${0})/..; pwd)
-build=${root}/build
-node_modules=${root}/node_modules
-src=${root}/src
-third_party=${root}/third_party
-tools=${root}/tools
-
-identifier=bigdl
-virtualenv=${third_party}/virtualenv/${identifier}
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
 }
 
-git_sync() {
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/${1}" ]; then
-        git -C "${third_party}/${1}" pull --quiet --prune
-    else
-        git -C "${third_party}" clone --quiet --recursive ${2} ${1}
-    fi
-    git -C "${third_party}/${1}" submodule sync --quiet
-    git -C "${third_party}/${1}" submodule update --quiet --init --recursive
-}
-
 clean() {
     bold "bigdl clean"
-    rm -rf ${virtualenv}
-    rm -rf ${third_party}/${identifier}
-    rm -rf ${third_party}/onnxmltools
+    rm -rf ./third_party/bigdl
 }
 
 sync() {
     bold "bigdl sync"
-    git_sync bigdl https://github.com/intel-analytics/BigDL.git
+    mkdir -p "./third_party"
+    if [ -d "./third_party/bigdl" ]; then
+        git -C "./third_party/bigdl" pull --quiet --prune
+    else
+        git -C "./third_party" clone --quiet --recursive https://github.com/intel-analytics/BigDL.git bigdl
+    fi
+    git -C "./third_party/bigdl" submodule sync --quiet
+    git -C "./third_party/bigdl" submodule update --quiet --init --recursive
 }
 
 schema() {
     bold "bigdl schema"
-    ${node_modules}/protobufjs/bin/pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --no-convert --no-verify --no-create --keep-case -r bigdl -o ${src}/bigdl-proto.js ${third_party}/${identifier}/spark/dl/src/main/resources/serialization/bigdl.proto
+    [[ $(file ./src/bigdl-proto.js) =~ CRLF ]] && crlf=1
+    npx pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --no-convert --no-verify --no-create --keep-case -r bigdl -o ./src/bigdl-proto.js ./third_party/bigdl/spark/dl/src/main/resources/serialization/bigdl.proto
+    if [[ -n ${crlf} ]]; then
+        unix2dos --quiet --newfile ./src/bigdl-proto.js ./src/bigdl-proto.js
+    fi
 }
 
 while [ "$#" != 0 ]; do

+ 14 - 16
tools/caffe

@@ -2,11 +2,7 @@
 
 set -e
 
-root=$(cd $(dirname ${0})/..; pwd)
-node_modules=${root}/node_modules
-src=${root}/src
-third_party=${root}/third_party
-tools=${root}/tools
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
@@ -14,27 +10,29 @@ bold() {
 
 clean() {
     bold "caffe clean"
-    rm -rf ${third_party}/caffe
+    rm -rf ./third_party/caffe
 }
 
 sync() {
     bold "caffe sync"
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/caffe" ]; then
-        git -C "${third_party}/caffe" pull --quiet --prune
+    mkdir -p "./third_party"
+    if [ -d "./third_party/caffe" ]; then
+        git -C "./third_party/caffe" pull --quiet --prune
     else
-        git -C "${third_party}" clone --quiet --recursive https://github.com/BVLC/caffe.git
+        git -C "./third_party" clone --quiet --recursive https://github.com/BVLC/caffe.git
     fi
-    git -C "${third_party}/caffe" submodule sync --quiet
-    git -C "${third_party}/caffe" submodule update --quiet --init --recursive
 }
 
 schema() {
     bold "caffe schema"
-    sed 's/required float min = 1;/optional float min = 1;/g;s/required float max = 2;/optional float max = 2;/g' <${third_party}/caffe/src/caffe/proto/caffe.proto >${tools}/caffe.proto
-    ${node_modules}/protobufjs/bin/pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --no-convert --no-verify --no-create --keep-case --decode-text -r caffe -o ${src}/caffe-proto.js ${tools}/caffe.proto
-    rm ${tools}/caffe.proto
-    node ${tools}/update_pbjs.js array ${src}/caffe-proto.js data float 1
+    [[ $(file ./src/caffe-proto.js) =~ CRLF ]] && crlf=1
+    sed 's/required float min = 1;/optional float min = 1;/g;s/required float max = 2;/optional float max = 2;/g' < ./third_party/caffe/src/caffe/proto/caffe.proto >./tools/caffe.proto
+    npx pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --no-convert --no-verify --no-create --keep-case --decode-text -r caffe -o ./src/caffe-proto.js ./tools/caffe.proto
+    rm ./tools/caffe.proto
+    node ./tools/update_pbjs.js array ./src/caffe-proto.js data float 1
+    if [[ -n ${crlf} ]]; then
+        unix2dos --quiet --newfile ./src/caffe-proto.js ./src/caffe-proto.js
+    fi
 }
 
 while [ "$#" != 0 ]; do

+ 1 - 1
tools/caffe2-script.py

@@ -153,7 +153,7 @@ def metadata():
 
     import caffe2.python.core
 
-    json_file = '../src/caffe2-metadata.json'
+    json_file = os.path.join(os.path.dirname(__file__), '../src/caffe2-metadata.json')
     json_data = open(json_file).read()
     json_root = json.loads(json_data)
 

+ 8 - 22
tools/chainer

@@ -1,39 +1,25 @@
 #!/bin/bash
 
 set -e
-
-root=$(cd $(dirname ${0})/..; pwd)
-build=${root}/build
-test=${root}/test
-third_party=${root}/third_party
-tools=${root}/tools
-
-identifier=chainer
-virtualenv=${third_party}/virtualenv/${identifier}
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
 }
 
-git_sync() {
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/${1}" ]; then
-        git -C "${third_party}/${1}" pull --quiet --prune
-    else
-        git -C "${third_party}" clone --quiet --recursive ${2}
-    fi
-    git -C "${third_party}/${1}" submodule sync --quiet
-    git -C "${third_party}/${1}" submodule update --quiet --init --recursive
-}
-
 clean() {
     bold "chainer clean"
-    rm -rf ${third_party}/${identifier}
+    rm -rf ./chainer
 }
 
 sync() {
     bold "chainer sync"
-    git_sync chainer https://github.com/chainer/chainer.git
+    mkdir -p "./third_party"
+    if [ -d "./third_party/chainer" ]; then
+        git -C "./third_party/chainer" pull --quiet --prune
+    else
+        git -C "./third_party" clone --quiet --recursive https://github.com/chainer/chainer.git
+    fi
 }
 
 while [ "$#" != 0 ]; do

+ 14 - 15
tools/cntk

@@ -1,12 +1,7 @@
 #!/bin/bash
 
 set -e
-
-root=$(cd $(dirname ${0})/..; pwd)
-node_modules=${root}/node_modules
-src=${root}/src
-third_party=${root}/third_party
-tools=${root}/tools
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
@@ -14,25 +9,29 @@ bold() {
 
 clean() {
     bold "cntk clean"
-    rm -rf "${third_party}/cntk"
+    rm -rf "./third_party/cntk"
 }
 
 sync() {
     bold "cntk sync"
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/cntk" ]; then
-        git -C "${third_party}/cntk" pull --quiet --prune
+    mkdir -p "./third_party"
+    if [ -d "./third_party/cntk" ]; then
+        git -C "./third_party/cntk" pull --quiet --prune
     else
-        git -C "${third_party}" clone --quiet --recursive https://github.com/Microsoft/CNTK.git cntk
+        git -C "./third_party" clone --quiet --recursive https://github.com/Microsoft/CNTK.git cntk
     fi
-    git -C "${third_party}/cntk" submodule sync --quiet
-    git -C "${third_party}/cntk" submodule update --quiet --init --recursive
+    git -C "./third_party/cntk" submodule sync --quiet
+    git -C "./third_party/cntk" submodule update --quiet --init --recursive
 }
 
 schema() {
     bold "cntk schema"
-    ${node_modules}/protobufjs/bin/pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --no-convert --no-verify --no-create --keep-case -r cntk -o ${src}/cntk-proto.js ${third_party}/cntk/Source/CNTKv2LibraryDll/proto/CNTK.proto
-    node ${tools}/update_pbjs.js array ${src}/cntk-proto.js value float 1
+    [[ $(file ./src/cntk-proto.js) =~ CRLF ]] && crlf=1
+    npx pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --no-convert --no-verify --no-create --keep-case -r cntk -o ./src/cntk-proto.js ./third_party/cntk/Source/CNTKv2LibraryDll/proto/CNTK.proto
+    node ./tools/update_pbjs.js array ./src/cntk-proto.js value float 1
+    if [[ -n ${crlf} ]]; then
+        unix2dos --quiet --newfile ./src/cntk-proto.js ./src/cntk-proto.js
+    fi
 }
 
 while [ "$#" != 0 ]; do

+ 30 - 24
tools/coreml

@@ -1,14 +1,19 @@
 #!/bin/bash
 
 set -e
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
-root=$(cd $(dirname ${0})/..; pwd)
-node_modules=${root}/node_modules
-src=${root}/src
-third_party=${root}/third_party
-tools=${root}/tools
+[[ "$(python3 --version 2> /dev/null)" =~ "Python 3" ]] && python=python3 || python=python
 
-virtualenv=${third_party}/virtualenv/coremltools
+venv() {
+    venv_dir=./third_party/venv/coremltools
+    [ -d "${venv_dir}" ] || ${python} -m venv ${venv_dir}
+    case "${venv_dir}" in
+        msys*) source ${venv_dir}/Scripts/activate;;
+        *) source ${venv_dir}/bin/activate;;
+    esac
+    ${python} -m pip install --quiet --upgrade pip
+}
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
@@ -16,38 +21,39 @@ bold() {
 
 clean() {
     bold "coreml clean"
-    rm -rf ${virtualenv}
-    rm -rf ${third_party}/coremltools
+    rm -rf ./third_party/venv/coremltools
+    rm -rf ./third_party/coremltools
 }
 
 sync() {
     bold "coreml sync"
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/coremltools" ]; then
-        git -C "${third_party}/coremltools" pull --quiet --prune
+    mkdir -p "./third_party"
+    if [ -d "./third_party/coremltools" ]; then
+        git -C "./third_party/coremltools" pull --quiet --prune
     else
-        git -C "${third_party}" clone --quiet --recursive https://github.com/apple/coremltools.git
+        git -C "./third_party" clone --quiet --recursive https://github.com/apple/coremltools.git
     fi
-    git -C "${third_party}/coremltools" submodule sync --quiet
-    git -C "${third_party}/coremltools" submodule update --quiet --init --recursive
+    popd > /dev/null
 }
 
 schema() {
     bold "coreml schema"
-    ${node_modules}/protobufjs/bin/pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --no-convert --no-verify --no-create --keep-case -r coreml -o ${src}/coreml-proto.js ${third_party}/coremltools/mlmodel/format/Model.proto
-    node ${tools}/update_pbjs.js array ${src}/coreml-proto.js floatValue float 2
+    [[ $(file ./src/coreml-proto.js) =~ CRLF ]] && crlf=1
+    npx pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --no-convert --no-verify --no-create --keep-case -r coreml -o ./src/coreml-proto.js ./third_party/coremltools/mlmodel/format/Model.proto
+    node ./tools/update_pbjs.js array ./src/coreml-proto.js floatValue float 2
+    if [[ -n ${crlf} ]]; then
+        unix2dos --quiet --newfile ./src/coreml-proto.js ./src/coreml-proto.js
+    fi
 }
 
 convert() {
     bold "coreml convert"
-    [ -n "$(python3 -m pip list --format columns --disable-pip-version-check | grep -w virtualenv)" ] || python3 -m pip install --force-reinstall --user --quiet virtualenv
-    [ -d "${virtualenv}" ] || python3 -m virtualenv --quiet -p python3 ${virtualenv}
-    source ${virtualenv}/bin/activate
-    python3 -m pip install --quiet --upgrade six numpy protobuf
-    python3 -m pip install --quiet ${third_party}/coremltools
-    python3 -m pip install --quiet onnx
-    python3 -m pip install --quiet sklearn
-    python3 ${tools}/coreml-script.py convert ${1}
+    venv
+    ${python} -m pip install --quiet --upgrade six numpy protobuf
+    ${python} -m pip install --quiet ./third_party/coremltools
+    ${python} -m pip install --quiet onnx
+    ${python} -m pip install --quiet sklearn
+    ${python} ./tools/coreml-script.py convert ${1}
     deactivate
 }
 

+ 6 - 15
tools/darknet

@@ -1,33 +1,24 @@
 #!/bin/bash
 
 set -e
-
-root=$(cd $(dirname ${0})/..; pwd)
-node_modules=${root}/node_modules
-src=${root}/src
-third_party=${root}/third_party
-tools=${root}/tools
-
-identifier=darknet
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
 }
 
 git_sync() {
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/${1}" ]; then
-        git -C "${third_party}/${1}" pull --quiet --prune
+    mkdir -p "./third_party"
+    if [ -d "./third_party/${1}" ]; then
+        git -C "./third_party/${1}" pull --quiet --prune
     else
-        git -C "${third_party}" clone --quiet --recursive ${2} ${1}
+        git -C "./third_party" clone --quiet --recursive ${2} ${1}
     fi
-    git -C "${third_party}/${1}" submodule sync --quiet
-    git -C "${third_party}/${1}" submodule update --quiet --init --recursive
 }
 
 clean() {
     bold "darknet clean"
-    rm -rf ${third_party}/${identifier}
+    rm -rf ./third_party/darknet
 }
 
 sync() {

+ 12 - 21
tools/dl4j

@@ -1,38 +1,29 @@
 #!/bin/bash
 
 set -e
-
-root=$(cd $(dirname ${0})/..; pwd)
-node_modules=${root}/node_modules
-src=${root}/src
-third_party=${root}/third_party
-tools=${root}/tools
-
-identifier=dl4j
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
+function exit_trap() {
+    popd > /dev/null
+}
+trap exit_trap EXIT
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
 }
 
-git_sync() {
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/${1}" ]; then
-        git -C "${third_party}/${1}" pull --quiet --prune
-    else
-        git -C "${third_party}" clone --quiet --recursive ${2} ${1}
-    fi
-    git -C "${third_party}/${1}" submodule sync --quiet
-    git -C "${third_party}/${1}" submodule update --quiet --init --recursive
-}
-
 clean() {
     bold "deeplearning4j clean"
-    rm -rf ${third_party}/${identifier}
+    rm -rf "./third_party/dl4j"
 }
 
 sync() {
     bold "deeplearning4j sync"
-    git_sync dl4j https://github.com/eclipse/deeplearning4j.git
+    mkdir -p "./third_party"
+    if [ -d "./third_party/dl4j" ]; then
+        git -C "./third_party/dl4j" pull --quiet --prune
+    else
+        git -C "./third_party" clone --quiet --recursive https://github.com/eclipse/deeplearning4j.git dl4j
+    fi
 }
 
 while [ "$#" != 0 ]; do

+ 27 - 28
tools/keras

@@ -1,62 +1,61 @@
 #!/bin/bash
 
 set -e
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
-root=$(cd $(dirname ${0})/..; pwd)
-build=${root}/build
-test=${root}/test
-third_party=${root}/third_party
-tools=${root}/tools
-
-virtualenv=${third_party}/virtualenv/keras
+[[ "$(python3 --version 2> /dev/null)" =~ "Python 3" ]] && python=python3 || python=python
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
 }
 
+venv() {
+    venv_dir=./third_party/venv/keras
+    [ -d "${venv_dir}" ] || ${python} -m venv ${venv_dir}
+    case "${OSTYPE}" in
+        msys*) source ${venv_dir}/Scripts/activate ;;
+        *) source ${venv_dir}/bin/activate ;;
+    esac
+    ${python} -m pip install --quiet --upgrade pip
+}
+
 clean() {
     bold "keras clean"
-    rm -rf ${virtualenv}
-    rm -rf ${third_party}/keras
+    rm -rf "./third_party/venv/keras"
+    rm -rf "./third_party/keras"
 }
 
 sync() {
     bold "keras sync"
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/keras" ]; then
-        git -C "${third_party}/keras" pull --quiet --prune
+    mkdir -p "./third_party"
+    if [ -d "./third_party/keras" ]; then
+        git -C "./third_party/keras" pull --quiet --prune
     else
-        git -C "${third_party}" clone --quiet --recursive https://github.com/keras-team/keras.git
+        git -C "./third_party" clone --quiet --recursive https://github.com/keras-team/keras.git
     fi
-    git -C "${third_party}/keras" submodule sync --quiet
-    git -C "${third_party}/keras" submodule update --quiet --init --recursive
+    git -C "./third_party/keras" submodule sync --quiet
+    git -C "./third_party/keras" submodule update --quiet --init --recursive
 }
 
 install() {
     bold "keras install"
-    [ -n "$(python3 -m pip list --format columns --disable-pip-version-check | grep -w virtualenv)" ] || python3 -m pip install --force-reinstall --user --quiet virtualenv
-    [ -d "${virtualenv}" ] || virtualenv --quiet -p python3 ${virtualenv}
-    source ${virtualenv}/bin/activate
-    python3 -m pip install --quiet --upgrade tensorflow
-    python3 -m pip install --quiet ${third_party}/keras
+    venv
+    ${python} -m pip install --quiet --upgrade tensorflow
+    ${python} -m pip install --quiet ./third_party/keras
     deactivate
 }
 
 metadata() {
     bold "keras metadata"
-    source ${virtualenv}/bin/activate
-    pushd ${tools} > /dev/null
-    python3 keras-script.py metadata
-    popd > /dev/null
+    venv
+    ${python} ./tools/keras-script.py metadata
     deactivate
 }
 
 zoo() {
     bold "keras zoo"
-    source ${virtualenv}/bin/activate
-    pushd ${tools} > /dev/null
-    python3 keras-script.py zoo
-    popd > /dev/null
+    venv
+    ${python} ./tools/keras-script.py zoo
     deactivate
 }
 

+ 1 - 1
tools/keras-script.py

@@ -285,7 +285,7 @@ def update_output(schema, description):
         entry['description'] = description
 
 def metadata():
-    json_file = '../src/keras-metadata.json'
+    json_file = os.path.join(os.path.dirname(__file__), '../src/keras-metadata.json')
     json_data = open(json_file).read()
     json_root = json.loads(json_data)
 

+ 12 - 23
tools/mlnet

@@ -1,45 +1,34 @@
 #!/bin/bash
 
 set -e
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
-root=$(cd $(dirname ${0})/..; pwd)
-node_modules=${root}/node_modules
-src=${root}/src
-third_party=${root}/third_party
-tools=${root}/tools
-
-identifier=mlnet
+[[ "$(python3 --version 2> /dev/null)" =~ "Python 3" ]] && python=python3 || python=python
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
 }
 
-git_sync() {
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/${1}" ]; then
-        git -C "${third_party}/${1}" pull --quiet --prune
-    else
-        git -C "${third_party}" clone --quiet --recursive ${2} ${1}
-    fi
-    git -C "${third_party}/${1}" submodule sync --quiet
-    git -C "${third_party}/${1}" submodule update --quiet --init --recursive
-}
-
 clean() {
     bold "mlnet clean"
-    rm -rf ${third_party}/mlnet
+    rm -rf ./third_party/mlnet
 }
 
 sync() {
     bold "mlnet sync"
-    git_sync mlnet https://github.com/dotnet/machinelearning.git
+    mkdir -p "./third_party"
+    if [ -d "./third_party/mlnet" ]; then
+        git -C "./third_party/mlnet" pull --quiet --prune
+    else
+        git -C "./third_party" clone --quiet --recursive https://github.com/dotnet/machinelearning.git mlnet
+    fi
+    git -C "./third_party/mlnet" submodule sync --quiet
+    git -C "./third_party/mlnet" submodule update --quiet --init --recursive
 }
 
 metadata() {
     bold "mlnet metadata"
-    pushd ${tools} > /dev/null
-    python3 mlnet-script.py metadata
-    popd > /dev/null
+    ${python} ./tools/mlnet-script.py metadata
 }
 
 while [ "$#" != 0 ]; do

+ 2 - 2
tools/mlnet-script.py

@@ -9,10 +9,10 @@ import re
 import sys
 
 def metadata():
-    json_file = '../src/mlnet-metadata.json'
+    json_file = os.path.join(os.path.dirname(__file__), '../src/mlnet-metadata.json')
     json_data = open(json_file).read()
     json_root = json.loads(json_data)
-    manifest_file = '../third_party/mlnet/test/BaselineOutput/Common/EntryPoints/core_manifest.json'
+    manifest_file = os.path.join(os.path.dirname(__file__), '../third_party/mlnet/test/BaselineOutput/Common/EntryPoints/core_manifest.json')
     manifest_data = open(manifest_file).read()
     manifest_root = json.loads(manifest_data)
     schema_map = {}

+ 29 - 34
tools/mnn

@@ -1,11 +1,7 @@
 #!/bin/bash
 
 set -e
-
-root=$(cd $(dirname ${0})/..; pwd)
-src=${root}/src
-third_party=${root}/third_party
-tools=${root}/tools
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
@@ -13,64 +9,63 @@ bold() {
 
 clean() {
     bold "mnn clean"
-    rm -rf ${third_party}/mnn
+    rm -rf ./third_party/mnn
 }
 
 sync() {
     bold "mnn sync"
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/mnn" ]; then
-        git -C "${third_party}/mnn" pull --quiet --prune
+    mkdir -p "./third_party"
+    if [ -d "./third_party/mnn" ]; then
+        git -C "./third_party/mnn" pull --quiet --prune
     else
-        git -C "${third_party}" clone --quiet --recursive https://github.com/alibaba/MNN.git mnn
+        git -C "./third_party" clone --quiet --recursive https://github.com/alibaba/MNN.git mnn
     fi
-    git -C "${third_party}/mnn" submodule sync --quiet
-    git -C "${third_party}/mnn" submodule update --quiet --init --recursive
 }
 
 schema() {
     bold "mnn schema"
     case "${OSTYPE}" in
         linux*)
-            FLATC_VERSION=$(curl -s https://api.github.com/repos/google/flatbuffers/releases/latest | grep tag_name | cut -f 2 -d : | cut -f 2 -d '"')
-            FLATC_DIR=$(dirname $(mktemp -u))/flatbuffers/${FLATC_VERSION}
-            if [ ! -f "${FLATC_DIR}/flatc" ]; then
-                mkdir -p "${FLATC_DIR}"
-                pushd "${FLATC_DIR}" > /dev/null
-                curl -sL https://github.com/google/flatbuffers/archive/${FLATC_VERSION}.tar.gz | tar zx --strip-components 1
+            flatc_version=$(curl -s https://api.github.com/repos/google/flatbuffers/releases/latest | grep tag_name | cut -f 2 -d : | cut -f 2 -d '"')
+            flatc_dir=$(dirname $(mktemp -u))/flatbuffers/${flatc_version}
+            if [ ! -f "${flatc_dir}/flatc" ]; then
+                mkdir -p "${flatc_dir}"
+                pushd "${flatc_dir}" > /dev/null
+                curl -sL https://github.com/google/flatbuffers/archive/${flatc_version}.tar.gz | tar zx --strip-components 1
                 cmake -G "Unix Makefiles" . &> /dev/null
                 make > /dev/null
                 popd > /dev/null
             fi
-            FLATC=${FLATC_DIR}/flatc
+            flatc=${flatc_dir}/flatc
             ;;
         darwin*)
             brew list flatbuffers > /dev/null 2>&1 || brew install flatbuffers > /dev/null
-            FLATC=flatc
+            flatc=flatc
             ;;
         msys*)
-            FLATC_VERSION=$(curl -s https://api.github.com/repos/google/flatbuffers/releases/latest | grep tag_name | cut -f 2 -d : | cut -f 2 -d '"')
-            FLATC_DIR=$(dirname $(mktemp -u))/flatbuffers/${FLATC_VERSION}
-            if [ ! -f "${FLATC_DIR}/flatc.exe" ]; then
-                mkdir -p "${FLATC_DIR}"
-                pushd "${FLATC_DIR}" > /dev/null
-                curl -sL -O https://github.com/google/flatbuffers/releases/download/${FLATC_VERSION}/flatc_windows_exe.zip
-                unzip flatc_windows_exe.zip
+            flatc_version=$(curl -s https://api.github.com/repos/google/flatbuffers/releases/latest | grep tag_name | cut -f 2 -d : | cut -f 2 -d '"')
+            flatc_dir=$(dirname $(mktemp -u))/flatbuffers/${flatc_version}
+            if [ ! -f "${flatc_dir}/flatc.exe" ]; then
+                mkdir -p "${flatc_dir}"
+                pushd "${flatc_dir}" > /dev/null
+                curl -sL -O https://github.com/google/flatbuffers/releases/download/${flatc_version}/flatc_windows_exe.zip
+                unzip flatc_windows_exe.zip > /dev/null
                 popd > /dev/null
             fi
-            FLATC=${FLATC_DIR}/flatc.exe
+            flatc=${flatc_dir}/flatc.exe
             ;;
     esac
-    ${FLATC} --no-js-exports --gen-all -o ${tools}/. --js ${third_party}/mnn/schema/default/MNN.fbs
-    mv ${tools}/MNN_generated.js ${src}/mnn-schema.js
-    cat <<EOT >> ${src}/mnn-schema.js
+    [[ $(file ./src/mnn-schema.js) =~ CRLF ]] && crlf=1
+    ${flatc} --no-js-exports --gen-all -o ./tools/. --js ./third_party/mnn/schema/default/MNN.fbs
+    mv ./tools/MNN_generated.js ./src/mnn-schema.js
+    cat <<EOT >> ./src/mnn-schema.js
 if (typeof module !== 'undefined' && typeof module.exports === 'object') {
   module.exports = MNN;
 }
 EOT
-    case "${OSTYPE}" in
-        msys*) unix2dos --quiet --newfile ${src}/mnn-schema.js ${src}/mnn-schema.js;;
-    esac
+    if [[ -n ${crlf} ]]; then
+        unix2dos --quiet --newfile ./src/mnn-schema.js ./src/mnn-schema.js
+    fi
 }
 
 while [ "$#" != 0 ]; do

+ 9 - 13
tools/mxnet

@@ -1,11 +1,7 @@
 #!/bin/bash
 
 set -e
-
-root=$(cd $(dirname ${0})/..; pwd)
-src=${root}/src
-third_party=${root}/third_party
-tools=${root}/tools
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
@@ -13,24 +9,24 @@ bold() {
 
 clean() {
     bold "mxnet clean"
-    rm -rf "${third_party}/mxnet"
+    rm -rf "./third_party/mxnet"
 }
 
 sync() {
     bold "mxnet sync"
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/mxnet" ]; then
-        git -C "${third_party}/mxnet" pull --quiet --prune
+    mkdir -p "./third_party"
+    if [ -d "./third_party/mxnet" ]; then
+        git -C "./third_party/mxnet" pull --quiet --prune
     else
-        git -C "${third_party}" clone --quiet --recursive https://github.com/apache/incubator-mxnet.git mxnet
+        git -C "./third_party" clone --quiet --recursive https://github.com/apache/incubator-mxnet.git mxnet
     fi
-    git -C "${third_party}/mxnet" submodule sync --quiet
-    git -C "${third_party}/mxnet" submodule update --quiet --init --recursive
+    git -C "./third_party/mxnet" submodule sync --quiet
+    git -C "./third_party/mxnet" submodule update --quiet --init --recursive
 }
 
 metadata() {
     bold "mxnet metadata"
-    # python3 mxnet-script.py
+    # python3 ./tools/mxnet-script.py
 }
 
 while [ "$#" != 0 ]; do

+ 1 - 1
tools/mxnet-script.py

@@ -8,7 +8,7 @@ import pydoc
 import re
 import sys
 
-json_file = '../src/mxnet-metadata.json'
+json_file = os.path.join(os.path.dirname(__file__), '../src/mxnet-metadata.json')
 json_data = open(json_file).read()
 json_root = json.loads(json_data)
 

+ 6 - 14
tools/ncnn

@@ -1,13 +1,7 @@
 #!/bin/bash
 
 set -e
-
-root=$(cd $(dirname ${0})/..; pwd)
-src=${root}/src
-third_party=${root}/third_party
-tools=${root}/tools
-
-identifier=ncnn
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
@@ -15,19 +9,17 @@ bold() {
 
 clean() {
     bold "ncnn clean"
-    rm -rf "${third_party}/${identifier}"
+    rm -rf "./third_party/ncnn"
 }
 
 sync() {
     bold "ncnn sync"
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/ncnn" ]; then
-        git -C "${third_party}/ncnn" pull --quiet --prune
+    mkdir -p "./third_party"
+    if [ -d "./third_party/ncnn" ]; then
+        git -C "./third_party/ncnn" pull --quiet --prune
     else
-        git -C "${third_party}" clone --quiet --recursive https://github.com/Tencent/ncnn.git ncnn
+        git -C "./third_party" clone --quiet --recursive https://github.com/Tencent/ncnn.git ncnn
     fi
-    git -C "${third_party}/ncnn" submodule sync --quiet
-    git -C "${third_party}/ncnn" submodule update --quiet --init --recursive
 }
 
 while [ "$#" != 0 ]; do

+ 41 - 38
tools/onnx

@@ -1,37 +1,42 @@
 #!/bin/bash
 
 set -e
-
-root=$(cd $(dirname ${0})/..; pwd)
-build=${root}/build
-node_modules=${root}/node_modules
-src=${root}/src
-third_party=${root}/third_party
-tools=${root}/tools
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
 identifier=onnx
-virtualenv=${third_party}/virtualenv/${identifier}
+
+[[ "$(python3 --version 2> /dev/null)" =~ "Python 3" ]] && python=python3 || python=python
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
 }
 
+venv() {
+    venv_dir=./third_party/venv/onnx
+    [ -d "${venv_dir}" ] || ${python} -m venv ${venv_dir}
+    case "${OSTYPE}" in
+        msys*) source ${venv_dir}/Scripts/activate;;
+        *) source ${venv_dir}/bin/activate;;
+    esac
+    ${python} -m pip install --quiet --upgrade pip
+}
+
 git_sync() {
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/${1}" ]; then
-        git -C "${third_party}/${1}" pull --quiet --prune
+    mkdir -p "./third_party"
+    if [ -d "./third_party/${1}" ]; then
+        git -C "./third_party/${1}" pull --quiet --prune
     else
-        git -C "${third_party}" clone --quiet --recursive ${2}
+        git -C "./third_party" clone --quiet --recursive ${2}
     fi
-    git -C "${third_party}/${1}" submodule sync --quiet
-    git -C "${third_party}/${1}" submodule update --quiet --init --recursive
+    git -C "./third_party/${1}" submodule sync --quiet
+    git -C "./third_party/${1}" submodule update --quiet --init --recursive
 }
 
 clean() {
     bold "onnx clean"
-    rm -rf ${virtualenv}
-    rm -rf ${third_party}/${identifier}
-    rm -rf ${third_party}/onnxmltools
+    rm -rf ./third_party/venv/onnx
+    rm -rf ./third_party/onnx
+    rm -rf ./third_party/onnxmltools
 }
 
 sync() {
@@ -52,53 +57,51 @@ install() {
             brew list protobuf > /dev/null 2>&1 || brew install protobuf > /dev/null
             ;;
     esac
-    [ -n "$(python3 -m pip list --format columns --disable-pip-version-check | grep -w virtualenv)" ] || python3 -m pip install --force-reinstall --user --quiet virtualenv
-    [ -d "${virtualenv}" ] || virtualenv --quiet -p python3 ${virtualenv}
-    source ${virtualenv}/bin/activate
-    python3 -m pip install --quiet --upgrade protobuf
+    venv
+    ${python} -m pip install --quiet --upgrade protobuf
     export ONNX_ML=1
     export ONNX_NAMESPACE=onnx
-    python3 -m pip install --quiet ${third_party}/onnx
+    ${python} -m pip install --quiet ./third_party/onnx
     deactivate
 }
 
 schema() {
     bold "onnx schema"
-    source ${virtualenv}/bin/activate
-    ${node_modules}/protobufjs/bin/pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --no-convert --no-verify --no-create --keep-case --decode-text -r onnx -o ${src}/onnx-proto.js ${third_party}/${identifier}/onnx/onnx-ml.proto ${third_party}/${identifier}/onnx/onnx-operators-ml.proto
-    node ${tools}/update_pbjs.js array ${src}/onnx-proto.js float_data float 1
-    node ${tools}/update_pbjs.js array ${src}/onnx-proto.js double_data double 1
-    deactivate
+    [[ $(file ./src/onnx-proto.js) =~ CRLF ]] && crlf=1
+    npx pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --no-convert --no-verify --no-create --keep-case --decode-text -r onnx -o ./src/onnx-proto.js ./third_party/onnx/onnx/onnx-ml.proto ./third_party/onnx/onnx/onnx-operators-ml.proto
+    node ./tools/update_pbjs.js array ./src/onnx-proto.js float_data float 1
+    node ./tools/update_pbjs.js array ./src/onnx-proto.js double_data double 1
+    if [[ -n ${crlf} ]]; then
+        unix2dos --quiet --newfile ./src/onnx-proto.js ./src/onnx-proto.js
+    fi
 }
 
 metadata() {
     bold "onnx metadata"
-    source ${virtualenv}/bin/activate
-    pushd ${tools} > /dev/null
-    python3 onnx-script.py metadata
-    popd > /dev/null
+    venv
+    ${python} ./tools/onnx-script.py metadata
     deactivate
 }
 
 convert() {
     bold "onnx convert"
-    source ${virtualenv}/bin/activate
-    python3 -m pip install --quiet ${third_party}/onnxmltools
-    python3 ${tools}/onnx-script.py convert ${1}
+    venv
+    ${python} -m pip install --quiet ./third_party/onnxmltools
+    ${python} ./tools/onnx-script.py convert ${1}
     deactivate
 }
 
 infer() {
     bold "onnx infer"
-    source ${virtualenv}/bin/activate
-    python3 ${tools}/onnx-script.py infer ${1}
+    venv
+    ${python} ./tools/onnx-script.py infer ${1}
     deactivate
 }
 
 optimize() {
     bold "onnx optimize"
-    source ${virtualenv}/bin/activate
-    python3 ${tools}/onnx-script.py optimize ${1}
+    venv
+    ${python} ./tools/onnx-script.py optimize ${1}
     deactivate
 }
 

+ 2 - 1
tools/onnx-script.py

@@ -216,7 +216,8 @@ def pip_import(package):
 def metadata():
     schemas = defs.get_all_schemas_with_history()
     schemas = sorted(schemas, key=lambda schema: schema.name)
-    generate_json(schemas, '../src/onnx-metadata.json')
+    json_file = os.path.join(os.path.dirname(__file__), '../src/onnx-metadata.json')
+    generate_json(schemas, json_file)
 
 def convert():
     file = sys.argv[2]

+ 13 - 24
tools/paddle

@@ -1,44 +1,34 @@
 #!/bin/bash
 
 set -e
-
-root=$(cd $(dirname ${0})/..; pwd)
-node_modules=${root}/node_modules
-src=${root}/src
-third_party=${root}/third_party
-tools=${root}/tools
-
-identifier=paddle
-virtualenv=${third_party}/virtualenv/${identifier}
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
 }
 
-git_sync () {
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/${1}" ]; then
-        git -C "${third_party}/${1}" pull --quiet --prune
-    else
-        git -C "${third_party}" clone --quiet --recursive ${2} ${1}
-    fi
-    git -C "${third_party}/${1}" submodule sync --quiet
-    git -C "${third_party}/${1}" submodule update --quiet --init --recursive
-}
-
 clean() {
     bold "paddle clean"
-    rm -rf ${third_party}/paddle
+    rm -rf ./third_party/paddle
 }
 
 sync() {
     bold "paddle sync"
-    git_sync paddle https://github.com/PaddlePaddle/Paddle.git
+    mkdir -p "./third_party"
+    if [ -d "./third_party/paddle" ]; then
+        git -C "./third_party/paddle" pull --quiet --prune
+    else
+        git -C "./third_party" clone --quiet --recursive https://github.com/PaddlePaddle/Paddle.git paddle
+    fi
 }
 
 schema() {
     bold "paddle schema"
-    ${node_modules}/protobufjs/bin/pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --no-convert --no-verify --no-create --keep-case -r paddle -o ${src}/paddle-proto.js ${third_party}/${identifier}/paddle/fluid/framework/framework.proto
+    [[ $(file ./src/paddle-proto.js) =~ CRLF ]] && crlf=1
+    npx pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --no-convert --no-verify --no-create --keep-case -r paddle -o ./src/paddle-proto.js ./third_party/paddle/paddle/fluid/framework/framework.proto
+    if [[ -n ${crlf} ]]; then
+        unix2dos --quiet --newfile ./src/paddle-proto.js ./src/paddle-proto.js
+    fi
 }
 
 while [ "$#" != 0 ]; do
@@ -46,7 +36,6 @@ while [ "$#" != 0 ]; do
     case "${command}" in
         "clean") clean;;
         "sync") sync;;
-        "install") install;;
         "schema") schema;;
     esac
 done

+ 41 - 36
tools/pytorch

@@ -1,37 +1,40 @@
 #!/bin/bash
 
 set -e
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
-root=$(cd $(dirname ${0})/..; pwd)
-build=${root}/build
-node_modules=${root}/node_modules
-src=${root}/src
-test=${root}/test
-third_party=${root}/third_party
-tools=${root}/tools
-
-identifier=pytorch
-virtualenv=${third_party}/virtualenv/${identifier}
+[[ "$(python3 --version 2> /dev/null)" =~ "Python 3" ]] && python=python3 || python=python
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
 }
 
+venv() {
+    venv_dir=./third_party/venv/pytorch
+    [ -d "${venv_dir}" ] || ${python} -m venv ${venv_dir}
+    case "${OSTYPE}" in
+        msys*) source ${venv_dir}/Scripts/activate;;
+        *) source ${venv_dir}/bin/activate;;
+    esac
+    ${python} -m pip install --quiet --upgrade pip
+}
+
 git_sync() {
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/${1}" ]; then
-        git -C "${third_party}/${1}" pull --quiet --prune
+    mkdir -p "./third_party"
+    if [ -d "./third_party/${1}" ]; then
+        git -C "./third_party/${1}" pull --quiet --prune
     else
-        git -C "${third_party}" clone --quiet --recursive ${2} ${1}
+        git -C "./third_party" clone --quiet --recursive ${2} ${1}
     fi
-    git -C "${third_party}/${1}" submodule sync --quiet
-    git -C "${third_party}/${1}" submodule update --quiet --init --recursive
+    git -C "./third_party/${1}" submodule sync --quiet
+    git -C "./third_party/${1}" submodule update --quiet --init --recursive
 }
 
 clean() {
     bold "pytorch clean"
-    rm -rf ${virtualenv}
-    rm -rf ${third_party}/${identifier}
+    rm -rf ./third_party/venv/pytorch
+    rm -rf ./third_party/pytorch
+    rm -rf ./third_party/torchvision
 }
 
 sync() {
@@ -42,39 +45,41 @@ sync() {
 
 install() {
     bold "pytorch install"
-    [ -n "$(python3 -m pip list --format columns --disable-pip-version-check | grep -w virtualenv)" ] || python3 -m pip install --force-reinstall --user --quiet virtualenv
-    [ -d "${virtualenv}" ] || python3 -m virtualenv --quiet -p python3 ${virtualenv}
-    source ${virtualenv}/bin/activate
-    python3 -m pip install --quiet --upgrade future protobuf numpy scikit-build scipy
-    python3 -m pip install --quiet --upgrade ninja pyyaml mkl mkl-include setuptools cmake cffi six typing
-    python3 -m pip install --quiet --pre --upgrade torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
-    python3 -m pip install --quiet --pre --upgrade torchvision -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
+    venv
+    ${python} -m pip install --quiet --upgrade future protobuf
+    ${python} -m pip install --quiet --pre --upgrade torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
+    ${python} -m pip install --quiet --pre --upgrade torchvision -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
     deactivate
 }
 
 schema() {
     bold "caffe2 schema"
-    ${node_modules}/protobufjs/bin/pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --no-convert --no-verify --no-create --keep-case --decode-text -r caffe2 -o ${src}/caffe2-proto.js ${third_party}/pytorch/caffe2/proto/caffe2.proto
-    node ${tools}/update_pbjs.js enumeration ${src}/caffe2-proto.js floats float 1
+    [[ $(file ./src/caffe2-proto.js) =~ CRLF ]] && crlf=1
+    npx pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --no-convert --no-verify --no-create --keep-case --decode-text -r caffe2 -o ./src/caffe2-proto.js ./third_party/pytorch/caffe2/proto/caffe2.proto
+    node ./tools/update_pbjs.js enumeration ./src/caffe2-proto.js floats float 1
+    if [[ -n ${crlf} ]]; then
+        unix2dos --quiet --newfile ./src/caffe2-proto.js ./src/caffe2-proto.js
+    fi
 }
 
 metadata() {
-    source ${virtualenv}/bin/activate
-    pushd ${tools} > /dev/null
+    [[ $(file ./src/pytorch-metadata.json) =~ CRLF ]] && crlf=1
+    venv
     bold "pytorch metadata"
-    python3 pytorch-script.py metadata
+    ${python} ./tools/pytorch-script.py metadata
     bold "caffe2 metadata"
-    python3 caffe2-script.py metadata
-    popd > /dev/null
+    ${python} ./tools/caffe2-script.py metadata
     deactivate
+    if [[ -n ${crlf} ]]; then
+        unix2dos --quiet --newfile ./src/pytorch-metadata.json ./src/pytorch-metadata.json
+        unix2dos --quiet --newfile ./src/caffe2-metadata.json ./src/caffe2-metadata.json
+    fi
 }
 
 zoo() {
     bold "pytorch zoo"
-    source ${virtualenv}/bin/activate
-    pushd ${tools} > /dev/null
-    python3 pytorch-script.py zoo
-    popd > /dev/null
+    venv
+    ${python} ./tools/pytorch-script.py zoo
     deactivate
 }
 

+ 1 - 1
tools/pytorch-script.py

@@ -10,7 +10,7 @@ import re
 import sys
 
 def metadata():
-    json_file = '../src/pytorch-metadata.json'
+    json_file = os.path.join(os.path.dirname(__file__), '../src/pytorch-metadata.json')
     json_data = open(json_file).read()
     json_root = json.loads(json_data)
 

+ 38 - 34
tools/sklearn

@@ -1,27 +1,42 @@
 #!/bin/bash
 
 set -e
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
-root=$(cd $(dirname ${0})/..; pwd)
-third_party=${root}/third_party
-tools=${root}/tools
-
-identifier=scikit-learn
-virtualenv=${third_party}/virtualenv/${identifier}
+[[ "$(python3 --version 2> /dev/null)" =~ "Python 3" ]] && python=python3 || python=python
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
 }
 
+venv() {
+    venv_dir=./third_party/venv/scikit-learn
+    [ -d "${venv_dir}" ] || ${python} -m venv ${venv_dir}
+    case "${OSTYPE}" in
+        msys*) source ${venv_dir}/Scripts/activate;;
+        *) source ${venv_dir}/bin/activate;;
+    esac
+    ${python} -m pip install --quiet --upgrade pip
+}
+
 git_sync() {
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/${1}" ]; then
-        git -C "${third_party}/${1}" pull --quiet --prune
+    mkdir -p "./third_party"
+    if [ -d "./third_party/${1}" ]; then
+        git -C "./third_party/${1}" pull --quiet --prune
     else
-        git -C "${third_party}" clone --quiet --recursive ${2} ${1}
+        git -C "./third_party" clone --quiet --recursive ${2} ${1}
     fi
-    git -C "${third_party}/${1}" submodule sync --quiet
-    git -C "${third_party}/${1}" submodule update --quiet --init --recursive
+    git -C "./third_party/${1}" submodule sync --quiet
+    git -C "./third_party/${1}" submodule update --quiet --init --recursive
+}
+
+clean() {
+    bold "sklearn clean"
+    rm -rf ./third_party/venv/scikit-learn
+    rm -rf ./third_party/numpy
+    rm -rf ./third_party/scikit-learn
+    rm -rf ./third_party/lightgbm
+    rm -rf ./third_party/xgboost
 }
 
 sync() {
@@ -34,39 +49,28 @@ sync() {
 
 install() {
     bold "sklearn install"
-    # case "$(uname)" in
-    #     "Darwin")
-    #         brew list libomp > /dev/null 2>&1 || brew install libomp > /dev/null
-    #         export CC=/usr/bin/clang
-    #         export CXX=/usr/bin/clang++
-    #         export CPPFLAGS="$CPPFLAGS -Xpreprocessor -fopenmp"
-    #         export CFLAGS="$CFLAGS -I/usr/local/opt/libomp/include"
-    #         export CXXFLAGS="$CXXFLAGS -I/usr/local/opt/libomp/include"
-    #         export LDFLAGS="$LDFLAGS -L/usr/local/opt/libomp/lib -lomp"
-    #         export DYLD_LIBRARY_PATH=/usr/local/opt/libomp/lib
-    #         ;;
-    # esac
-    [ -n "$(python3 -m pip list --format columns --disable-pip-version-check | grep -w virtualenv)" ] || python3 -m pip install --force-reinstall --user --quiet virtualenv
-    [ -d "${virtualenv}" ] || virtualenv --quiet -p python3 ${virtualenv}
-    source ${virtualenv}/bin/activate
-    python3 -m pip install --quiet six cython pytest flake8 numpy scipy
-    python3 -m pip install --quiet --pre -f https://sklearn-nightly.scdn8.secure.raxcdn.com scikit-learn
-    # python3 -m pip install --quiet ${third_party}/scikit-learn
+    venv
+    ${python} -m pip install --quiet six cython pytest flake8 numpy scipy pylint astroid isort
+    ${python} -m pip install --quiet --pre -f https://sklearn-nightly.scdn8.secure.raxcdn.com scikit-learn
+    # ${python} -m pip install --quiet ./third_party/scikit-learn
     deactivate
 }
 
 metadata() {
     bold "sklearn metadata"
-    source ${virtualenv}/bin/activate
-    pushd ${tools} > /dev/null
-    python3 sklearn-script.py
-    popd > /dev/null
+    [[ $(file ./src/sklearn-metadata.json) =~ CRLF ]] && crlf=1
+    venv
+    ${python} ./tools/sklearn-script.py
     deactivate
+    if [[ -n ${crlf} ]]; then
+        unix2dos --quiet --newfile ./src/sklearn-metadata.json ./src/sklearn-metadata.json
+    fi
 }
 
 while [ "$#" != 0 ]; do
     command="$1" && shift
     case "${command}" in
+        "clean") clean;;
         "sync") sync;;
         "install") install;;
         "metadata") metadata;;

+ 2 - 1
tools/sklearn-script.py

@@ -4,11 +4,12 @@ from __future__ import print_function
 
 import io
 import json
+import os
 import pydoc
 import re
 import sys
 
-json_file = '../src/sklearn-metadata.json'
+json_file = os.path.join(os.path.dirname(__file__), '../src/sklearn-metadata.json')
 json_data = open(json_file).read()
 json_root = json.loads(json_data)
 

+ 85 - 68
tools/tf

@@ -1,102 +1,119 @@
 #!/bin/bash
 
 set -e
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
-root=$(cd $(dirname ${0})/..; pwd)
-build=${root}/build
-node_modules=${root}/node_modules
-src=${root}/src
-third_party=${root}/third_party
-tools=${root}/tools
-
-identifier=tensorflow
-virtualenv=${third_party}/virtualenv/${identifier}
+[[ "$(python3 --version 2> /dev/null)" =~ "Python 3" ]] && python=python3 || python=python
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
 }
 
-git_sync () {
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/${1}" ]; then
-        git -C "${third_party}/${1}" pull --quiet --prune
-    else
-        git -C "${third_party}" clone --quiet --recursive ${2}
-    fi
-    git -C "${third_party}/${1}" submodule sync --quiet
-    git -C "${third_party}/${1}" submodule update --quiet --init --recursive
+venv() {
+    venv_dir=./third_party/venv/tensorflow
+    [ -d "${venv_dir}" ] || ${python} -m venv ${venv_dir}
+    case "${OSTYPE}" in
+        msys*) source ${venv_dir}/Scripts/activate;;
+        *) source ${venv_dir}/bin/activate;;
+    esac
+    ${python} -m pip install --quiet --upgrade pip
 }
 
 clean() {
     bold "tf clean"
-    rm -rf ${virtualenv}
-    rm -rf ${third_party}/${identifier}
+    rm -rf "./third_party/venv/tensorflow"
+    rm -rf "./third_party/tensorflow"
 }
 
 sync() {
     bold "tf sync"
-    git_sync tensorflow https://github.com/tensorflow/tensorflow.git
+    mkdir -p "./third_party"
+    if [ -d "./third_party/tensorflow" ]; then
+        git -C "./third_party/tensorflow" pull --quiet --prune
+    else
+        git -C "./third_party" clone --quiet --recursive https://github.com/tensorflow/tensorflow.git
+    fi
+    git -C "./third_party/tensorflow" submodule sync --quiet
+    git -C "./third_party/tensorflow" submodule update --quiet --init --recursive
 }
 
 install() {
     bold "tf install"
-    case "$(uname)" in
-        "Linux")
-            [ -n "$(which protoc)" ] || sudo apt install -y protobuf-compiler libprotoc-dev
-            ;;
-        "Darwin")
-            brew list protobuf > /dev/null 2>&1 || brew install protobuf > /dev/null
-            ;;
-    esac
-    [ -n "$(python3 -m pip list --format columns --disable-pip-version-check | grep -w virtualenv)" ] || python3 -m pip install --force-reinstall --user --quiet virtualenv
-    [ -d "${virtualenv}" ] || virtualenv --quiet -p python3 ${virtualenv}
-    source ${virtualenv}/bin/activate
-    python3 -m pip install --quiet --upgrade protobuf
+    venv
+    ${python} -m pip install --quiet --upgrade protobuf
     deactivate
 }
 
 schema() {
     bold "tf schema"
-    ${node_modules}/protobufjs/bin/pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --no-convert --no-verify --no-create --keep-case --decode-text -r tf -o ${src}/tf-proto.js \
-        ${third_party}/${identifier}/tensorflow/core/protobuf/saved_model.proto \
-        ${third_party}/${identifier}/tensorflow/core/protobuf/meta_graph.proto \
-        ${third_party}/${identifier}/tensorflow/core/protobuf/saver.proto \
-        ${third_party}/${identifier}/tensorflow/core/framework/graph.proto \
-        ${third_party}/${identifier}/tensorflow/core/framework/op_def.proto \
-        ${third_party}/${identifier}/tensorflow/core/framework/tensor_shape.proto \
-        ${third_party}/${identifier}/tensorflow/core/framework/types.proto \
-        ${third_party}/${identifier}/tensorflow/core/framework/node_def.proto \
-        ${third_party}/${identifier}/tensorflow/core/framework/versions.proto \
-        ${third_party}/${identifier}/tensorflow/core/framework/function.proto \
-        ${third_party}/${identifier}/tensorflow/core/framework/attr_value.proto \
-        ${third_party}/${identifier}/tensorflow/core/framework/tensor.proto \
-        ${third_party}/${identifier}/tensorflow/core/framework/variable.proto \
-        ${third_party}/${identifier}/tensorflow/core/framework/resource_handle.proto \
-        ${third_party}/${identifier}/tensorflow/core/protobuf/saved_object_graph.proto \
-        ${third_party}/${identifier}/tensorflow/core/protobuf/trackable_object_graph.proto \
-        ${third_party}/${identifier}/tensorflow/core/protobuf/struct.proto \
-        ${third_party}/${identifier}/tensorflow/core/protobuf/tensor_bundle.proto \
-        ${third_party}/${identifier}/tensorflow/core/framework/tensor_slice.proto
+    [[ $(file ./src/tf-proto.js) =~ CRLF ]] && crlf=1
+    npx pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --no-convert --no-verify --no-create --keep-case --decode-text -r tf -o ./src/tf-proto.js \
+        ./third_party/tensorflow/tensorflow/core/protobuf/saved_model.proto \
+        ./third_party/tensorflow/tensorflow/core/protobuf/meta_graph.proto \
+        ./third_party/tensorflow/tensorflow/core/protobuf/saver.proto \
+        ./third_party/tensorflow/tensorflow/core/framework/graph.proto \
+        ./third_party/tensorflow/tensorflow/core/framework/op_def.proto \
+        ./third_party/tensorflow/tensorflow/core/framework/tensor_shape.proto \
+        ./third_party/tensorflow/tensorflow/core/framework/types.proto \
+        ./third_party/tensorflow/tensorflow/core/framework/node_def.proto \
+        ./third_party/tensorflow/tensorflow/core/framework/versions.proto \
+        ./third_party/tensorflow/tensorflow/core/framework/function.proto \
+        ./third_party/tensorflow/tensorflow/core/framework/attr_value.proto \
+        ./third_party/tensorflow/tensorflow/core/framework/tensor.proto \
+        ./third_party/tensorflow/tensorflow/core/framework/variable.proto \
+        ./third_party/tensorflow/tensorflow/core/framework/resource_handle.proto \
+        ./third_party/tensorflow/tensorflow/core/protobuf/saved_object_graph.proto \
+        ./third_party/tensorflow/tensorflow/core/protobuf/trackable_object_graph.proto \
+        ./third_party/tensorflow/tensorflow/core/protobuf/struct.proto \
+        ./third_party/tensorflow/tensorflow/core/protobuf/tensor_bundle.proto \
+        ./third_party/tensorflow/tensorflow/core/framework/tensor_slice.proto
+    if [[ -n ${crlf} ]]; then
+        unix2dos --quiet --newfile ./src/tf-proto.js ./src/tf-proto.js
+    fi
 }
 
 metadata() {
     bold "tf metadata"
-    source ${virtualenv}/bin/activate
-    pushd ${tools} > /dev/null
-    protoc --proto_path ${third_party}/${identifier} ${third_party}/${identifier}/tensorflow/core/framework/attr_value.proto --python_out=${tools}
-    protoc --proto_path ${third_party}/${identifier} ${third_party}/${identifier}/tensorflow/core/framework/tensor.proto --python_out=${tools}
-    protoc --proto_path ${third_party}/${identifier} ${third_party}/${identifier}/tensorflow/core/framework/types.proto --python_out=${tools}
-    protoc --proto_path ${third_party}/${identifier} ${third_party}/${identifier}/tensorflow/core/framework/tensor_shape.proto --python_out=${tools}
-    protoc --proto_path ${third_party}/${identifier} ${third_party}/${identifier}/tensorflow/core/framework/resource_handle.proto --python_out=${tools}
-    protoc --proto_path ${third_party}/${identifier} ${third_party}/${identifier}/tensorflow/core/framework/api_def.proto --python_out=${tools}
-    protoc --proto_path ${third_party}/${identifier} ${third_party}/${identifier}/tensorflow/core/framework/op_def.proto --python_out=${tools}
-    touch ${tools}/tensorflow/__init__.py
-    touch ${tools}/tensorflow/core/__init__.py
-    touch ${tools}/tensorflow/core/framework/__init__.py
-    python3 tf-script.py metadata
-    rm -rf ${tools}/tensorflow
-    popd > /dev/null
+    [[ $(file ./src/tf-metadata.json) =~ CRLF ]] && crlf=1
+    venv
+    case "${OSTYPE}" in
+        linux*)
+            [ -n "$(which protoc)" ] || sudo apt install -y protobuf-compiler libprotoc-dev
+            protoc=protoc
+            ;;
+        darwin*)
+            brew list protobuf > /dev/null 2>&1 || brew install protobuf > /dev/null
+            protoc=protoc
+            ;;
+        msys*)
+            protoc_version=$(curl -s https://api.github.com/repos/protocolbuffers/protobuf/releases/latest | grep tag_name | cut -f 2 -d : | cut -f 2 -d '"' | cut -f 2 -d v)
+            protoc_dir=$(dirname $(mktemp -u))/protobuf/v${protoc_version}
+            if [ ! -f "${protoc_dir}/bin/flatc" ]; then
+                mkdir -p "${protoc_dir}"
+                pushd "${protoc_dir}" > /dev/null
+                curl -sL -O https://github.com/protocolbuffers/protobuf/releases/download/v${protoc_version}/protoc-${protoc_version}-win32.zip
+                unzip protoc-${protoc_version}-win32.zip > /dev/null
+                popd > /dev/null
+            fi
+            protoc=${protoc_dir}/bin/protoc
+            ;;
+    esac
+    ${protoc} --proto_path ./third_party/tensorflow ./third_party/tensorflow/tensorflow/core/framework/attr_value.proto --python_out=./tools
+    ${protoc} --proto_path ./third_party/tensorflow ./third_party/tensorflow/tensorflow/core/framework/tensor.proto --python_out=./tools
+    ${protoc} --proto_path ./third_party/tensorflow ./third_party/tensorflow/tensorflow/core/framework/types.proto --python_out=./tools
+    ${protoc} --proto_path ./third_party/tensorflow ./third_party/tensorflow/tensorflow/core/framework/tensor_shape.proto --python_out=./tools
+    ${protoc} --proto_path ./third_party/tensorflow ./third_party/tensorflow/tensorflow/core/framework/resource_handle.proto --python_out=./tools
+    ${protoc} --proto_path ./third_party/tensorflow ./third_party/tensorflow/tensorflow/core/framework/api_def.proto --python_out=./tools
+    ${protoc} --proto_path ./third_party/tensorflow ./third_party/tensorflow/tensorflow/core/framework/op_def.proto --python_out=./tools
+    touch ./tools/tensorflow/__init__.py
+    touch ./tools/tensorflow/core/__init__.py
+    touch ./tools/tensorflow/core/framework/__init__.py
+    ${python} ./tools/tf-script.py metadata
+    rm -rf ./tools/tensorflow
     deactivate
+    if [[ -n ${crlf} ]]; then
+        unix2dos --quiet --newfile ./src/tf-metadata.json ./src/tf-metadata.json
+    fi
 }
 
 while [ "$#" != 0 ]; do

+ 4 - 5
tools/tf-script.py

@@ -190,10 +190,9 @@ def metadata():
             return convert_shape(attr_value.shape)
         raise Exception()
 
-    api_def_map = read_api_def_map('../third_party/tensorflow/tensorflow/core/api_def/base_api')
-
-    input_file = '../third_party/tensorflow/tensorflow/core/ops/ops.pbtxt'
-
+    tensorflow_repo_dir = os.path.join(os.path.dirname(__file__), '../third_party/tensorflow')
+    api_def_map = read_api_def_map(os.path.join(tensorflow_repo_dir, 'tensorflow/core/api_def/base_api'))
+    input_file = os.path.join(tensorflow_repo_dir, 'tensorflow/core/ops/ops.pbtxt')
     ops_list = op_def_pb2.OpList()
     with open(input_file) as input_handle:
         text_format.Merge(input_handle.read(), ops_list)
@@ -291,7 +290,7 @@ def metadata():
             'schema': json_schema 
         })
 
-    json_file = '../src/tf-metadata.json'
+    json_file = os.path.join(os.path.dirname(__file__), '../src/tf-metadata.json')
     with io.open(json_file, 'w', newline='') as fout:
         json_data = json.dumps(json_root, sort_keys=True, indent=2)
         for line in json_data.splitlines():

+ 48 - 47
tools/tflite

@@ -1,94 +1,95 @@
 #!/bin/bash
 
 set -e
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
-root=$(cd $(dirname ${0})/..; pwd)
-build=${root}/build
-src=${root}/src
-third_party=${root}/third_party
-tools=${root}/tools
-
-identifier=tflite
-virtualenv=${third_party}/virtualenv/${identifier}
+[[ "$(python3 --version 2> /dev/null)" =~ "Python 3" ]] && python=python3 || python=python
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
 }
 
+venv() {
+    venv_dir=./third_party/venv/tflite
+    [ -d "${venv_dir}" ] || ${python} -m venv ${venv_dir}
+    case "${OSTYPE}" in
+        msys*) source ${venv_dir}/Scripts/activate;;
+        *) source ${venv_dir}/bin/activate;;
+    esac
+    ${python} -m pip install --quiet --upgrade pip
+}
+
 clean() {
     bold "tflite clean"
-    rm -rf ${virtualenv}
-    rm -rf ${third_party}/tensorflow
+    rm -rf ./third_party/venv/tflite
+    rm -rf ./third_party/tensorflow
 }
 
 sync() {
     bold "tflite sync"
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/tensorflow" ]; then
-        git -C "${third_party}/tensorflow" pull --quiet --prune
+    mkdir -p "./third_party"
+    if [ -d "./third_party/tensorflow" ]; then
+        git -C "./third_party/tensorflow" pull --quiet --prune
     else
-        git -C "${third_party}" clone --quiet --recursive https://github.com/tensorflow/tensorflow.git
+        git -C "./third_party" clone --quiet --recursive https://github.com/tensorflow/tensorflow.git
     fi
-    git -C "${third_party}/tensorflow" submodule sync --quiet
-    git -C "${third_party}/tensorflow" submodule update --quiet --init --recursive
+    git -C "./third_party/tensorflow" submodule sync --quiet
+    git -C "./third_party/tensorflow" submodule update --quiet --init --recursive
 }
 
 schema() {
     bold "tflite schema"
     case "${OSTYPE}" in
         linux*)
-            FLATC_VERSION=$(curl -s https://api.github.com/repos/google/flatbuffers/releases/latest | grep tag_name | cut -f 2 -d : | cut -f 2 -d '"')
-            FLATC_DIR=$(dirname $(mktemp -u))/flatbuffers/${FLATC_VERSION}
-            if [ ! -f "${FLATC_DIR}/flatc" ]; then
-                mkdir -p "${FLATC_DIR}"
-                pushd "${FLATC_DIR}" > /dev/null
-                curl -sL https://github.com/google/flatbuffers/archive/${FLATC_VERSION}.tar.gz | tar zx --strip-components 1
+            flatc_version=$(curl -s https://api.github.com/repos/google/flatbuffers/releases/latest | grep tag_name | cut -f 2 -d : | cut -f 2 -d '"')
+            flatc_dir=$(dirname $(mktemp -u))/flatbuffers/${flatc_version}
+            if [ ! -f "${flatc_dir}/flatc" ]; then
+                mkdir -p "${flatc_dir}"
+                pushd "${flatc_dir}" > /dev/null
+                curl -sL https://github.com/google/flatbuffers/archive/${flatc_version}.tar.gz | tar zx --strip-components 1
                 cmake -G "Unix Makefiles" . &> /dev/null
                 make > /dev/null
                 popd > /dev/null
             fi
-            FLATC=${FLATC_DIR}/flatc
+            flatc=${flatc_dir}/flatc
             ;;
         darwin*)
             brew list flatbuffers > /dev/null 2>&1 || brew install flatbuffers > /dev/null
-            FLATC=flatc
+            flatc=flatc
             ;;
         msys*)
-            FLATC_VERSION=$(curl -s https://api.github.com/repos/google/flatbuffers/releases/latest | grep tag_name | cut -f 2 -d : | cut -f 2 -d '"')
-            FLATC_DIR=$(dirname $(mktemp -u))/flatbuffers/${FLATC_VERSION}
-            if [ ! -f "${FLATC_DIR}/flatc.exe" ]; then
-                mkdir -p "${FLATC_DIR}"
-                pushd "${FLATC_DIR}" > /dev/null
-                curl -sL -O https://github.com/google/flatbuffers/releases/download/${FLATC_VERSION}/flatc_windows_exe.zip
-                unzip flatc_windows_exe.zip
+            flatc_version=$(curl -s https://api.github.com/repos/google/flatbuffers/releases/latest | grep tag_name | cut -f 2 -d : | cut -f 2 -d '"')
+            flatc_dir=$(dirname $(mktemp -u))/flatbuffers/${flatc_version}
+            if [ ! -f "${flatc_dir}/flatc.exe" ]; then
+                mkdir -p "${flatc_dir}"
+                pushd "${flatc_dir}" > /dev/null
+                curl -sL -O https://github.com/google/flatbuffers/releases/download/${flatc_version}/flatc_windows_exe.zip
+                unzip flatc_windows_exe.zip > /dev/null
                 popd > /dev/null
             fi
-            FLATC=${FLATC_DIR}/flatc.exe
+            flatc=${flatc_dir}/flatc.exe
             ;;
     esac
-    sed 's/namespace tflite;/namespace TFLITE;/g' <${third_party}/tensorflow/tensorflow/lite/schema/schema.fbs >${tools}/tflite.schema.fbs
-    ${FLATC} --no-js-exports --js ${tools}/tflite.schema.fbs
-    rm ${tools}/tflite.schema.fbs
-    mv ./tflite.schema_generated.js ${src}/tflite-schema.js
-    cat <<EOT >> ${src}/tflite-schema.js
+    [[ $(file ./src/tflite-schema.js) =~ CRLF ]] && crlf=1
+    sed 's/namespace tflite;/namespace TFLITE;/g' < ./third_party/tensorflow/tensorflow/lite/schema/schema.fbs > ./tools/tflite.schema.fbs
+    ${flatc} --no-js-exports --js ./tools/tflite.schema.fbs
+    rm ./tools/tflite.schema.fbs
+    mv ./tflite.schema_generated.js ./src/tflite-schema.js
+    cat <<EOT >> ./src/tflite-schema.js
 if (typeof module !== 'undefined' && typeof module.exports === 'object') {
   module.exports = TFLITE;
 }
 EOT
-    case "${OSTYPE}" in
-        msys*)
-            unix2dos --quiet --newfile ${src}/tflite-schema.js ${src}/tflite-schema.js
-            ;;
-    esac
+    if [[ -n ${crlf} ]]; then
+        unix2dos --quiet --newfile ./src/tflite-schema.js ./src/tflite-schema.js
+    fi
 }
 
 visualize() {
     bold "tflite visualize"
-    [ -n "$(python3 -m pip list --format columns --disable-pip-version-check | grep -w virtualenv)" ] || python3 -m pip install --force-reinstall --user --quiet virtualenv
-    [ -d "${virtualenv}" ] || virtualenv --quiet -p python3 ${virtualenv}
-    source ${virtualenv}/bin/activate
-    python3 -m pip install --quiet tensorflow
-    python3 ${third_party}/tensorflow/tensorflow/lite/tools/visualize.py $@
+    venv
+    ${python} -m pip install --quiet tensorflow
+    ${python} ./third_party/tensorflow/tensorflow/lite/tools/visualize.py $@
     deactivate
 }
 

+ 8 - 21
tools/torch

@@ -1,38 +1,25 @@
 #!/bin/bash
 
 set -e
-
-root=$(cd $(dirname ${0})/..; pwd)
-node_modules=${root}/node_modules
-src=${root}/src
-third_party=${root}/third_party
-tools=${root}/tools
-
-identifier=torch
+pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
 
 bold() {
     echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)" 
 }
 
-git_sync() {
-    mkdir -p "${third_party}"
-    if [ -d "${third_party}/${1}" ]; then
-        git -C "${third_party}/${1}" pull --quiet --prune
-    else
-        git -C "${third_party}" clone --quiet --recursive ${2} ${1}
-    fi
-    git -C "${third_party}/${1}" submodule sync --quiet
-    git -C "${third_party}/${1}" submodule update --quiet --init --recursive
-}
-
 clean() {
     bold "torch clean"
-    rm -rf ${third_party}/${identifier}
+    rm -rf ./third_party/torch
 }
 
 sync() {
     bold "torch sync"
-    git_sync torch https://github.com/torch/torch7.git
+    mkdir -p "./third_party"
+    if [ -d "./third_party/torch" ]; then
+        git -C "./third_party/torch" pull --quiet --prune
+    else
+        git -C "./third_party" clone --quiet --recursive https://github.com/torch/torch7.git torch
+    fi
 }
 
 while [ "$#" != 0 ]; do