From 941fbe88b4bc40f85478d3f42eaa3ee23f2ba132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=9D=BF?= Date: Mon, 21 Nov 2022 16:49:28 +0800 Subject: [PATCH] Put all the train scripts into scripts directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add scripts directory to start training easier than before User should execute common env setup script only once before training other models Remove some of the arguments and set them by common env setup script Update readme file for each model Signed-off-by: 李睿 --- cv/classification/acmix/pytorch/README.md | 7 +++++-- cv/classification/acmix/pytorch/run.sh | 19 ++++++++++------- scripts/_utils/common_env_setup.sh | 25 +++++++++++++++++++++++ scripts/acmix/pytorch/run.sh | 1 + 4 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 scripts/_utils/common_env_setup.sh create mode 120000 scripts/acmix/pytorch/run.sh diff --git a/cv/classification/acmix/pytorch/README.md b/cv/classification/acmix/pytorch/README.md index b7f5e724..c46c7e6a 100644 --- a/cv/classification/acmix/pytorch/README.md +++ b/cv/classification/acmix/pytorch/README.md @@ -15,7 +15,10 @@ Sign up and login in [imagenet official website](https://www.image-net.org/index ### Swin-S + ACmix on ImageNet using 8 cards: ``` -bash run.sh 8 acmix_swin_small_patch4_window7_224.yaml +mkdir -p /data/datasets +ln -s /path/to/imagenet /data/datasets/imagenet +source /scripts/_utils/common_env_setup.sh +bash run.sh ``` ## Results on BI-V100 @@ -26,4 +29,4 @@ bash run.sh 8 acmix_swin_small_patch4_window7_224.yaml ## Reference -https://github.com/leaplabthu/acmix \ No newline at end of file +https://github.com/leaplabthu/acmix diff --git a/cv/classification/acmix/pytorch/run.sh b/cv/classification/acmix/pytorch/run.sh index 8041c1e2..96ed6bee 100644 --- a/cv/classification/acmix/pytorch/run.sh +++ b/cv/classification/acmix/pytorch/run.sh @@ -1,9 +1,14 @@ -NGPU=$1 -CONFIG=$2 -DATA_PATH=$3 +#!/bin/bash -cd Swin-Transformer +source ${ROOT_DIR}/scripts/_utils/common_env_setup.sh -python3 -m torch.distributed.launch --nproc_per_node ${NGPU} \ - --master_port 12345 main.py --cfg configs/${CONFIG} \ - --data-path ${DATA_PATH} --batch-size 128 +DATA_PATH=${DATA_DIR}/imagenet +CONFIG="acmix_swin_small_patch4_window7_224.yaml" + +cd ${ROOT_DIR}/cv/classification/acmix/pytorch/Swin-Transformer + +python3 -m torch.distributed.launch --master_port 12345 --nproc_per_node ${NGPU} \ + main.py --cfg configs/${CONFIG} \ + --data-path ${DATA_PATH} \ + --batch-size 128 \ + "$@" diff --git a/scripts/_utils/common_env_setup.sh b/scripts/_utils/common_env_setup.sh new file mode 100644 index 00000000..8ecce547 --- /dev/null +++ b/scripts/_utils/common_env_setup.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +ROOT_DIR=$(git rev-parse --show-toplevel) +export ROOT_DIR=$ROOT_DIR + +data_dir=$DATA_DIR +if [ -n "$data_dir" ]; then + data_dir=$DATA_DIR +else + data_dir=$ROOT_DIR/data/datasets +fi +DATA_DIR=$data_dir +export DATA_DIR=$data_dir + +devices=$CUDA_VISIBLE_DEVICES +if [ -n "$devices" ]; then + _devices=(${devices//,/ }) + num_devices=${#_devices[@]} +else + num_devices=1 + export CUDA_VISIBLE_DEVICES=0 + echo "CUDA_VISIBLE_DEVICES Not found, set nproc_per_node = ${num_devices}" +fi +NGPU=${num_devices} +export NGPU=$NGPU diff --git a/scripts/acmix/pytorch/run.sh b/scripts/acmix/pytorch/run.sh new file mode 120000 index 00000000..d48eb835 --- /dev/null +++ b/scripts/acmix/pytorch/run.sh @@ -0,0 +1 @@ +../../../cv/classification/acmix/pytorch/run.sh \ No newline at end of file -- Gitee