keras 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. set -e
  3. root=$(cd $(dirname ${0})/..; pwd)
  4. build=${root}/build
  5. test=${root}/test
  6. tools=${root}/tools
  7. third_party=${root}/third_party
  8. if [ $(which python3) ]; then
  9. python="python3"
  10. else
  11. python="python"
  12. fi
  13. identifier=keras
  14. virtualenv=${build}/virtualenv/${identifier}
  15. bold() {
  16. echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)"
  17. }
  18. git_sync() {
  19. mkdir -p "${third_party}"
  20. if [ -d "${third_party}/${1}" ]; then
  21. git -C "${third_party}/${1}" fetch --quiet -p
  22. git -C "${third_party}/${1}" reset --quiet --hard origin/master
  23. else
  24. git -C "${third_party}" clone --quiet --recursive ${2}
  25. fi
  26. git -C "${third_party}" submodule update --quiet --init
  27. }
  28. clean() {
  29. bold "keras clean"
  30. rm -rf ${virtualenv}
  31. rm -rf ${third_party}/${identifier}
  32. }
  33. sync() {
  34. bold "keras sync"
  35. git_sync keras https://github.com/keras-team/keras.git
  36. }
  37. install() {
  38. bold "keras install"
  39. [ -n "$(python3 -m pip list --disable-pip-version-check | grep -w virtualenv)" ] || ${python} -m pip install --force-reinstall --user --quiet virtualenv
  40. [ -d "${virtualenv}" ] || virtualenv --quiet -p ${python} ${virtualenv}
  41. source ${virtualenv}/bin/activate
  42. ${python} -m pip install --quiet tensorflow
  43. ${python} -m pip install --quiet ${third_party}/${identifier}
  44. deactivate
  45. }
  46. metadata() {
  47. bold "keras metadata"
  48. source ${virtualenv}/bin/activate
  49. pushd ${tools} > /dev/null
  50. ${python} keras-script.py metadata
  51. popd > /dev/null
  52. deactivate
  53. }
  54. zoo() {
  55. bold "keras zoo"
  56. source ${virtualenv}/bin/activate
  57. pushd ${tools} > /dev/null
  58. ${python} keras-script.py zoo keras.applications.densenet.DenseNet121 ${test}/data/keras/DenseNet121.h5
  59. ${python} keras-script.py zoo keras.applications.inception_resnet_v2.InceptionResNetV2 ${test}/data/keras/InceptionResNetV2.h5
  60. ${python} keras-script.py zoo keras.applications.inception_v3.InceptionV3 ${test}/data/keras/InceptionV3.h5
  61. ${python} keras-script.py zoo keras.applications.mobilenet_v2.MobileNetV2 ${test}/data/keras/MobileNetV2.h5
  62. ${python} keras-script.py zoo keras.applications.nasnet.NASNetMobile ${test}/data/keras/NASNetMobile.h5
  63. ${python} keras-script.py zoo keras.applications.resnet50.ResNet50 ${test}/data/keras/ResNet50.h5
  64. ${python} keras-script.py zoo keras.applications.vgg16.VGG16 ${test}/data/keras/VGG16.h5
  65. ${python} keras-script.py zoo keras.applications.vgg19.VGG19 ${test}/data/keras/VGG19.h5
  66. ${python} keras-script.py zoo keras.applications.xception.Xception ${test}/data/keras/Xception.h5
  67. rm -rf ~/.keras/models
  68. popd > /dev/null
  69. deactivate
  70. }
  71. while [ "$#" != 0 ]; do
  72. command="$1" && shift
  73. case "${command}" in
  74. "clean") clean;;
  75. "sync") sync;;
  76. "install") install;;
  77. "metadata") metadata;;
  78. "zoo") zoo;;
  79. esac
  80. done