2
0

tflite 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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=python3;;
  7. esac
  8. bold() {
  9. echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)"
  10. }
  11. venv() {
  12. env_dir=./third_party/env/tflite
  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 "tflite clean"
  22. rm -rf "./third_party/env/tflite"
  23. rm -rf "./third_party/src/tensorflow"
  24. }
  25. sync() {
  26. bold "tflite sync"
  27. [ -d "./third_party/src/tensorflow" ] || git clone --quiet --recursive https://github.com/tensorflow/tensorflow.git "./third_party/src/tensorflow"
  28. pushd "./third_party/src/tensorflow" > /dev/null
  29. git pull --quiet --prune
  30. git submodule sync --quiet
  31. git submodule update --quiet --init --recursive
  32. popd > /dev/null
  33. }
  34. schema() {
  35. bold "tflite schema"
  36. case "${OSTYPE}" in
  37. linux*)
  38. flatc_version=$(curl -s https://api.github.com/repos/google/flatbuffers/releases/latest | grep tag_name | cut -f 2 -d : | cut -f 2 -d '"')
  39. flatc_dir=./third_party/bin/flatbuffers/${flatc_version}
  40. if [ ! -f "${flatc_dir}/flatc" ]; then
  41. mkdir -p "${flatc_dir}"
  42. pushd "${flatc_dir}" > /dev/null
  43. curl -sL https://github.com/google/flatbuffers/archive/${flatc_version}.tar.gz | tar zx --strip-components 1
  44. cmake -G "Unix Makefiles" . &> /dev/null
  45. make > /dev/null
  46. popd > /dev/null
  47. fi
  48. export PATH=${flatc_dir}:${PATH}
  49. ;;
  50. darwin*)
  51. brew list flatbuffers > /dev/null 2>&1 || brew install flatbuffers > /dev/null
  52. ;;
  53. msys*)
  54. [ -x "$(command -v flatc)" ] || $(choco install flatc) > /dev/null
  55. ;;
  56. esac
  57. [[ $(grep -U $'\x0D' ./src/tflite-schema.js) ]] && crlf=1
  58. sed 's/namespace tflite;/namespace TFLITE;/g' < ./third_party/src/tensorflow/tensorflow/lite/schema/schema.fbs > ./tools/tflite.schema.fbs
  59. flatc --no-js-exports --js ./tools/tflite.schema.fbs
  60. rm ./tools/tflite.schema.fbs
  61. mv ./tflite.schema_generated.js ./src/tflite-schema.js
  62. cat <<EOT >> ./src/tflite-schema.js
  63. if (typeof module !== 'undefined' && typeof module.exports === 'object') {
  64. module.exports = TFLITE;
  65. }
  66. EOT
  67. if [[ -n ${crlf} ]]; then
  68. unix2dos --quiet --newfile ./src/tflite-schema.js ./src/tflite-schema.js
  69. fi
  70. }
  71. while [ "$#" != 0 ]; do
  72. command="$1" && shift
  73. case "${command}" in
  74. "clean") clean;;
  75. "sync") sync;;
  76. "install") install;;
  77. "schema") schema;;
  78. esac
  79. done