forked from corenel/pytorch-adda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.sh
128 lines (118 loc) · 4.4 KB
/
cmd.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
function process_args {
declare -A args
# 無名引数数
local gpu_i=$1
local exec_num=$2
local dset_num=$3 # -1の時, 前dsetを実行
shift 3 # 無名引数数
# 残りの名前付き引数を解析
local parent="OfficeHome"
local task_temp=""
local resume=""
local tmux_session=""
local params=$(getopt -n "$0" -o p:t: -l parent:,task:,resume:,tmux: -- "$@")
eval set -- "$params"
while true; do
case "$1" in
-p|--parent)
parent="$2"
shift 2
;;
-t|--task)
task_temp="$2"
shift 2
;;
--resume)
resume=" --resume $2"
shift 2
;;
--tmux)
tmux_session="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "不明な引数: $1" >&2
return 1
;;
esac
done
if [ $parent = 'Office31' ]; then
local task=(
# "original_uda"
# "true_domains"
# "simclr_rpl_uniform_dim512_wght0.5_bs512_ep300_g3_encoder_outdim64_shfl"
# "simclr_bs512_ep300_g3_shfl"
# "simple_bs512_ep300_g3_AE_outd64_shfl"
"contrastive_rpl_dim512_wght0.6_AE_bs256_ep300_outd64_g3"
)
elif [ $parent = 'OfficeHome' ]; then
local task=(
# "original_uda"
"true_domains"
# "simclr_rpl_dim128_wght0.5_bs512_ep3000_g3_encoder_outdim64_shfl"
# "simclr_bs512_ep1000_g3_shfl"
)
fi
if [ ! -z "$task_temp" ]; then
task=("$task_temp")
fi
echo "gpu_i: $gpu_i"
echo "exec_num: $exec_num"
echo "dset_num: $dset_num"
echo "parent: $parent"
echo "task: $task"
echo -e '' # (今は使っていないが)改行文字は echo コマンドに -e オプションを付けて実行した場合にのみ機能する.
###################################################
##### データセット設定
if [ $parent = 'Office31' ]; then
dsetlist=("amazon_dslr" "webcam_amazon" "dslr_webcam")
elif [ $parent = 'OfficeHome' ]; then
dsetlist=('Art_Clipart' 'Art_Product' 'Art_RealWorld' 'Clipart_Product' 'Clipart_RealWorld' 'Product_RealWorld')
elif [ $parent = 'DomainNet' ]; then
dsetlist=('clipart_infograph' 'clipart_painting' 'clipart_quickdraw' 'clipart_real' 'clipart_sketch' 'infograph_painting' 'infograph_quickdraw' 'infograph_real' 'infograph_sketch' 'painting_quickdraw' 'painting_real' 'painting_sketch' 'quickdraw_real' 'quickdraw_sketch' 'real_sketch')
else
echo "不明なデータセット: $parent" >&2
return 1
fi
###################################################
COMMAND="conda deactivate && conda deactivate "
COMMAND+=" && conda activate cdan "
for tsk in "${task[@]}"; do
if [ $dset_num -eq -1 ]; then
for dset in "${dsetlist[@]}"; do
COMMAND+=" && CUDA_VISIBLE_DEVICES=$gpu_i exec_num=$exec_num python main.py --parent $parent --dset $dset --task $tsk $resume"
done
elif [[ $dset_num == *"_"* ]]; then # アンダーラインが含まれているかチェック
# アンダーラインで文字列を分割
IFS='_' read -r -a dset_num_list <<< "$dset_num"
for num in "${dset_num_list[@]}"; do
dset=${dsetlist[$num]}
COMMAND+=" && CUDA_VISIBLE_DEVICES=$gpu_i exec_num=$exec_num python main.py --parent $parent --dset $dset --task $tsk $resume"
done
else
dset=${dsetlist[$dset_num]}
COMMAND+=" && CUDA_VISIBLE_DEVICES=$gpu_i exec_num=$exec_num python main.py --parent $parent --dset $dset --task $tsk $resume"
fi
done
###### 実行.
echo $COMMAND
echo ''
if [ -n "$tmux_session" ]; then
tmux -2 new -d -s $tmux_session
tmux send-key -t $tmux_session.0 "$COMMAND" ENTER
else
eval $COMMAND
fi
}
########## Verify the number of arguments ##########
# 最初の3つの引数をチェック
if [ "$#" -lt 3 ]; then
echo "エラー: 引数が足りません。最初の3つの引数は必須です。" >&2
return 1
fi
########## Main ##########
process_args "$@"