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_train.sh 2.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/usr/bin/env 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. run_ascend()
  17. {
  18. if [ $2 -lt 1 ] && [ $2 -gt 8 ]
  19. then
  20. echo "error: DEVICE_NUM=$2 is not in (1-8)"
  21. exit 1
  22. fi
  23. if [ ! -d $5 ]
  24. then
  25. echo "error: DATASET_PATH=$5 is not a directory"
  26. exit 1
  27. fi
  28. BASEPATH=$(cd "`dirname $0`" || exit; pwd)
  29. export PYTHONPATH=${BASEPATH}:$PYTHONPATH
  30. if [ -d "../train" ];
  31. then
  32. rm -rf ../train
  33. fi
  34. mkdir ../train
  35. cd ../train || exit
  36. python ${BASEPATH}/../src/launch.py \
  37. --nproc_per_node=$2 \
  38. --visible_devices=$4 \
  39. --server_id=$3 \
  40. --training_script=${BASEPATH}/../train.py \
  41. --dataset_path=$5 \
  42. --pre_trained=$6 \
  43. --platform=$1 &> ../train.log & # dataset train folder
  44. }
  45. run_gpu()
  46. {
  47. if [ $2 -lt 1 ] && [ $2 -gt 8 ]
  48. then
  49. echo "error: DEVICE_NUM=$2 is not in (1-8)"
  50. exit 1
  51. fi
  52. if [ ! -d $4 ]
  53. then
  54. echo "error: DATASET_PATH=$4 is not a directory"
  55. exit 1
  56. fi
  57. BASEPATH=$(cd "`dirname $0`" || exit; pwd)
  58. export PYTHONPATH=${BASEPATH}:$PYTHONPATH
  59. if [ -d "../train" ];
  60. then
  61. rm -rf ../train
  62. fi
  63. mkdir ../train
  64. cd ../train || exit
  65. export CUDA_VISIBLE_DEVICES="$3"
  66. mpirun -n $2 --allow-run-as-root \
  67. python ${BASEPATH}/../train.py \
  68. --dataset_path=$4 \
  69. --platform=$1 \
  70. &> ../train.log & # dataset train folder
  71. }
  72. if [ $# -gt 6 ] || [ $# -lt 4 ]
  73. then
  74. echo "Usage:\n \
  75. Ascend: sh run_train.sh Ascend [DEVICE_NUM] [SERVER_IP(x.x.x.x)] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [DATASET_PATH] [CKPT_PATH]\n \
  76. GPU: sh run_train.sh GPU [DEVICE_NUM] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [DATASET_PATH]\n \
  77. "
  78. exit 1
  79. fi
  80. if [ $1 = "Ascend" ] ; then
  81. run_ascend "$@"
  82. elif [ $1 = "GPU" ] ; then
  83. run_gpu "$@"
  84. else
  85. echo "not support platform"
  86. fi;