tf 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. venv() {
  9. env_dir=./third_party/env/tensorflow
  10. [ -d "${env_dir}" ] || ${python} -m venv ${env_dir}
  11. case "${OSTYPE}" in
  12. msys*) source ${env_dir}/Scripts/activate;;
  13. *) source ${env_dir}/bin/activate;;
  14. esac
  15. ${python} -m pip install --quiet --upgrade pip requests
  16. }
  17. clean() {
  18. echo "tf clean"
  19. rm -rf "./third_party/env/tensorflow"
  20. rm -rf "./third_party/source/tensorflow"
  21. rm -rf "./third_party/source/tflite-support"
  22. }
  23. sync() {
  24. echo "tf sync"
  25. [ -d "./third_party/source/tensorflow" ] || git clone --quiet https://github.com/tensorflow/tensorflow.git "./third_party/source/tensorflow"
  26. git -C "./third_party/source/tensorflow" pull --quiet --prune
  27. mkdir -p "./third_party/source/tflite-support/tensorflow_lite_support/metadata"
  28. curl --silent --location --output "./third_party/source/tflite-support/tensorflow_lite_support/metadata/metadata_schema.fbs" "https://github.com/tensorflow/tflite-support/raw/master/tensorflow_lite_support/metadata/metadata_schema.fbs"
  29. }
  30. install() {
  31. echo "tf install"
  32. venv
  33. ${python} -m pip install --quiet --upgrade wheel
  34. ${python} -m pip install --quiet --upgrade tf-nightly > /dev/null 2>&1 || true
  35. deactivate
  36. }
  37. schema() {
  38. echo "tf schema"
  39. [[ $(grep -U $'\x0D' ./source/tf-proto.js) ]] && crlf=1
  40. node ./tools/protoc.js --binary --text --json --root tf --out ./source/tf-proto.js --path ./third_party/source/tensorflow --path ./third_party/source/tensorflow/third_party/xla tensorflow/core/protobuf/saved_model.proto tensorflow/core/protobuf/tensor_bundle.proto tensorflow/core/util/saved_tensor_slice.proto tensorflow/core/util/event.proto tensorflow/core/protobuf/config.proto tensorflow/core/util/memmapped_file_system.proto tensorflow/core/protobuf/fingerprint.proto
  41. if [[ -n ${crlf} ]]; then
  42. unix2dos --quiet --newfile ./source/tf-proto.js ./source/tf-proto.js
  43. fi
  44. echo "tflite schema"
  45. [[ $(grep -U $'\x0D' ./source/tflite-schema.js) ]] && crlf=1
  46. temp1=$(mktemp -d)
  47. temp2=$(mktemp -d)
  48. node ./tools/flatc.js --text --root tflite --out ./source/tflite-schema.js ./third_party/source/tensorflow/tensorflow/compiler/mlir/lite/schema/schema.fbs ./third_party/source/tflite-support/tensorflow_lite_support/metadata/metadata_schema.fbs
  49. if [[ -n ${crlf} ]]; then
  50. unix2dos --quiet --newfile ./source/tflite-schema.js ./source/tflite-schema.js
  51. fi
  52. echo "keras schema"
  53. [[ $(grep -U $'\x0D' ./source/keras-proto.js) ]] && crlf=1
  54. node ./tools/protoc.js --binary --text --root tf --out ./source/keras-proto.js --path ./third_party/source/tensorflow --path ./third_party/source/tensorflow/third_party/xla/third_party/tsl tensorflow/python/keras/protobuf/saved_metadata.proto
  55. if [[ -n ${crlf} ]]; then
  56. unix2dos --quiet --newfile ./source/keras-proto.js ./source/keras-proto.js
  57. fi
  58. }
  59. metadata() {
  60. echo "tflite metadata"
  61. export TF_CPP_MIN_LOG_LEVEL=2
  62. if [[ $(grep -U $'\x0D' ./source/tflite-metadata.json) ]]; then crlf=1; else crlf=; fi
  63. node ./tools/tflite-script.js
  64. if [[ -n ${crlf} ]]; then
  65. unix2dos --quiet --newfile ./source/tflite-metadata.json ./source/tflite-metadata.json
  66. fi
  67. echo "tf metadata"
  68. venv
  69. if [[ $(grep -U $'\x0D' ./source/tf-metadata.json) ]]; then crlf=1; else crlf=; fi
  70. export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
  71. if pip show "tf-nightly" > /dev/null 2>&1; then
  72. ${python} ./tools/tf_script.py
  73. fi
  74. if [[ -n ${crlf} ]]; then
  75. unix2dos --quiet --newfile ./source/tf-metadata.json ./source/tf-metadata.json
  76. fi
  77. deactivate
  78. }
  79. while [ "$#" != 0 ]; do
  80. command="$1" && shift
  81. case "${command}" in
  82. "clean") clean;;
  83. "sync") sync;;
  84. "install") install;;
  85. "schema") schema;;
  86. "metadata") metadata;;
  87. esac
  88. done