-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackbone.sh
executable file
·179 lines (154 loc) · 3.49 KB
/
backbone.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
#!/bin/bash
set -e
GPUID1=0
export CUDA_VISIBLE_DEVICES=$GPUID1
MODE=$1
if [ $MODE != "validation" ] && [ $MODE != "training" ]
then
echo "mode must be either validation or training"
exit 1
fi
# get modality as arg
MODALITY=$2
# make sure modality is either ct or mri
if [ $MODALITY != "ct" ] && [ $MODALITY != "mri" ]
then
echo "modality must be either ct or mri"
exit 1
fi
####### Shared configs ######
PROTO_GRID=8 # using 32 / 8 = 4, 4-by-4 prototype pooling window during training
INPUT_SIZE=256
ALL_EV=( 0 ) # 5-fold cross validation (0, 1, 2, 3, 4)
if [ $MODALITY == "ct" ]
then
DATASET='SABS_Superpix'
else
DATASET='CHAOST2_Superpix'
fi
if [ $INPUT_SIZE -gt 256 ]
then
DATASET=${DATASET}'_672'
fi
NWORKER=4
MODEL_NAME='dinov2_l14'
LORA=0
RELOAD_PATH=( "None" )
SKIP_SLICES="True"
DO_CCA="True"
TTT="False"
NSTEP=100000
RESET_AFTER_SLICE="True"
FINETUNE_ON_SUPPORT="False"
USE_SLICE_ADAPTER="False"
ADAPTER_LAYERS=1
CLAHE=False
ALL_SCALE=( "MIDDLE") # config of pseudolabels
LABEL_SETS=$3
EXCLU='[2,3]'
if [[ $MODALITY == "mri" && $LABEL_SETS -eq 1 ]]
then
echo "exluding 1, 4"
EXCLU='[1,4]' # liver(1), spleen(4)
fi
ORGANS='kidneys'
if [ $LABEL_SETS -eq 1 ]
then
ORGANS='liver_spleen'
fi
FREE_DESC=""
CPT="${MODE}_${MODEL_NAME}_${MODALITY}"
if [ -n "$FREE_DESC" ]
then
CPT="${CPT}_${FREE_DESC}"
fi
if [[ $TTT == "True" ]]
then
CPT="${CPT}_ttt_nstep_${NSTEP}"
if [ $RESET_AFTER_SLICE == "True" ]
then
CPT="${CPT}_reset_after_slice"
fi
fi
if [ $USE_SLICE_ADAPTER == "True" ]
then
CPT="${CPT}_w_adapter_${ADAPTER_LAYERS}_layers"
fi
if [ $LORA -ne 0 ]
then
CPT="${CPT}_lora_${LORA}"
fi
if [ $CLAHE == "True" ]
then
CPT="${CPT}_w_clahe"
fi
if [ $DO_CCA = "True" ]
then
CPT="${CPT}_cca"
fi
CPT="${CPT}_grid_${PROTO_GRID}_res_${INPUT_SIZE}"
if [ ${EXCLU} = "[]" ]
then
CPT="${CPT}_setting1"
else
CPT="${CPT}_setting2"
fi
CPT="${CPT}_${ORGANS}_fold"
###### Training configs (irrelavent in testing) ######
DECAY=0.95
MAX_ITER=1000 # defines the size of an epoch
SNAPSHOT_INTERVAL=25000 # interval for saving snapshot
SEED='1234'
###### Validation configs ######
SUPP_ID='[6]' # using the additionally loaded scan as support
if [ $MODALITY == "mri" ]
then
SUPP_ID='[4]'
fi
echo ===================================
for ((i=0; i<${#ALL_EV[@]}; i++))
do
EVAL_FOLD=${ALL_EV[i]}
CPT_W_FOLD="${CPT}_${EVAL_FOLD}"
echo $CPT_W_FOLD on GPU $GPUID1
for SUPERPIX_SCALE in "${ALL_SCALE[@]}"
do
PREFIX="test_vfold${EVAL_FOLD}"
echo $PREFIX
LOGDIR="./test_${MODALITY}/${CPT_W_FOLD}"
if [ ! -d $LOGDIR ]
then
mkdir -p $LOGDIR
fi
python3 $MODE.py with \
"modelname=$MODEL_NAME" \
'usealign=True' \
'optim_type=sgd' \
reload_model_path=${RELOAD_PATH[i]} \
num_workers=$NWORKER \
scan_per_load=-1 \
label_sets=$LABEL_SETS \
'use_wce=True' \
exp_prefix=$PREFIX \
'clsname=grid_proto' \
n_steps=$NSTEP \
exclude_cls_list=$EXCLU \
eval_fold=$EVAL_FOLD \
dataset=$DATASET \
proto_grid_size=$PROTO_GRID \
max_iters_per_load=$MAX_ITER \
min_fg_data=1 seed=$SEED \
save_snapshot_every=$SNAPSHOT_INTERVAL \
superpix_scale=$SUPERPIX_SCALE \
lr_step_gamma=$DECAY \
path.log_dir=$LOGDIR \
support_idx=$SUPP_ID \
lora=$LORA \
do_cca=$DO_CCA \
ttt=$TTT \
adapter_layers=$ADAPTER_LAYERS \
use_slice_adapter=$USE_SLICE_ADAPTER \
reset_after_slice=$RESET_AFTER_SLICE \
"input_size=($INPUT_SIZE, $INPUT_SIZE)"
done
done