pytorch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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) ] && [ $(which pip3) ]; then
  13. python="python3"
  14. pip="pip3"
  15. else
  16. python="python"
  17. pip="pip"
  18. fi
  19. bold() {
  20. echo "$(tty -s && tput bold)$1$(tty -s && tput sgr0)"
  21. }
  22. git_sync() {
  23. mkdir -p "${third_party}"
  24. if [ -d "${third_party}/${1}" ]; then
  25. git -C "${third_party}/${1}" fetch --quiet -p
  26. git -C "${third_party}/${1}" reset --quiet --hard origin/$(git -C "${third_party}/${1}" rev-parse --abbrev-ref HEAD)
  27. else
  28. git -C "${third_party}" clone --quiet --recursive ${2}
  29. fi
  30. git -C "${third_party}" submodule update --quiet --init
  31. }
  32. clean() {
  33. bold "pytorch clean"
  34. rm -rf ${virtualenv}
  35. rm -rf ${third_party}/${identifier}
  36. }
  37. sync() {
  38. bold "pytorch sync"
  39. git_sync pytorch https://github.com/pytorch/pytorch.git
  40. }
  41. install() {
  42. bold "pytorch install"
  43. case "$(uname)" in
  44. "Darwin")
  45. if [ -z "$(which cmake)" ]; then
  46. brew bundle --file=- <<-EOS
  47. brew "automake"
  48. brew "cmake"
  49. brew "gflags"
  50. brew "glog"
  51. EOS
  52. fi
  53. ;;
  54. esac
  55. if [ ! -d "${virtualenv}" ]; then
  56. virtualenv --quiet -p ${python} ${virtualenv}
  57. fi
  58. source ${virtualenv}/bin/activate
  59. pushd "${third_party}/pytorch" > /dev/null
  60. ${pip} install --quiet future leveldb numpy protobuf pydot python-gflags pyyaml scikit-image setuptools six hypothesis typing tqdm
  61. ${pip} install --quiet torchvision
  62. ${pip} install --quiet .
  63. popd > /dev/null
  64. deactivate
  65. }
  66. schema() {
  67. bold "caffe2 schema"
  68. ${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
  69. node ${tools}/update_pbjs.js enumeration ${src}/caffe2-proto.js floats float 1
  70. }
  71. metadata() {
  72. source ${virtualenv}/bin/activate
  73. pushd ${tools} > /dev/null
  74. bold "pytorch metadata"
  75. ${python} pytorch-script.py metadata
  76. bold "caffe2 metadata"
  77. ${python} caffe2-script.py metadata
  78. popd > /dev/null
  79. deactivate
  80. }
  81. zoo() {
  82. bold "pytorch zoo"
  83. source ${virtualenv}/bin/activate
  84. pushd ${tools} > /dev/null
  85. ${python} pytorch-script.py zoo torchvision.models.alexnet ${test}/data/pytorch/alexnet.pth
  86. ${python} pytorch-script.py zoo torchvision.models.densenet121 ${test}/data/pytorch/densenet121.pth
  87. ${python} pytorch-script.py zoo torchvision.models.densenet161 ${test}/data/pytorch/densenet161.pth
  88. ${python} pytorch-script.py zoo torchvision.models.inception_v3 ${test}/data/pytorch/inception_v3.pth
  89. ${python} pytorch-script.py zoo torchvision.models.resnet101 ${test}/data/pytorch/resnet101.pth
  90. ${python} pytorch-script.py zoo torchvision.models.resnet18 ${test}/data/pytorch/resnet18.pth
  91. ${python} pytorch-script.py zoo torchvision.models.resnet50 ${test}/data/pytorch/resnet50.pth
  92. ${python} pytorch-script.py zoo torchvision.models.squeezenet1_0 ${test}/data/pytorch/squeezenet1_0.pth
  93. ${python} pytorch-script.py zoo torchvision.models.vgg11_bn ${test}/data/pytorch/vgg11_bn.pth
  94. ${python} pytorch-script.py zoo torchvision.models.vgg16 ${test}/data/pytorch/vgg16.pth
  95. rm -rf ~/.torch/models
  96. popd > /dev/null
  97. deactivate
  98. }
  99. while [ "$#" != 0 ]; do
  100. command="$1" && shift
  101. case "${command}" in
  102. "clean") clean;;
  103. "sync") sync;;
  104. "install") install;;
  105. "schema") schema;;
  106. "metadata") metadata;;
  107. "zoo") zoo;;
  108. esac
  109. done