tf-update 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. tools=${root}/tools
  8. third_party=${root}/third_party
  9. python=${python:-python}
  10. pip=${pip:-pip}
  11. identifier=tensorflow
  12. repository=https://github.com/tensorflow/${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 "Generate '../src/tf.js'"
  22. ${node_modules}/protobufjs/bin/pbjs -t static-module -w closure -r tf -o ${src}/tf.js \
  23. ${third_party}/${identifier}/tensorflow/core/protobuf/saved_model.proto \
  24. ${third_party}/${identifier}/tensorflow/core/protobuf/meta_graph.proto \
  25. ${third_party}/${identifier}/tensorflow/core/protobuf/saver.proto \
  26. ${third_party}/${identifier}/tensorflow/core/framework/graph.proto \
  27. ${third_party}/${identifier}/tensorflow/core/framework/op_def.proto \
  28. ${third_party}/${identifier}/tensorflow/core/framework/tensor_shape.proto \
  29. ${third_party}/${identifier}/tensorflow/core/framework/types.proto \
  30. ${third_party}/${identifier}/tensorflow/core/framework/node_def.proto \
  31. ${third_party}/${identifier}/tensorflow/core/framework/versions.proto \
  32. ${third_party}/${identifier}/tensorflow/core/framework/function.proto \
  33. ${third_party}/${identifier}/tensorflow/core/framework/attr_value.proto \
  34. ${third_party}/${identifier}/tensorflow/core/framework/tensor.proto \
  35. ${third_party}/${identifier}/tensorflow/core/framework/resource_handle.proto \
  36. export PYTHONUSERBASE=${build}/third_party/pypi/${identifier}
  37. export PATH=$PATH:${PYTHONUSERBASE}/bin
  38. echo $PYTHONUSERBASE
  39. rm -rf ${PYTHONUSERBASE}
  40. ${pip} install --user protobuf
  41. echo "Generate '../src/tf-metadata.json'"
  42. protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/attr_value.proto --python_out=${tools}
  43. protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/tensor.proto --python_out=${tools}
  44. protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/types.proto --python_out=${tools}
  45. protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/tensor_shape.proto --python_out=${tools}
  46. protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/resource_handle.proto --python_out=${tools}
  47. protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/api_def.proto --python_out=${tools}
  48. protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/op_def.proto --python_out=${tools}
  49. touch ${tools}/tensorflow/__init__.py
  50. touch ${tools}/tensorflow/core/__init__.py
  51. touch ${tools}/tensorflow/core/framework/__init__.py
  52. pushd ${tools} > /dev/null
  53. ${python} tf-metadata.py
  54. popd > /dev/null
  55. rm -rf ${tools}/tensorflow