tf 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/bin/bash
  2. set -e
  3. pushd $(cd $(dirname ${0})/..; pwd) > /dev/null
  4. case "${OSTYPE}" in
  5. msys*) python="winpty python";;
  6. *) python="python";;
  7. esac
  8. bold() {
  9. echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)"
  10. }
  11. venv() {
  12. env_dir=./third_party/env/tf
  13. [ -d "${env_dir}" ] || ${python} -m venv ${env_dir}
  14. case "${OSTYPE}" in
  15. msys*) source ${env_dir}/Scripts/activate;;
  16. *) source ${env_dir}/bin/activate;;
  17. esac
  18. ${python} -m pip install --quiet --upgrade pip
  19. }
  20. clean() {
  21. bold "tf clean"
  22. rm -rf "./third_party/env/tf"
  23. rm -rf "./third_party/source/tf"
  24. }
  25. sync() {
  26. bold "tf sync"
  27. [ -d "./third_party/source/tf" ] || git clone --quiet --recursive https://github.com/tensorflow/tensorflow.git "./third_party/source/tf"
  28. pushd "./third_party/source/tf" > /dev/null
  29. git pull --quiet --prune
  30. git submodule sync --quiet
  31. git submodule update --quiet --init --recursive
  32. popd > /dev/null
  33. [ -d "./third_party/source/tflite-support" ] || git clone --quiet --recursive https://github.com/tensorflow/tflite-support.git "./third_party/source/tflite-support"
  34. pushd "./third_party/source/tflite-support" > /dev/null
  35. git pull --quiet --prune
  36. popd > /dev/null
  37. }
  38. install() {
  39. bold "tf install"
  40. if [ "$(uname -ms)" = "Darwin arm64" ]; then
  41. echo "- arm64 [skip]"
  42. return
  43. fi
  44. venv
  45. ${python} -m pip install --quiet --upgrade wheel
  46. ${python} -m pip install --quiet --upgrade tf-nightly
  47. deactivate
  48. }
  49. schema() {
  50. bold "tf schema"
  51. [[ $(grep -U $'\x0D' ./source/tf-proto.js) ]] && crlf=1
  52. node ./tools/protoc.js --text --root tf --out ./source/tf-proto.js --path ./third_party/source/tf tensorflow/core/protobuf/saved_model.proto tensorflow/core/protobuf/tensor_bundle.proto tensorflow/core/util/saved_tensor_slice.proto tensorflow/core/util/event.proto
  53. if [[ -n ${crlf} ]]; then
  54. unix2dos --quiet --newfile ./source/tf-proto.js ./source/tf-proto.js
  55. fi
  56. bold "tflite schema"
  57. [[ $(grep -U $'\x0D' ./source/tflite-schema.js) ]] && crlf=1
  58. temp1=$(mktemp -d)
  59. temp2=$(mktemp -d)
  60. node ./tools/flatc.js --text --root tflite --out ./source/tflite-schema.js ./third_party/source/tf/tensorflow/lite/schema/schema.fbs
  61. node ./tools/flatc.js --root tflite --out ${temp1}/tflite-metadata-schema.js ./third_party/source/tflite-support/tensorflow_lite_support/metadata/metadata_schema.fbs
  62. sed "s/var \$root = flatbuffers.get('tflite');//g" < ${temp1}/tflite-metadata-schema.js >> ${temp2}/tflite-metadata-schema.js
  63. cat ${temp2}/tflite-metadata-schema.js >> ./source/tflite-schema.js
  64. rm -rf ${temp1} ${temp2}
  65. if [[ -n ${crlf} ]]; then
  66. unix2dos --quiet --newfile ./source/tflite-schema.js ./source/tflite-schema.js
  67. fi
  68. }
  69. metadata() {
  70. bold "tf metadata"
  71. if [ "$(uname -ms)" = "Darwin arm64" ]; then
  72. echo "- arm64 [skip]"
  73. return
  74. fi
  75. venv
  76. if [[ $(grep -U $'\x0D' ./source/tf-metadata.json) ]]; then crlf=1; else crlf=; fi
  77. export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
  78. ${python} ./tools/tf-script.py metadata
  79. if [[ -n ${crlf} ]]; then
  80. unix2dos --quiet --newfile ./source/tf-metadata.json ./source/tf-metadata.json
  81. fi
  82. deactivate
  83. bold "keras metadata"
  84. venv
  85. if [[ $(grep -U $'\x0D' ./source/keras-metadata.json) ]]; then crlf=1; else crlf=; fi
  86. ${python} ./tools/keras-script.py metadata
  87. if [[ -n ${crlf} ]]; then
  88. unix2dos --quiet --newfile ./source/keras-metadata.json ./source/keras-metadata.json
  89. fi
  90. deactivate
  91. }
  92. zoo() {
  93. bold "keras zoo"
  94. venv
  95. export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
  96. ${python} ./tools/keras-script.py zoo
  97. deactivate
  98. }
  99. while [ "$#" != 0 ]; do
  100. command="$1" && shift
  101. case "${command}" in
  102. "clean") clean;;
  103. "sync") sync;;
  104. "install") install;;
  105. "schema") schema;;
  106. "metadata") metadata;;
  107. "zoo") zoo;;
  108. esac
  109. done