Browse Source

Update CoreML script

Lutz Roeder 6 years ago
parent
commit
10be6ea602
2 changed files with 16 additions and 26 deletions
  1. 1 1
      Makefile
  2. 15 25
      tools/coreml

+ 1 - 1
Makefile

@@ -24,7 +24,7 @@ update:
 	@./tools/armnn sync schema
 	@./tools/bigdl sync schema
 	@./tools/caffe sync schema
-	@./tools/coreml sync install schema
+	@./tools/coreml sync schema
 	@./tools/chainer sync
 	@./tools/cntk sync schema
 	@./tools/darknet sync

+ 15 - 25
tools/coreml

@@ -8,53 +8,43 @@ src=${root}/src
 third_party=${root}/third_party
 tools=${root}/tools
 
-identifier=coremltools
-virtualenv=${third_party}/virtualenv/${identifier}
+virtualenv=${third_party}/virtualenv/coremltools
 
 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 "coreml clean"
+    rm -rf ${virtualenv}
     rm -rf ${third_party}/coremltools
 }
 
 sync() {
     bold "coreml sync"
-    git_sync coremltools https://github.com/apple/coremltools.git
-}
-
-install() {
-    bold "coreml 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 six numpy protobuf
-    python3 -m pip install --quiet ${third_party}/${identifier}
-    deactivate
+    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
+    fi
+    git -C "${third_party}/coremltools" submodule sync --quiet
+    git -C "${third_party}/coremltools" submodule update --quiet --init --recursive
 }
 
 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}/${identifier}/mlmodel/format/Model.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 -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
 }
 
 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}