tflite-update 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/bin/bash
  2. set -e
  3. if [ "$#" == 0 ]; then
  4. __sync=true
  5. __build=true
  6. __update=true
  7. else
  8. while test $# -gt 0
  9. do
  10. case "$1" in
  11. sync) __sync=true;;
  12. build) __build=true;;
  13. update) __update=true;;
  14. esac
  15. shift
  16. done
  17. fi
  18. root=$(cd $(dirname ${0})/../..; pwd)
  19. src=${root}/src
  20. tools=${root}/tools
  21. third_party=${root}/third_party
  22. mkdir -p ${third_party}
  23. identifier=tensorflow
  24. if [ ${__sync} ]; then
  25. repository=https://github.com/google/flatbuffers.git
  26. if [ -d "${third_party}/flatbuffers" ]; then
  27. git -C "${third_party}/flatbuffers" fetch -p
  28. git -C "${third_party}/flatbuffers" reset --hard origin/master
  29. else
  30. echo "Clone ${repository}..."
  31. git -C "${third_party}" clone --recursive ${repository}
  32. fi
  33. repository=https://github.com/tensorflow/${identifier}.git
  34. if [ -d "${third_party}/${identifier}" ]; then
  35. git -C "${third_party}/${identifier}" fetch -p
  36. git -C "${third_party}/${identifier}" reset --hard origin/master
  37. else
  38. echo "Clone ${repository}..."
  39. git -C "${third_party}" clone --recursive ${repository}
  40. fi
  41. fi
  42. if [ ${__build} ]; then
  43. pushd "${third_party}/flatbuffers" > /dev/null
  44. cmake -G "Unix Makefiles"
  45. make
  46. popd > /dev/null
  47. fi
  48. if [ ${__update} ]; then
  49. echo "Generate '../src/tflite-schema.js'"
  50. cp ${third_party}/tensorflow/tensorflow/lite/schema/schema.fbs ${tools}/metadata/tflite.schema.fbs
  51. sed -i 's/namespace tflite\;/namespace tflite_schema\;/' ${tools}/metadata/tflite.schema.fbs
  52. ${third_party}/flatbuffers/flatc --no-js-exports --js ${tools}/metadata/tflite.schema.fbs
  53. mv ./tflite.schema_generated.js ${src}/tflite-schema.js
  54. rm ${tools}/metadata/tflite.schema.fbs
  55. cat <<EOT >> ${src}/tflite-schema.js
  56. if (typeof module !== 'undefined' && typeof module.exports === 'object') {
  57. module.exports = tflite_schema;
  58. }
  59. EOT
  60. fi