-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtta.sh
executable file
·340 lines (294 loc) · 12.3 KB
/
tta.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
SRC_PREFIX="reproduce_src"
LOG_PREFIX="reproduce_methods"
DATASETS="cifar10" # cifar10 or cifar100 or imagenet
METHODS="NOTE" #Src BN_Stats ONDA PseudoLabel TENT CoTTA NOTE NOTE_iid
echo DATASETS: $DATASETS
echo METHODS: $METHODS
GPUS=(0 1 2 3 4 5 6 7) #available gpus
NUM_GPUS=${#GPUS[@]}
sleep 1 # prevent mistake
mkdir raw_logs # save console outputs here
#### Useful functions
wait_n() {
#limit the max number of jobs as NUM_MAX_JOB and wait
background=($(jobs -p))
local default_num_jobs=8 #num concurrent jobs
local num_max_jobs=${1:-$default_num_jobs}
if ((${#background[@]} >= num_max_jobs)); then
wait -n
fi
}
test_time_adaptation() {
###############################################################
###### Run Baselines & NOTE; Evaluation: Target domains ######
###############################################################
i=0
for DATASET in $DATASETS; do
for METHOD in $METHODS; do
update_every_x="64"
memory_size="64"
SEED="0"
lr="0.001" #other baselines
validation="--dummy"
weight_decay="0"
if [ "${DATASET}" = "cifar10" ]; then
MODEL="resnet18"
CP_base="log/cifar10/Src/tgt_test/"${SRC_PREFIX}
# TGTS="test"
TGTS="gaussian_noise-5
shot_noise-5
impulse_noise-5
defocus_blur-5
glass_blur-5
motion_blur-5
zoom_blur-5
snow-5
frost-5
fog-5
brightness-5
contrast-5
elastic_transform-5
pixelate-5
jpeg_compression-5"
elif [ "${DATASET}" = "cifar100" ]; then
MODEL="resnet18"
CP_base="log/cifar100/Src/tgt_test/"${SRC_PREFIX}
# TGTS="test"
TGTS="gaussian_noise-5
shot_noise-5
impulse_noise-5
defocus_blur-5
glass_blur-5
motion_blur-5
zoom_blur-5
snow-5
frost-5
fog-5
brightness-5
contrast-5
elastic_transform-5
pixelate-5
jpeg_compression-5"
elif [ "${DATASET}" = "imagenet" ]; then
MODEL="resnet18_pretrained"
CP_base="log/imagenet/Src/tgt_test/"${SRC_PREFIX}
TGTS="gaussian_noise-5
shot_noise-5
impulse_noise-5
defocus_blur-5
glass_blur-5
motion_blur-5
zoom_blur-5
snow-5
frost-5
fog-5
brightness-5
contrast-5
elastic_transform-5
pixelate-5
jpeg_compression-5"
fi
for SEED in 0 1 2; do #multiple seeds
if [ "${METHOD}" = "Src" ]; then
EPOCH=0
if [ "${DATASET}" = "imagenet" ]; then
CP="" # use pytorch-provided model
else
CP="--load_checkpoint_path "${CP_base}_${SEED}/cp/cp_last.pth.tar
fi
for TGT in $TGTS; do
python main.py --gpu_idx ${GPUS[i % ${NUM_GPUS}]} --dataset $DATASET --method ${METHOD} --tgt ${TGT} --model $MODEL --epoch $EPOCH --update_every_x ${update_every_x} ${CP} --seed $SEED \
--log_prefix ${LOG_PREFIX}_${SEED} \
${validation} \
2>&1 | tee raw_logs/${DATASET}_${LOG_PREFIX}_${SEED}_job${i}.txt &
i=$((i + 1))
wait_n
done
elif [ "${METHOD}" = "NOTE" ]; then
lr="0.0001"
EPOCH=1
memory_type="PBRS"
loss_scaler=0
iabn_k=4
bn_momentum=0.01
if [ "${DATASET}" = "imagenet" ]; then
CP="--load_checkpoint_path "${CP_base}_0_iabn_k${iabn_k}/cp/cp_last.pth.tar
else
CP="--load_checkpoint_path "${CP_base}_${SEED}_iabn_k${iabn_k}/cp/cp_last.pth.tar
fi
for dist in 0 1; do #dist 0: non-i.i.d. / dist 1: i.i.d.
for TGT in $TGTS; do
python main.py --gpu_idx ${GPUS[i % ${NUM_GPUS}]} --dataset $DATASET --method ${METHOD} --tgt ${TGT} --model $MODEL --epoch $EPOCH ${CP} --seed $SEED \
--remove_cp --online --use_learned_stats --lr ${lr} --weight_decay ${weight_decay} --tgt_train_dist ${dist} --update_every_x ${update_every_x} --memory_size ${memory_size} --memory_type ${memory_type} --bn_momentum ${bn_momentum} \
--iabn --iabn_k ${iabn_k} \
--log_prefix ${LOG_PREFIX}_${SEED}_dist${dist}_iabn_k${iabn_k}_mt${bn_momentum} \
--loss_scaler ${loss_scaler} \
${validation} \
2>&1 | tee raw_logs/${DATASET}_${LOG_PREFIX}_${SEED}_job${i}.txt &
i=$((i + 1))
wait_n
done
done
elif [ "${METHOD}" = "NOTE_iid" ]; then # NOTE given an i.i.d. assumption
lr="0.001"
EPOCH=1
memory_type="FIFO"
loss_scaler=0
iabn_k=4
if [ "${DATASET}" = "imagenet" ]; then
CP="--load_checkpoint_path "${CP_base}_0_iabn_k${iabn_k}/cp/cp_last.pth.tar
else
CP="--load_checkpoint_path "${CP_base}_${SEED}_iabn_k${iabn_k}/cp/cp_last.pth.tar
fi
for dist in 1; do # dist 1: i.i.d.
### Train with IABN
for TGT in $TGTS; do
python main.py --gpu_idx ${GPUS[i % ${NUM_GPUS}]} --dataset $DATASET --method "NOTE" --tgt ${TGT} --model $MODEL --epoch $EPOCH ${CP} --seed $SEED \
--remove_cp --online --lr ${lr} --weight_decay ${weight_decay} --tgt_train_dist ${dist} --update_every_x ${update_every_x} --memory_size ${memory_size} --memory_type ${memory_type} \
--iabn --iabn_k ${iabn_k} \
--log_prefix ${LOG_PREFIX}_iid_${SEED}_dist${dist}_iabn_k${iabn_k} \
--loss_scaler ${loss_scaler} \
${validation} \
2>&1 | tee raw_logs/${DATASET}_${LOG_PREFIX}_${SEED}_job${i}.txt &
i=$((i + 1))
wait_n
done
done
elif [ "${METHOD}" = "BN_Stats" ]; then
if [ "${DATASET}" = "imagenet" ]; then
CP="" # use pytorch-provided model
else
CP="--load_checkpoint_path "${CP_base}_${SEED}/cp/cp_last.pth.tar
fi
#### Train with BN
for dist in 0 1; do
for TGT in $TGTS; do
python main.py --gpu_idx ${GPUS[i % ${NUM_GPUS}]} --dataset $DATASET --method ${METHOD} --tgt ${TGT} --model $MODEL --epoch $EPOCH ${CP} --seed $SEED \
--remove_cp --online --tgt_train_dist ${dist} --update_every_x ${update_every_x} --memory_size ${memory_size} \
--log_prefix ${LOG_PREFIX}_${SEED}_dist${dist} \
${validation} \
2>&1 | tee raw_logs/${DATASET}_${LOG_PREFIX}_${SEED}_job${i}.txt &
i=$((i + 1))
wait_n
done
done
elif [ "${METHOD}" = "ONDA" ]; then
EPOCH=1
#### Train with BN
update_every_x=10
memory_size=10
bn_momentum=0.1
if [ "${DATASET}" = "imagenet" ]; then
CP="" # use pytorch-provided model
else
CP="--load_checkpoint_path "${CP_base}_${SEED}/cp/cp_last.pth.tar
fi
for dist in 0 1; do
for TGT in $TGTS; do
python main.py --gpu_idx ${GPUS[i % ${NUM_GPUS}]} --dataset $DATASET --method ${METHOD} --tgt ${TGT} --model $MODEL --epoch $EPOCH ${CP} --seed $SEED \
--remove_cp --online --use_learned_stats --weight_decay ${weight_decay} --tgt_train_dist ${dist} --update_every_x ${update_every_x} --memory_size ${memory_size} \
--bn_momentum ${bn_momentum} \
--log_prefix ${LOG_PREFIX}_${SEED}_dist${dist} \
${validation} \
2>&1 | tee raw_logs/${DATASET}_${LOG_PREFIX}_${SEED}_job${i}.txt &
i=$((i + 1))
wait_n
done
done
elif [ "${METHOD}" = "PseudoLabel" ]; then
EPOCH=1
lr=0.001
if [ "${DATASET}" = "imagenet" ]; then
CP="" # use pytorch-provided model
else
CP="--load_checkpoint_path "${CP_base}_${SEED}/cp/cp_last.pth.tar
fi
for dist in 0 1; do
for TGT in $TGTS; do
python main.py --gpu_idx ${GPUS[i % ${NUM_GPUS}]} --dataset $DATASET --method ${METHOD} --tgt ${TGT} --model $MODEL --epoch $EPOCH ${CP} --seed $SEED \
--remove_cp --online --tgt_train_dist ${dist} --update_every_x ${update_every_x} --memory_size ${memory_size} \
--lr ${lr} --weight_decay ${weight_decay} \
--log_prefix ${LOG_PREFIX}_${SEED}_dist${dist} \
${validation} \
2>&1 | tee raw_logs/${DATASET}_${LOG_PREFIX}_${SEED}_job${i}.txt &
i=$((i + 1))
wait_n
done
done
elif [ "${METHOD}" = "TENT" ]; then
EPOCH=1
if [ "${DATASET}" = "imagenet" ]; then
CP="" # use pytorch-provided model
lr=0.00025 #referred to the paper
else
lr=0.001
CP="--load_checkpoint_path "${CP_base}_${SEED}/cp/cp_last.pth.tar
fi
#### Train with BN
for dist in 0 1; do
for TGT in $TGTS; do
python main.py --gpu_idx ${GPUS[i % ${NUM_GPUS}]} --dataset $DATASET --method ${METHOD} --tgt ${TGT} --model $MODEL --epoch $EPOCH ${CP} --seed $SEED \
--remove_cp --online --tgt_train_dist ${dist} --update_every_x ${update_every_x} --memory_size ${memory_size} \
--lr ${lr} --weight_decay ${weight_decay} \
--log_prefix ${LOG_PREFIX}_${SEED}_dist${dist} \
${validation} \
2>&1 | tee raw_logs/${DATASET}_${LOG_PREFIX}_${SEED}_job${i}.txt &
i=$((i + 1))
wait_n
done
done
elif [ "${METHOD}" = "LAME" ]; then
EPOCH=1
#### Train with BN
if [ "${DATASET}" = "imagenet" ]; then
CP="" # use pytorch-provided model
else
CP="--load_checkpoint_path "${CP_base}_${SEED}/cp/cp_last.pth.tar
fi
for dist in 0 1; do
for TGT in $TGTS; do
python main.py --gpu_idx ${GPUS[i % ${NUM_GPUS}]} --dataset $DATASET --method ${METHOD} --tgt ${TGT} --model $MODEL --epoch $EPOCH ${CP} --seed $SEED \
--remove_cp --online --tgt_train_dist ${dist} --update_every_x ${update_every_x} --memory_size ${memory_size} \
--lr ${lr} --weight_decay ${weight_decay} \
--log_prefix ${LOG_PREFIX}_${SEED}_dist${dist} \
${validation} \
2>&1 | tee raw_logs/${DATASET}_${LOG_PREFIX}_${SEED}_job${i}.txt &
i=$((i + 1))
wait_n
done
done
elif [ "${METHOD}" = "CoTTA" ]; then
lr=0.001
EPOCH=1
if [ "${DATASET}" = "cifar10" ]; then
aug_threshold=0.92 #value reported from the official code
elif [ "${DATASET}" = "cifar100" ]; then
aug_threshold=0.72 #value reported from the official code
elif [ "${DATASET}" = "imagenet" ]; then
aug_threshold=0.1 #value reported from the official code
fi
if [ "${DATASET}" = "imagenet" ]; then
CP="" # use pytorch-provided model
else
CP="--load_checkpoint_path "${CP_base}_${SEED}/cp/cp_last.pth.tar
fi
for dist in 0 1; do
for TGT in $TGTS; do
python main.py --gpu_idx ${GPUS[i % ${NUM_GPUS}]} --dataset $DATASET --method ${METHOD} --tgt ${TGT} --model $MODEL --epoch $EPOCH ${CP} --seed $SEED \
--remove_cp --online --tgt_train_dist ${dist} --update_every_x ${update_every_x} --memory_size ${memory_size} \
--lr ${lr} --weight_decay ${weight_decay} \
--aug_threshold ${aug_threshold} \
--log_prefix ${LOG_PREFIX}_${SEED}_dist${dist} \
${validation} \
2>&1 | tee raw_logs/${DATASET}_${LOG_PREFIX}_${SEED}_job${i}.txt &
i=$((i + 1))
wait_n
done
done
fi
done
done
done
wait
}
test_time_adaptation