pytorch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/bin/bash
  2. set -e
  3. root=$(cd $(dirname ${0})/..; pwd)
  4. build=${root}/build
  5. node_modules=${root}/node_modules
  6. src=${root}/src
  7. test=${root}/test
  8. tools=${root}/tools
  9. third_party=${root}/third_party
  10. identifier=pytorch
  11. virtualenv=${build}/virtualenv/${identifier}
  12. if [ $(which python3) ]; then
  13. python="python3"
  14. else
  15. python="python"
  16. fi
  17. bold() {
  18. echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)"
  19. }
  20. git_sync() {
  21. mkdir -p "${third_party}"
  22. if [ -d "${third_party}/${1}" ]; then
  23. git -C "${third_party}/${1}" fetch --quiet -p
  24. git -C "${third_party}/${1}" reset --quiet --hard origin/$(git -C "${third_party}/${1}" rev-parse --abbrev-ref HEAD)
  25. else
  26. git -C "${third_party}" clone --quiet --recursive ${2}
  27. fi
  28. git -C "${third_party}" submodule update --quiet --init
  29. }
  30. clean() {
  31. bold "pytorch clean"
  32. rm -rf ${virtualenv}
  33. rm -rf ${third_party}/${identifier}
  34. }
  35. sync() {
  36. bold "pytorch sync"
  37. git_sync pytorch https://github.com/pytorch/pytorch.git
  38. }
  39. install() {
  40. bold "pytorch install"
  41. case "$(uname)" in
  42. "Linux")
  43. [ -n "$(which cmake)" ] || sudo apt install -y cmake
  44. ;;
  45. "Darwin")
  46. brew list automake > /dev/null 2>&1 || brew install automake > /dev/null
  47. brew list cmake > /dev/null 2>&1 || brew install cmake > /dev/null
  48. brew list gflags > /dev/null 2>&1 || brew install gflags > /dev/null
  49. brew list glog > /dev/null 2>&1 || brew install glog > /dev/null
  50. ;;
  51. esac
  52. [ -n "$(python3 -m pip list --format columns --disable-pip-version-check | grep -w virtualenv)" ] || ${python} -m pip install --force-reinstall --user --quiet virtualenv
  53. [ -d "${virtualenv}" ] || ${python} -m virtualenv --quiet -p ${python} ${virtualenv}
  54. source ${virtualenv}/bin/activate
  55. ${python} -m pip install --quiet future leveldb numpy protobuf pydot python-gflags pyyaml scikit-image setuptools six hypothesis typing tqdm
  56. ${python} -m pip install --quiet ${third_party}/pytorch
  57. ${python} -m pip install --quiet torchvision
  58. deactivate
  59. }
  60. schema() {
  61. bold "caffe2 schema"
  62. ${node_modules}/protobufjs/bin/pbjs -t static-module -w closure --no-encode --no-delimited --no-comments --keep-case --decode-text -r caffe2 -o ${src}/caffe2-proto.js ${third_party}/pytorch/caffe2/proto/caffe2.proto
  63. node ${tools}/update_pbjs.js enumeration ${src}/caffe2-proto.js floats float 1
  64. }
  65. metadata() {
  66. source ${virtualenv}/bin/activate
  67. pushd ${tools} > /dev/null
  68. bold "pytorch metadata"
  69. ${python} pytorch-script.py metadata
  70. bold "caffe2 metadata"
  71. ${python} caffe2-script.py metadata
  72. popd > /dev/null
  73. deactivate
  74. }
  75. zoo() {
  76. bold "pytorch zoo"
  77. source ${virtualenv}/bin/activate
  78. pushd ${tools} > /dev/null
  79. ${python} pytorch-script.py zoo torchvision.models.alexnet ${test}/data/pytorch/alexnet.pth
  80. ${python} pytorch-script.py zoo torchvision.models.densenet121 ${test}/data/pytorch/densenet121.pth
  81. ${python} pytorch-script.py zoo torchvision.models.densenet161 ${test}/data/pytorch/densenet161.pth
  82. ${python} pytorch-script.py zoo torchvision.models.inception_v3 ${test}/data/pytorch/inception_v3.pth
  83. ${python} pytorch-script.py zoo torchvision.models.resnet101 ${test}/data/pytorch/resnet101.pth
  84. ${python} pytorch-script.py zoo torchvision.models.resnet18 ${test}/data/pytorch/resnet18.pth
  85. ${python} pytorch-script.py zoo torchvision.models.resnet50 ${test}/data/pytorch/resnet50.pth
  86. ${python} pytorch-script.py zoo torchvision.models.squeezenet1_0 ${test}/data/pytorch/squeezenet1_0.pth
  87. ${python} pytorch-script.py zoo torchvision.models.vgg11_bn ${test}/data/pytorch/vgg11_bn.pth
  88. ${python} pytorch-script.py zoo torchvision.models.vgg16 ${test}/data/pytorch/vgg16.pth
  89. rm -rf ~/.torch/models
  90. popd > /dev/null
  91. deactivate
  92. }
  93. while [ "$#" != 0 ]; do
  94. command="$1" && shift
  95. case "${command}" in
  96. "clean") clean;;
  97. "sync") sync;;
  98. "install") install;;
  99. "schema") schema;;
  100. "metadata") metadata;;
  101. "zoo") zoo;;
  102. esac
  103. done