tf 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. identifier=tensorflow
  10. virtualenv=${build}/virtualenv/${identifier}
  11. if [ $(which python3) ] && [ $(which pip3) ]; then
  12. python="python3"
  13. pip="pip3"
  14. else
  15. python="python"
  16. pip="pip"
  17. fi
  18. bold() {
  19. echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)"
  20. }
  21. git_sync () {
  22. mkdir -p "${third_party}"
  23. if [ -d "${third_party}/${1}" ]; then
  24. git -C "${third_party}/${1}" fetch -p --quiet
  25. git -C "${third_party}/${1}" reset --quiet --hard origin/master
  26. else
  27. echo "Clone ${2}..."
  28. git -C "${third_party}" clone --recursive ${2}
  29. fi
  30. }
  31. clean() {
  32. bold "tf clean"
  33. rm -rf ${virtualenv}
  34. rm -rf ${third_party}/${identifier}
  35. }
  36. sync() {
  37. bold "tf sync"
  38. git_sync tensorflow https://github.com/tensorflow/tensorflow.git
  39. }
  40. install() {
  41. bold "tf install"
  42. virtualenv --quiet -p ${python} ${virtualenv}
  43. source ${virtualenv}/bin/activate
  44. ${pip} install --quiet protobuf
  45. deactivate
  46. }
  47. schema() {
  48. bold "tf schema"
  49. ${node_modules}/protobufjs/bin/pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --keep-case --decode-text -r tf -o ${src}/tf-proto.js \
  50. ${third_party}/${identifier}/tensorflow/core/protobuf/saved_model.proto \
  51. ${third_party}/${identifier}/tensorflow/core/protobuf/meta_graph.proto \
  52. ${third_party}/${identifier}/tensorflow/core/protobuf/saver.proto \
  53. ${third_party}/${identifier}/tensorflow/core/framework/graph.proto \
  54. ${third_party}/${identifier}/tensorflow/core/framework/op_def.proto \
  55. ${third_party}/${identifier}/tensorflow/core/framework/tensor_shape.proto \
  56. ${third_party}/${identifier}/tensorflow/core/framework/types.proto \
  57. ${third_party}/${identifier}/tensorflow/core/framework/node_def.proto \
  58. ${third_party}/${identifier}/tensorflow/core/framework/versions.proto \
  59. ${third_party}/${identifier}/tensorflow/core/framework/function.proto \
  60. ${third_party}/${identifier}/tensorflow/core/framework/attr_value.proto \
  61. ${third_party}/${identifier}/tensorflow/core/framework/tensor.proto \
  62. ${third_party}/${identifier}/tensorflow/core/framework/resource_handle.proto
  63. }
  64. metadata() {
  65. bold "tf metadata"
  66. source ${virtualenv}/bin/activate
  67. pushd ${tools} > /dev/null
  68. protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/attr_value.proto --python_out=${tools}
  69. protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/tensor.proto --python_out=${tools}
  70. protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/types.proto --python_out=${tools}
  71. protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/tensor_shape.proto --python_out=${tools}
  72. protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/resource_handle.proto --python_out=${tools}
  73. protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/api_def.proto --python_out=${tools}
  74. protoc --proto_path ${third_party}/${identifier} tensorflow/core/framework/op_def.proto --python_out=${tools}
  75. touch ${tools}/tensorflow/__init__.py
  76. touch ${tools}/tensorflow/core/__init__.py
  77. touch ${tools}/tensorflow/core/framework/__init__.py
  78. ${python} tf-script.py
  79. rm -rf ${tools}/tensorflow
  80. popd > /dev/null
  81. deactivate
  82. }
  83. while [ "$#" != 0 ]; do
  84. command="$1" && shift
  85. case "${command}" in
  86. "clean") clean;;
  87. "sync") sync;;
  88. "install") install;;
  89. "schema") schema;;
  90. "metadata") metadata;;
  91. esac
  92. done