tf 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 --quiet -p
  25. git -C "${third_party}/${1}" reset --quiet --hard origin/master
  26. else
  27. git -C "${third_party}" clone --quiet --recursive ${2}
  28. fi
  29. }
  30. clean() {
  31. bold "tf clean"
  32. rm -rf ${virtualenv}
  33. rm -rf ${third_party}/${identifier}
  34. }
  35. sync() {
  36. bold "tf sync"
  37. git_sync tensorflow https://github.com/tensorflow/tensorflow.git
  38. }
  39. install() {
  40. bold "tf install"
  41. case "$(uname)" in
  42. "Linux")
  43. if [ -z "$(which protoc)" ]; then
  44. sudo apt install protobuf-compiler libprotoc-dev
  45. fi
  46. ;;
  47. "Darwin")
  48. if [ -z "$(which protoc)" ]; then
  49. brew install protobuf
  50. fi
  51. ;;
  52. esac
  53. if [ ! -d "${virtualenv}" ]; then
  54. virtualenv --quiet -p ${python} ${virtualenv}
  55. fi
  56. source ${virtualenv}/bin/activate
  57. ${pip} install --quiet protobuf
  58. deactivate
  59. }
  60. schema() {
  61. bold "tf schema"
  62. ${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 \
  63. ${third_party}/${identifier}/tensorflow/core/protobuf/saved_model.proto \
  64. ${third_party}/${identifier}/tensorflow/core/protobuf/meta_graph.proto \
  65. ${third_party}/${identifier}/tensorflow/core/protobuf/saver.proto \
  66. ${third_party}/${identifier}/tensorflow/core/framework/graph.proto \
  67. ${third_party}/${identifier}/tensorflow/core/framework/op_def.proto \
  68. ${third_party}/${identifier}/tensorflow/core/framework/tensor_shape.proto \
  69. ${third_party}/${identifier}/tensorflow/core/framework/types.proto \
  70. ${third_party}/${identifier}/tensorflow/core/framework/node_def.proto \
  71. ${third_party}/${identifier}/tensorflow/core/framework/versions.proto \
  72. ${third_party}/${identifier}/tensorflow/core/framework/function.proto \
  73. ${third_party}/${identifier}/tensorflow/core/framework/attr_value.proto \
  74. ${third_party}/${identifier}/tensorflow/core/framework/tensor.proto \
  75. ${third_party}/${identifier}/tensorflow/core/framework/resource_handle.proto
  76. }
  77. metadata() {
  78. bold "tf metadata"
  79. source ${virtualenv}/bin/activate
  80. pushd ${tools} > /dev/null
  81. protoc --proto_path ${third_party}/${identifier} ${third_party}/${identifier}/tensorflow/core/framework/attr_value.proto --python_out=${tools}
  82. protoc --proto_path ${third_party}/${identifier} ${third_party}/${identifier}/tensorflow/core/framework/tensor.proto --python_out=${tools}
  83. protoc --proto_path ${third_party}/${identifier} ${third_party}/${identifier}/tensorflow/core/framework/types.proto --python_out=${tools}
  84. protoc --proto_path ${third_party}/${identifier} ${third_party}/${identifier}/tensorflow/core/framework/tensor_shape.proto --python_out=${tools}
  85. protoc --proto_path ${third_party}/${identifier} ${third_party}/${identifier}/tensorflow/core/framework/resource_handle.proto --python_out=${tools}
  86. protoc --proto_path ${third_party}/${identifier} ${third_party}/${identifier}/tensorflow/core/framework/api_def.proto --python_out=${tools}
  87. protoc --proto_path ${third_party}/${identifier} ${third_party}/${identifier}/tensorflow/core/framework/op_def.proto --python_out=${tools}
  88. touch ${tools}/tensorflow/__init__.py
  89. touch ${tools}/tensorflow/core/__init__.py
  90. touch ${tools}/tensorflow/core/framework/__init__.py
  91. ${python} tf-script.py
  92. rm -rf ${tools}/tensorflow
  93. popd > /dev/null
  94. deactivate
  95. }
  96. while [ "$#" != 0 ]; do
  97. command="$1" && shift
  98. case "${command}" in
  99. "clean") clean;;
  100. "sync") sync;;
  101. "install") install;;
  102. "schema") schema;;
  103. "metadata") metadata;;
  104. esac
  105. done