onnx-update 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/bash
  2. set -e
  3. root=$(cd $(dirname ${0})/../..; pwd)
  4. build=${root}/build
  5. node_modules=${root}/node_modules
  6. src=${root}/src
  7. third_party=${root}/third_party
  8. tools=${root}/tools
  9. python=${python:-python}
  10. pip=${pip:-pip}
  11. identifier=onnx
  12. repository=https://github.com/onnx/${identifier}.git
  13. mkdir -p ${third_party}
  14. if [ -d "${third_party}/${identifier}" ]; then
  15. git -C "${third_party}/${identifier}" fetch -p
  16. git -C "${third_party}/${identifier}" reset --hard origin/master
  17. else
  18. echo "Clone ${repository}..."
  19. git -C "${third_party}" clone --recursive ${repository}
  20. fi
  21. echo "Install ONNX"
  22. virtualenv=${build}/virtualenv/${identifier}
  23. virtualenv -p ${python} ${virtualenv}
  24. source ${virtualenv}/bin/activate
  25. export ONNX_ML=1
  26. export ONNX_NAMESPACE=onnx
  27. ${pip} install ${third_party}/${identifier}
  28. echo "Generate 'onnx-metadata.json'"
  29. pushd ${tools}/metadata > /dev/null
  30. ${python} onnx-metadata.py
  31. popd > /dev/null
  32. deactivate
  33. echo "Generate 'onnx.js'"
  34. ${node_modules}/protobufjs/bin/pbjs -t static-module -w closure -r onnx -o ${src}/onnx.js ${third_party}/${identifier}/onnx/onnx-ml.proto ${third_party}/${identifier}/onnx/onnx-operators-ml.proto
  35. node ${tools}/metadata/update_pbjs.js array ${src}/onnx.js floatData float 1
  36. node ${tools}/metadata/update_pbjs.js array ${src}/onnx.js doubleData double 1