Skip to content

Commit b192374

Browse files
authored
Update hype parameter for DeepLab (#1926) (#1928)
* fix some hyper parameters * Update README
1 parent dc76c32 commit b192374

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

fluid/PaddleCV/deeplabv3+/.gitignore

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
deeplabv3plus_xception65_initialize.params
2-
deeplabv3plus.params
3-
deeplabv3plus.tar.gz
1+
*.tgz
2+
deeplabv3plus_gn_init*
3+
deeplabv3plus_xception65_initialize*
4+
*.log
5+
*.sh
6+
output*

fluid/PaddleCV/deeplabv3+/README.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,19 @@ python train.py --help
7272
以上命令用于测试训练过程是否正常,仅仅迭代了50次并且使用了1的batch size,如果需要复现
7373
原论文的实验,请使用以下设置:
7474
```
75+
CUDA_VISIBLE_DEVICES=0 \
7576
python ./train.py \
76-
--batch_size=8 \
77+
--batch_size=4 \
7778
--parallel=True \
7879
--norm_type=gn \
7980
--train_crop_size=769 \
80-
--total_step=90000 \
81+
--total_step=500000 \
8182
--base_lr=0.001 \
8283
--init_weights_path=deeplabv3plus_gn_init \
8384
--save_weights_path=output \
8485
--dataset_path=$DATASET_PATH
8586
```
86-
如果您的显存不足,可以尝试减小`batch_size`,同时等比例放大`total_step`, 保证相乘的值不变,这得益于Group Norm的特性,改变 `batch_size` 并不会显著影响结果,而且能够节约更多显存, 比如您可以设置`--batch_size=4 --total_step=180000`
87-
88-
如果您希望使用多卡进行训练,可以同比增加`batch_size`,减小`total_step`, 比如原来单卡训练是`--batch_size=4 --total_step=180000`,使用4卡训练则是`--batch_size=16 --total_step=45000`
87+
如果您的显存不足,可以尝试减小`batch_size`,同时等比例放大`total_step`, 缩小`base_lr`, 保证相乘的值不变,这得益于Group Norm的特性,改变 `batch_size` 并不会显著影响结果,而且能够节约更多显存, 比如您可以设置`--batch_size=2 --total_step=1000000 --base_lr=0.0005`
8988

9089
### 测试
9190
执行以下命令在`Cityscape`测试数据集上进行测试:
@@ -110,7 +109,6 @@ step: 500, mIoU: 0.7881
110109

111110
|数据集 | norm type | pretrained model | trained model | mean IoU
112111
|---|---|---|---|---|
113-
|CityScape | batch norm | [deeplabv3plus_xception65_initialize.tgz](https://paddle-deeplab.bj.bcebos.com/deeplabv3plus_xception65_initialize.tgz) | [deeplabv3plus.tgz](https://paddle-deeplab.bj.bcebos.com/deeplabv3plus.tgz) | 0.7873 |
114112
|CityScape | group norm | [deeplabv3plus_gn_init.tgz](https://paddle-deeplab.bj.bcebos.com/deeplabv3plus_gn_init.tgz) | [deeplabv3plus_gn.tgz](https://paddle-deeplab.bj.bcebos.com/deeplabv3plus_gn.tgz) | 0.7881 |
115113

116114
## 参考

fluid/PaddleCV/deeplabv3+/eval.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,4 @@ def load_model():
137137
all_correct = right.copy()
138138
mp = (wrong + right) != 0
139139
miou2 = np.mean((right[mp] * 1.0 / (right[mp] + wrong[mp])))
140-
if args.verbose:
141-
print('step: %s, mIoU: %s' % (i + 1, miou2), flush=True)
142-
else:
143-
print('\rstep: %s, mIoU: %s' % (i + 1, miou2), end='\r', flush=True)
140+
print('step: %s, mIoU: %s' % (i + 1, miou2))

fluid/PaddleCV/deeplabv3+/reader.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
default_config = {
1010
"shuffle": True,
1111
"min_resize": 0.5,
12-
"max_resize": 2,
12+
"max_resize": 4,
1313
"crop_size": 769,
1414
}
1515

@@ -90,9 +90,21 @@ def get_img(self):
9090
break
9191
if shape == -1:
9292
return img, label, ln
93-
random_scale = np.random.rand(1) * (self.config['max_resize'] -
94-
self.config['min_resize']
95-
) + self.config['min_resize']
93+
94+
if np.random.rand() > 0.5:
95+
range_l = 1
96+
range_r = self.config['max_resize']
97+
else:
98+
range_l = self.config['min_resize']
99+
range_r = 1
100+
101+
if np.random.rand() > 0.5:
102+
assert len(img.shape) == 3 and len(
103+
label.shape) == 3, "{} {}".format(img.shape, label.shape)
104+
img = img[:, :, ::-1]
105+
label = label[:, :, ::-1]
106+
107+
random_scale = np.random.rand(1) * (range_r - range_l) + range_l
96108
crop_size = int(shape / random_scale)
97109
bb = crop_size // 2
98110

fluid/PaddleCV/deeplabv3+/train.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
add_arg = lambda *args: utility.add_arguments(*args, argparser=parser)
2222

2323
# yapf: disable
24-
add_arg('batch_size', int, 2, "The number of images in each batch during training.")
24+
add_arg('batch_size', int, 4, "The number of images in each batch during training.")
2525
add_arg('train_crop_size', int, 769, "Image crop size during training.")
26-
add_arg('base_lr', float, 0.0001, "The base learning rate for model training.")
27-
add_arg('total_step', int, 90000, "Number of the training step.")
26+
add_arg('base_lr', float, 0.001, "The base learning rate for model training.")
27+
add_arg('total_step', int, 500000, "Number of the training step.")
2828
add_arg('init_weights_path', str, None, "Path of the initial weights in paddlepaddle format.")
2929
add_arg('save_weights_path', str, None, "Path of the saved weights during training.")
3030
add_arg('dataset_path', str, None, "Cityscape dataset path.")
@@ -39,7 +39,7 @@
3939
parser.add_argument(
4040
'--enable_ce',
4141
action='store_true',
42-
help='If set, run the task with continuous evaluation logs.')
42+
help='If set, run the task with continuous evaluation logs. Users can ignore this agument.')
4343
#yapf: enable
4444

4545
@contextlib.contextmanager
@@ -87,7 +87,8 @@ def loss(logit, label):
8787
label = fluid.layers.reshape(label, [-1, 1])
8888
label = fluid.layers.cast(label, 'int64')
8989
label_nignore = fluid.layers.reshape(label_nignore, [-1, 1])
90-
loss = fluid.layers.softmax_with_cross_entropy(logit, label, ignore_index=255, numeric_stable_mode=True)
90+
logit = fluid.layers.softmax(logit, use_cudnn=False)
91+
loss = fluid.layers.cross_entropy(logit, label, ignore_index=255)
9192
label_nignore.stop_gradient = True
9293
label.stop_gradient = True
9394
return loss, label_nignore

0 commit comments

Comments
 (0)