| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #!/bin/bash
- set -e
- pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
- [[ "$(python3 --version 2> /dev/null)" =~ "Python 3" ]] && python=python3 || python=python
- 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)"
- }
- clean() {
- bold "coreml clean"
- 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
- else
- git -C "./third_party" clone --quiet --recursive https://github.com/apple/coremltools.git
- fi
- popd > /dev/null
- }
- schema() {
- bold "coreml schema"
- [[ $(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"
- 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
- }
- while [ "$#" != 0 ]; do
- command="$1" && shift
- case "${command}" in
- "clean") clean;;
- "sync") sync;;
- "install") install;;
- "schema") schema;;
- "convert") convert ${1} && shift;;
- esac
- done
|