Skip to content

Commit e951076

Browse files
authored
Fix fastscnn resize problems. (open-mmlab#82)
* Fix fast_scnn resize problems * Fix fast_scnn resize problems 1 * Fix fast_scnn resize problems 2 * test for pascal voc
1 parent 3e49d0a commit e951076

File tree

3 files changed

+72
-13
lines changed

3 files changed

+72
-13
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
_base_ = [
2+
'../_base_/models/fast_scnn.py', '../_base_/datasets/pascal_voc12.py',
3+
'../_base_/default_runtime.py', '../_base_/schedules/schedule_80k.py'
4+
]
5+
6+
# Re-config the data sampler.
7+
data = dict(samples_per_gpu=8, workers_per_gpu=4)
8+
9+
# Re-config the optimizer.
10+
optimizer = dict(type='SGD', lr=0.12, momentum=0.9, weight_decay=4e-5)
11+
12+
# update num_classes of the segmentor.
13+
# model settings
14+
norm_cfg = dict(type='SyncBN', requires_grad=True, momentum=0.01)
15+
model = dict(
16+
type='EncoderDecoder',
17+
backbone=dict(
18+
type='FastSCNN',
19+
downsample_dw_channels=(32, 48),
20+
global_in_channels=64,
21+
global_block_channels=(64, 96, 128),
22+
global_block_strides=(2, 2, 1),
23+
global_out_channels=128,
24+
higher_in_channels=64,
25+
lower_in_channels=128,
26+
fusion_out_channels=128,
27+
out_indices=(0, 1, 2),
28+
norm_cfg=norm_cfg,
29+
align_corners=False),
30+
decode_head=dict(
31+
type='DepthwiseSeparableFCNHead',
32+
in_channels=128,
33+
channels=128,
34+
concat_input=False,
35+
num_classes=21,
36+
in_index=-1,
37+
norm_cfg=norm_cfg,
38+
align_corners=False,
39+
loss_decode=dict(
40+
type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.)),
41+
auxiliary_head=[
42+
dict(
43+
type='FCNHead',
44+
in_channels=128,
45+
channels=32,
46+
num_convs=1,
47+
num_classes=21,
48+
in_index=-2,
49+
norm_cfg=norm_cfg,
50+
concat_input=False,
51+
align_corners=False,
52+
loss_decode=dict(
53+
type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)),
54+
dict(
55+
type='FCNHead',
56+
in_channels=64,
57+
channels=32,
58+
num_convs=1,
59+
num_classes=21,
60+
in_index=-3,
61+
norm_cfg=norm_cfg,
62+
concat_input=False,
63+
align_corners=False,
64+
loss_decode=dict(
65+
type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)),
66+
])
67+
68+
# model training and testing settings
69+
train_cfg = dict()
70+
test_cfg = dict(mode='whole')

mmseg/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .version import __version__, version_info
44

55
MMCV_MIN = '1.0.5'
6-
MMCV_MAX = '1.0.5'
6+
MMCV_MAX = '1.1.0'
77

88

99
def digit_version(version_str):

mmseg/models/backbones/fast_scnn.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,6 @@ class FeatureFusionModule(nn.Module):
186186
lower_in_channels (int): Number of input channels of the
187187
lower-resolution branch.
188188
out_channels (int): Number of output channels.
189-
scale_factor (int): Scale factor applied to the lower-res input.
190-
Should be coherent with the downsampling factor determined
191-
by the GFE module.
192189
conv_cfg (dict | None): Config of conv layers. Default: None
193190
norm_cfg (dict | None): Config of norm layers. Default:
194191
dict(type='BN')
@@ -202,13 +199,11 @@ def __init__(self,
202199
higher_in_channels,
203200
lower_in_channels,
204201
out_channels,
205-
scale_factor,
206202
conv_cfg=None,
207203
norm_cfg=dict(type='BN'),
208204
act_cfg=dict(type='ReLU'),
209205
align_corners=False):
210206
super(FeatureFusionModule, self).__init__()
211-
self.scale_factor = scale_factor
212207
self.conv_cfg = conv_cfg
213208
self.norm_cfg = norm_cfg
214209
self.act_cfg = act_cfg
@@ -239,7 +234,7 @@ def __init__(self,
239234
def forward(self, higher_res_feature, lower_res_feature):
240235
lower_res_feature = resize(
241236
lower_res_feature,
242-
scale_factor=self.scale_factor,
237+
size=higher_res_feature.size()[2:],
243238
mode='bilinear',
244239
align_corners=self.align_corners)
245240
lower_res_feature = self.dwconv(lower_res_feature)
@@ -321,11 +316,6 @@ def __init__(self,
321316
raise AssertionError('Global Output Channels must be the same \
322317
with Lower Input Channels!')
323318

324-
# Calculate scale factor used in FFM.
325-
self.scale_factor = 1
326-
for factor in global_block_strides:
327-
self.scale_factor *= factor
328-
329319
self.in_channels = in_channels
330320
self.downsample_dw_channels1 = downsample_dw_channels[0]
331321
self.downsample_dw_channels2 = downsample_dw_channels[1]
@@ -361,7 +351,6 @@ def __init__(self,
361351
higher_in_channels,
362352
lower_in_channels,
363353
fusion_out_channels,
364-
scale_factor=self.scale_factor,
365354
conv_cfg=self.conv_cfg,
366355
norm_cfg=self.norm_cfg,
367356
act_cfg=self.act_cfg,

0 commit comments

Comments
 (0)