forked from HRNet/HRFormer
/
run_hrt_small_ocr_v2_ohem.sh
158 lines (137 loc) · 6.37 KB
/
run_hrt_small_ocr_v2_ohem.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
#!/usr/bin/env bash
SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
cd $SCRIPTPATH
cd ../../../
. config.profile
# check the enviroment info
nvidia-smi
${PYTHON} -m pip install yacs
${PYTHON} -m pip install torchcontrib
${PYTHON} -m pip install git+https://github.com/lucasb-eyer/pydensecrf.git
${PYTHON} -m pip install timm
${PYTHON} -m pip install einops
export PYTHONPATH="$PWD":$PYTHONPATH
DATA_DIR="${DATA_ROOT}/cityscapes"
SAVE_DIR="${DATA_ROOT}/seg_result/cityscapes/"
BACKBONE="hrt_small"
CONFIGS="configs/cityscapes/H_48_D_4.json"
CONFIGS_TEST="configs/cityscapes/H_48_D_4_TEST_MS3x.json"
MODEL_NAME="hrt_small_ocr_v2"
LOSS_TYPE="fs_auxohemce_loss"
CHECKPOINTS_NAME="${MODEL_NAME}_${BACKBONE}_ohem_$(date +%F_%H-%M-%S)"
LOG_FILE="./log/cityscapes/${CHECKPOINTS_NAME}.log"
echo "Logging to $LOG_FILE"
mkdir -p `dirname $LOG_FILE`
# AdamW training settings
MAX_ITERS=80000
OPTIM_METHOD='adamw'
BASE_LR=0.0001
LR_POLICY='warm_lambda_poly' # linear warmup
GROUP_METHOD='decay' # no weight decay on norm and pos embed
PRETRAINED_MODEL="./hrt_pretrained_models/hrt_small.pth" # Replace with the path to pre-trained backbone
if [ "$1"x == "train"x ]; then
${PYTHON} -u main.py --configs ${CONFIGS} \
--drop_last y \
--phase train \
--gathered n \
--loss_balance y \
--log_to_file n \
--backbone ${BACKBONE} \
--model_name ${MODEL_NAME} \
--gpu 0 1 2 3 4 5 6 7 \
--data_dir ${DATA_DIR} \
--loss_type ${LOSS_TYPE} \
--max_iters ${MAX_ITERS} \
--checkpoints_name ${CHECKPOINTS_NAME} \
--pretrained ${PRETRAINED_MODEL} \
--optim_method ${OPTIM_METHOD} \
--base_lr ${BASE_LR} \
--lr_policy ${LR_POLICY} \
--group_method ${GROUP_METHOD} \
--train_batch_size 8 \
--distributed \
2>&1 | tee ${LOG_FILE}
elif [ "$1"x == "local"x ]; then
${PYTHON} -u main.py --configs ${CONFIGS} \
--drop_last y \
--phase train \
--gathered n \
--loss_balance y \
--log_to_file n \
--backbone ${BACKBONE} \
--model_name ${MODEL_NAME} \
--gpu 0 1 2 3 \
--data_dir ${DATA_DIR} \
--loss_type ${LOSS_TYPE} \
--max_iters ${MAX_ITERS} \
--checkpoints_name ${CHECKPOINTS_NAME} \
--pretrained ${PRETRAINED_MODEL} \
--optim_method ${OPTIM_METHOD} \
--base_lr ${BASE_LR} \
--lr_policy ${LR_POLICY} \
--group_method ${GROUP_METHOD} \
--train_batch_size 4 \
--distributed \
2>&1 | tee ${LOG_FILE}
elif [ "$1"x == "resume"x ]; then
${PYTHON} -u main.py --configs ${CONFIGS} \
--drop_last y \
--phase train \
--gathered n \
--loss_balance y \
--log_to_file n \
--backbone ${BACKBONE} \
--model_name ${MODEL_NAME} \
--max_iters ${MAX_ITERS} \
--data_dir ${DATA_DIR} \
--loss_type ${LOSS_TYPE} \
--gpu 0 1 2 3 \
--resume_continue y \
--resume ./checkpoints/cityscapes/${CHECKPOINTS_NAME}_latest.pth \
--checkpoints_name ${CHECKPOINTS_NAME} \
2>&1 | tee -a ${LOG_FILE}
elif [ "$1"x == "val"x ]; then
${PYTHON} -u main.py --configs ${CONFIGS_TEST} --drop_last y --data_dir ${DATA_DIR} \
--backbone ${BACKBONE} --model_name ${MODEL_NAME} --checkpoints_name ${CHECKPOINTS_NAME} \
--phase test --gpu 0 1 2 3 4 5 6 7 --resume ./checkpoints/cityscapes/${CHECKPOINTS_NAME}_max_performance.pth \
--loss_type ${LOSS_TYPE} --test_dir ${DATA_DIR}/val/image \
--out_dir ${SAVE_DIR}${CHECKPOINTS_NAME}_val_ms
${PYTHON} lib/metrics/cityscapes/setup.py build_ext --inplace
cd lib/metrics
${PYTHON} -u cityscapes_evaluator.py --pred_dir ../../${SAVE_DIR}${CHECKPOINTS_NAME}_val_ms/label \
--gt_dir ../../${DATA_DIR}/val/label
elif [ "$1"x == "segfix"x ]; then
if [ "$3"x == "test"x ]; then
DIR=${SAVE_DIR}${CHECKPOINTS_NAME}_test_ss/label
echo "Applying SegFix for $DIR"
${PYTHON} scripts/cityscapes/segfix.py \
--input $DIR \
--split test \
--offset ${DATA_ROOT}/cityscapes/test_offset/semantic/offset_hrnext/
elif [ "$3"x == "val"x ]; then
DIR=${SAVE_DIR}${CHECKPOINTS_NAME}_val/label
echo "Applying SegFix for $DIR"
${PYTHON} scripts/cityscapes/segfix.py \
--input $DIR \
--split val \
--offset ${DATA_ROOT}/cityscapes/val/offset_pred/semantic/offset_hrnext/
fi
elif [ "$1"x == "test"x ]; then
if [ "$3"x == "ss"x ]; then
echo "[single scale] test"
${PYTHON} -u main.py --configs ${CONFIGS} --drop_last y \
--backbone ${BACKBONE} --model_name ${MODEL_NAME} --checkpoints_name ${CHECKPOINTS_NAME} \
--phase test --gpu 0 1 2 3 --resume ./checkpoints/cityscapes/${CHECKPOINTS_NAME}_latest.pth \
--test_dir ${DATA_DIR}/test --log_to_file n \
--out_dir ${SAVE_DIR}${CHECKPOINTS_NAME}_test_ss
else
echo "[multiple scale + flip] test"
${PYTHON} -u main.py --configs ${CONFIGS_TEST} --drop_last y \
--backbone ${BACKBONE} --model_name ${MODEL_NAME} --checkpoints_name ${CHECKPOINTS_NAME} \
--phase test --gpu 0 1 2 3 --resume ./checkpoints/cityscapes/${CHECKPOINTS_NAME}_latest.pth \
--test_dir ${DATA_DIR}/test --log_to_file n \
--out_dir ${SAVE_DIR}${CHECKPOINTS_NAME}_test_ms
fi
else
echo "$1"x" is invalid..."
fi