You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

run_standalone_train.sh 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/bash
  2. # Copyright 2020 Huawei Technologies Co., Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # ============================================================================
  16. if [ $# != 3 ] && [ $# != 4 ]
  17. then
  18. echo "Usage: sh run_standalone_train.sh [resnet50|resnet101] [cifar10|imagenet2012] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)"
  19. exit 1
  20. fi
  21. if [ $1 != "resnet50" ] && [ $1 != "resnet101" ]
  22. then
  23. echo "error: the selected net is neither resnet50 nor resnet101"
  24. exit 1
  25. fi
  26. if [ $2 != "cifar10" ] && [ $2 != "imagenet2012" ]
  27. then
  28. echo "error: the selected dataset is neither cifar10 nor imagenet2012"
  29. exit 1
  30. fi
  31. if [ $1 == "resnet101" ] && [ $2 == "cifar10" ]
  32. then
  33. echo "error: training resnet101 with cifar10 dataset is unsupported now!"
  34. exit 1
  35. fi
  36. get_real_path(){
  37. if [ "${1:0:1}" == "/" ]; then
  38. echo "$1"
  39. else
  40. echo "$(realpath -m $PWD/$1)"
  41. fi
  42. }
  43. PATH1=$(get_real_path $3)
  44. if [ $# == 4 ]
  45. then
  46. PATH2=$(get_real_path $4)
  47. fi
  48. if [ ! -d $PATH1 ]
  49. then
  50. echo "error: DATASET_PATH=$PATH1 is not a directory"
  51. exit 1
  52. fi
  53. if [ $# == 4 ] && [ ! -f $PATH2 ]
  54. then
  55. echo "error: PRETRAINED_CKPT_PATH=$PATH2 is not a file"
  56. exit 1
  57. fi
  58. ulimit -u unlimited
  59. export DEVICE_NUM=1
  60. export DEVICE_ID=0
  61. export RANK_ID=0
  62. export RANK_SIZE=1
  63. if [ -d "train" ];
  64. then
  65. rm -rf ./train
  66. fi
  67. mkdir ./train
  68. cp ../*.py ./train
  69. cp *.sh ./train
  70. cp -r ../src ./train
  71. cd ./train || exit
  72. echo "start training for device $DEVICE_ID"
  73. env > env.log
  74. if [ $# == 3 ]
  75. then
  76. python train.py --net=$1 --dataset=$2 --dataset_path=$PATH1 &> log &
  77. fi
  78. if [ $# == 4 ]
  79. then
  80. python train.py --net=$1 --dataset=$2 --dataset_path=$PATH1 --pre_trained=$PATH2 &> log &
  81. fi
  82. cd ..