-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_pascal_weak.sh
216 lines (166 loc) · 7.02 KB
/
run_pascal_weak.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
#!/usr/bin/env sh
# Modified version from https://bitbucket.org/deeplab/deeplab-public using weak annotations
# Martin Kersner, m.kersner@gmail.com
# 2016/04/07
CAFFE_BIN=code/.build_release/tools/caffe.bin
EXP=exper/voc12
DATA_ROOT=exper/voc12/data
GPU_ID=0
# Specify number of classes
NUM_LABELS=21 # all classes
#NUM_LABELS=4 # 3 classes + 1 background
LIST_SUFFIX= # all classes
#LIST_SUFFIX=_subset # only for limited number of classes
# Specify which dataset use for training
#TRAIN_SET_SUFFIX= # original PASCAL VOC 2012 dataset
#TRAIN_SET_SUFFIX=_aug # augmented PASCAL VOC dataset
TRAIN_SET_SUFFIX=_bbox # weak labels consisting of only bounding boxes
#TRAIN_SET_SUFFIX=_bboxcrf # weak labels consisting of bounding boxes processed by DenseCRF
#TRAIN_SET_STRONG=train
TRAIN_SET_STRONG=train200
#TRAIN_SET_STRONG=train500
#TRAIN_SET_STRONG=train750
#TRAIN_SET_STRONG=train1000
TRAIN_SET_WEAK_LEN=5000
# Specify which model to train
NET_ID=DeepLab-LargeFOV-Semi-Bbox-Fixed
# Run
RUN_TRAIN=1
RUN_TEST=0
RUN_TRAIN2=1
RUN_TEST2=0
# Create directories ###########################################################
CONFIG_DIR=${EXP}/config/${NET_ID}
MODEL_DIR=${EXP}/model/${NET_ID}
LOG_DIR=${EXP}/log/${NET_ID}
for DIR in $CONFIG_DIR $MODEL_DIR $LOG_DIR; do
mkdir -p ${DIR}
done
export GLOG_log_dir=${LOG_DIR}
# Training #1 (on train_aug) ###################################################
if [ ${RUN_TRAIN} -eq 1 ]; then
LIST_DIR=${EXP}/list${LIST_SUFFIX}
TRAIN_SET=train${TRAIN_SET_SUFFIX}
TMPFILE_WEAK=$(mktemp /tmp/run_pascal_weak.XXXXXX)
exec 3>"$TMPFILE_WEAK"
rm "$TMPFILE_WEAK"
TMPFILE_STRONG=$(mktemp /tmp/run_pascal_weak.XXXXXX)
exec 3>"$TMPFILE_STRONG"
rm "$TMPFILE_STRONG"
TMPFILE_CMP=$(mktemp /tmp/run_pascal_weak.XXXXXX)
exec 3>"$TMPFILE_CMP"
rm "$TMPFILE_CMP"
grep -o "[0-9]*_[0-9]*.png" ${LIST_DIR}/${TRAIN_SET}.txt | sort > "$TMPFILE_WEAK"
grep -o "[0-9]*_[0-9]*.png" ${LIST_DIR}/${TRAIN_SET_STRONG}.txt | sort > "$TMPFILE_STRONG"
if [ -z ${TRAIN_SET_WEAK_LEN} ]; then
TRAIN_SET_WEAK_BBOX=${TRAIN_SET}_diff_${TRAIN_SET_STRONG}
cat ${LIST_DIR}/${TRAIN_SET_STRONG}.txt > ${LIST_DIR}/${TRAIN_SET_WEAK_BBOX}.txt
comm -3 "$TMPFILE_WEAK" "$TMPFILE_STRONG" | sort > "$TMPFILE_CMP"
grep -f "$TMPFILE_CMP" ${LIST_DIR}/${TRAIN_SET}.txt >> ${LIST_DIR}/${TRAIN_SET_WEAK_BBOX}.txt
else
TRAIN_SET_WEAK_BBOX=${TRAIN_SET}_diff_${TRAIN_SET_STRONG}_head${TRAIN_SET_WEAK_LEN}
cat ${LIST_DIR}/${TRAIN_SET_STRONG}.txt > ${LIST_DIR}/${TRAIN_SET_WEAK_BBOX}.txt
comm -3 "$TMPFILE_WEAK" "$TMPFILE_STRONG" | head -n ${TRAIN_SET_WEAK_LEN} | sort > "$TMPFILE_CMP"
./fast_grep ${TMPFILE_CMP} ${LIST_DIR}/${TRAIN_SET}.txt >> ${LIST_DIR}/${TRAIN_SET_WEAK_BBOX}.txt
#grep -f ${TMPFILE_CMP} ${LIST_DIR}/${TRAIN_SET}.txt >> ${LIST_DIR}/${TRAIN_SET_WEAK_BBOX}.txt
fi
MODEL=${EXP}/model/${NET_ID}/init.caffemodel
echo "Training net ${EXP}/${NET_ID}"
for pname in train solver; do
sed "$(eval echo $(cat sub.sed))" \
${CONFIG_DIR}/${pname}.prototxt > ${CONFIG_DIR}/${pname}_${TRAIN_SET}.prototxt
done
CMD="${CAFFE_BIN} train \
--solver=${CONFIG_DIR}/solver_${TRAIN_SET}.prototxt \
--gpu=${GPU_ID}"
if [ -f ${MODEL} ]; then
CMD="${CMD} --weights=${MODEL}"
fi
echo Running ${CMD} && ${CMD}
fi
# Test #1 specification (on val or test) #######################################
if [ ${RUN_TEST} -eq 1 ]; then
for TEST_SET in val; do
TEST_ITER=`cat exper/voc12/list${LIST_SUFFIX}/${TEST_SET}.txt | wc -l`
MODEL=${EXP}/model/${NET_ID}/test.caffemodel
if [ ! -f ${MODEL} ]; then
MODEL=`ls -t ${EXP}/model/${NET_ID}/train_iter_*.caffemodel | head -n 1`
fi
echo "Testing net ${EXP}/${NET_ID}"
FEATURE_DIR=${EXP}/features/${NET_ID}
mkdir -p ${FEATURE_DIR}/${TEST_SET}/fc8
mkdir -p ${FEATURE_DIR}/${TEST_SET}/crf
sed "$(eval echo $(cat sub.sed))" \
${CONFIG_DIR}/test.prototxt > ${CONFIG_DIR}/test_${TEST_SET}.prototxt
CMD="${CAFFE_BIN} test \
--model=${CONFIG_DIR}/test_${TEST_SET}.prototxt \
--weights=${MODEL} \
--gpu=${GPU_ID} \
--iterations=${TEST_ITER}"
echo Running ${CMD} && ${CMD}
done
fi
# Training #2 (finetune on trainval_aug) #######################################
if [ ${RUN_TRAIN2} -eq 1 ]; then
LIST_DIR=${EXP}/list${LIST_SUFFIX}
TRAIN_SET=trainval${TRAIN_SET_SUFFIX}
TMPFILE_WEAK=$(mktemp /tmp/run_pascal_weak.XXXXXX)
exec 3>"$TMPFILE_WEAK"
rm "$TMPFILE_WEAK"
TMPFILE_STRONG=$(mktemp /tmp/run_pascal_weak.XXXXXX)
exec 3>"$TMPFILE_STRONG"
rm "$TMPFILE_STRONG"
TMPFILE_CMP=$(mktemp /tmp/run_pascal_weak.XXXXXX)
exec 3>"$TMPFILE_CMP"
rm "$TMPFILE_CMP"
grep -o "[0-9]*_[0-9]*.png" ${LIST_DIR}/${TRAIN_SET}.txt | sort > "$TMPFILE_WEAK"
grep -o "[0-9]*_[0-9]*.png" ${LIST_DIR}/${TRAIN_SET_STRONG}.txt | sort > "$TMPFILE_STRONG"
if [ -z ${TRAIN_SET_WEAK_LEN} ]; then
TRAIN_SET_WEAK_BBOX=${TRAIN_SET}_diff_${TRAIN_SET_STRONG}
cat ${LIST_DIR}/${TRAIN_SET_STRONG}.txt > ${LIST_DIR}/${TRAIN_SET_WEAK_BBOX}.txt
comm -3 "$TMPFILE_WEAK" "$TMPFILE_STRONG" | sort > "$TMPFILE_CMP"
grep -f "$TMPFILE_CMP" ${LIST_DIR}/${TRAIN_SET}.txt >> ${LIST_DIR}/${TRAIN_SET_WEAK_BBOX}.txt
else
TRAIN_SET_WEAK_BBOX=${TRAIN_SET}_diff_${TRAIN_SET_STRONG}_head${TRAIN_SET_WEAK_LEN}
cat ${LIST_DIR}/${TRAIN_SET_STRONG}.txt > ${LIST_DIR}/${TRAIN_SET_WEAK_BBOX}.txt
comm -3 "$TMPFILE_WEAK" "$TMPFILE_STRONG" | head -n ${TRAIN_SET_WEAK_LEN} | sort > "$TMPFILE_CMP"
./fast_grep ${TMPFILE_CMP} ${LIST_DIR}/${TRAIN_SET}.txt >> ${LIST_DIR}/${TRAIN_SET_WEAK_BBOX}.txt
#grep -f ${TMPFILE_CMP} ${LIST_DIR}/${TRAIN_SET}.txt >> ${LIST_DIR}/${TRAIN_SET_WEAK_BBOX}.txt
fi
MODEL=${EXP}/model/${NET_ID}/init2.caffemodel
if [ ! -f ${MODEL} ]; then
MODEL=`ls -t ${EXP}/model/${NET_ID}/train_iter_*.caffemodel | head -n 1`
fi
echo "Training2 net ${EXP}/${NET_ID}"
for pname in train solver2; do
sed "$(eval echo $(cat sub.sed))" \
${CONFIG_DIR}/${pname}.prototxt > ${CONFIG_DIR}/${pname}_${TRAIN_SET}.prototxt
done
CMD="${CAFFE_BIN} train \
--solver=${CONFIG_DIR}/solver2_${TRAIN_SET}.prototxt \
--weights=${MODEL} \
--gpu=${GPU_ID}"
echo Running ${CMD} && ${CMD}
fi
# Test #2 on official test set #################################################
if [ ${RUN_TEST2} -eq 1 ]; then
for TEST_SET in val; do
TEST_ITER=`cat exper/voc12/list${LIST_SUFFIX}/${TEST_SET}.txt | wc -l`
MODEL=${EXP}/model/${NET_ID}/test2.caffemodel
if [ ! -f ${MODEL} ]; then
MODEL=`ls -t ${EXP}/model/${NET_ID}/train2_iter_*.caffemodel | head -n 1`
fi
echo "Testing2 net ${EXP}/${NET_ID}"
FEATURE_DIR=${EXP}/features2/${NET_ID}
mkdir -p ${FEATURE_DIR}/${TEST_SET}/fc8
mkdir -p ${FEATURE_DIR}/${TEST_SET}/crf
sed "$(eval echo $(cat sub.sed))" \
${CONFIG_DIR}/test.prototxt > ${CONFIG_DIR}/test_${TEST_SET}.prototxt
CMD="${CAFFE_BIN} test \
--model=${CONFIG_DIR}/test_${TEST_SET}.prototxt \
--weights=${MODEL} \
--gpu=${GPU_ID} \
--iterations=${TEST_ITER}"
echo Running ${CMD} && ${CMD}
done
fi