coreml 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. set -e
  3. root=$(cd $(dirname ${0})/..; pwd)
  4. node_modules=${root}/node_modules
  5. src=${root}/src
  6. third_party=${root}/third_party
  7. tools=${root}/tools
  8. identifier=coremltools
  9. virtualenv=${third_party}/virtualenv/${identifier}
  10. bold() {
  11. echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)"
  12. }
  13. git_sync () {
  14. mkdir -p "${third_party}"
  15. if [ -d "${third_party}/${1}" ]; then
  16. git -C "${third_party}/${1}" pull --quiet --prune
  17. else
  18. git -C "${third_party}" clone --quiet --recursive ${2}
  19. fi
  20. git -C "${third_party}/${1}" submodule sync --quiet
  21. git -C "${third_party}/${1}" submodule update --quiet --init --recursive
  22. }
  23. clean() {
  24. bold "coreml clean"
  25. rm -rf ${third_party}/coremltools
  26. }
  27. sync() {
  28. bold "coreml sync"
  29. git_sync coremltools https://github.com/apple/coremltools.git
  30. }
  31. install() {
  32. bold "coreml install"
  33. [ -n "$(python3 -m pip list --format columns --disable-pip-version-check | grep -w virtualenv)" ] || python3 -m pip install --force-reinstall --user --quiet virtualenv
  34. [ -d "${virtualenv}" ] || python3 -m virtualenv --quiet -p python3 ${virtualenv}
  35. source ${virtualenv}/bin/activate
  36. python3 -m pip install --quiet ${third_party}/${identifier}
  37. deactivate
  38. }
  39. schema() {
  40. bold "coreml schema"
  41. ${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
  42. node ${tools}/update_pbjs.js array ${src}/coreml-proto.js floatValue float 2
  43. }
  44. convert() {
  45. bold "coreml convert"
  46. source ${virtualenv}/bin/activate
  47. python3 -m pip install --quiet onnx
  48. python3 -m pip install --quiet sklearn
  49. python3 ${tools}/coreml-script.py convert ${1}
  50. deactivate
  51. }
  52. while [ "$#" != 0 ]; do
  53. command="$1" && shift
  54. case "${command}" in
  55. "clean") clean;;
  56. "sync") sync;;
  57. "install") install;;
  58. "schema") schema;;
  59. "convert") convert ${1} && shift;;
  60. esac
  61. done