coreml 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. if [ $(which python3) ]; then
  11. python="python3"
  12. else
  13. python="python"
  14. fi
  15. bold() {
  16. echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)"
  17. }
  18. git_sync () {
  19. mkdir -p "${third_party}"
  20. if [ -d "${third_party}/${1}" ]; then
  21. git -C "${third_party}/${1}" fetch --quiet -p
  22. git -C "${third_party}/${1}" reset --quiet --hard origin/master
  23. else
  24. git -C "${third_party}" clone --quiet --recursive ${2}
  25. fi
  26. }
  27. clean() {
  28. bold "coreml clean"
  29. rm -rf ${third_party}/coremltools
  30. }
  31. sync() {
  32. bold "coreml sync"
  33. git_sync coremltools https://github.com/apple/coremltools.git
  34. }
  35. install() {
  36. bold "coreml install"
  37. [ -n "$(python3 -m pip list --format columns --disable-pip-version-check | grep -w virtualenv)" ] || ${python} -m pip install --force-reinstall --user --quiet virtualenv
  38. [ -d "${virtualenv}" ] || ${python} -m virtualenv --quiet -p ${python} ${virtualenv}
  39. source ${virtualenv}/bin/activate
  40. ${python} -m pip install --quiet ${third_party}/${identifier}
  41. deactivate
  42. }
  43. schema() {
  44. bold "coreml schema"
  45. ${node_modules}/protobufjs/bin/pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --keep-case -r coreml -o ${src}/coreml-proto.js ${third_party}/${identifier}/mlmodel/format/Model.proto
  46. node ${tools}/update_pbjs.js array ${src}/coreml-proto.js floatValue float 2
  47. }
  48. convert() {
  49. bold "coreml convert"
  50. source ${virtualenv}/bin/activate
  51. ${python} -m pip install --quiet onnx
  52. ${python} -m pip install --quiet sklearn
  53. ${python} ${tools}/coreml-script.py convert ${1}
  54. deactivate
  55. }
  56. while [ "$#" != 0 ]; do
  57. command="$1" && shift
  58. case "${command}" in
  59. "clean") clean;;
  60. "sync") sync;;
  61. "install") install;;
  62. "schema") schema;;
  63. "convert") convert ${1} && shift;;
  64. esac
  65. done