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.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. --platform=$1 &> ../train.log & # dataset train folder
  43. }
  44. run_gpu()
  45. {
  46. if [ $2 -lt 1 ] && [ $2 -gt 8 ]
  47. then
  48. echo "error: DEVICE_NUM=$2 is not in (1-8)"
  49. exit 1
  50. fi
  51. if [ ! -d $4 ]
  52. then
  53. echo "error: DATASET_PATH=$4 is not a directory"
  54. exit 1
  55. fi
  56. BASEPATH=$(cd "`dirname $0`" || exit; pwd)
  57. export PYTHONPATH=${BASEPATH}:$PYTHONPATH
  58. if [ -d "../train" ];
  59. then
  60. rm -rf ../train
  61. fi
  62. mkdir ../train
  63. cd ../train || exit
  64. export CUDA_VISIBLE_DEVICES="$3"
  65. mpirun -n $2 --allow-run-as-root \
  66. python ${BASEPATH}/../train.py \
  67. --dataset_path=$4 \
  68. --platform=$1 \
  69. &> ../train.log & # dataset train folder
  70. }
  71. if [ $# -gt 5 ] || [ $# -lt 4 ]
  72. then
  73. echo "Usage:\n \
  74. 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]\n \
  75. GPU: sh run_train.sh GPU [DEVICE_NUM] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [DATASET_PATH]\n \
  76. "
  77. exit 1
  78. fi
  79. if [ $1 = "Ascend" ] ; then
  80. run_ascend "$@"
  81. elif [ $1 = "GPU" ] ; then
  82. run_gpu "$@"
  83. else
  84. echo "not support platform"
  85. fi;