tf 4.0 KB

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