From 4c6070a7c3925ebb82a709e3148356aa4963be7a Mon Sep 17 00:00:00 2001 From: johnzja Date: Fri, 21 Aug 2020 22:32:34 +0800 Subject: [PATCH 1/4] Fix fast_scnn resize problems --- mmseg/__init__.py | 2 +- mmseg/models/backbones/fast_scnn.py | 13 +------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/mmseg/__init__.py b/mmseg/__init__.py index 11376951e9..abaee58890 100644 --- a/mmseg/__init__.py +++ b/mmseg/__init__.py @@ -3,7 +3,7 @@ from .version import __version__, version_info MMCV_MIN = '1.0.5' -MMCV_MAX = '1.0.5' +MMCV_MAX = '1.1.0' def digit_version(version_str): diff --git a/mmseg/models/backbones/fast_scnn.py b/mmseg/models/backbones/fast_scnn.py index d94f52cb7f..dcb24214dd 100644 --- a/mmseg/models/backbones/fast_scnn.py +++ b/mmseg/models/backbones/fast_scnn.py @@ -186,9 +186,6 @@ class FeatureFusionModule(nn.Module): lower_in_channels (int): Number of input channels of the lower-resolution branch. out_channels (int): Number of output channels. - scale_factor (int): Scale factor applied to the lower-res input. - Should be coherent with the downsampling factor determined - by the GFE module. conv_cfg (dict | None): Config of conv layers. Default: None norm_cfg (dict | None): Config of norm layers. Default: dict(type='BN') @@ -202,13 +199,11 @@ def __init__(self, higher_in_channels, lower_in_channels, out_channels, - scale_factor, conv_cfg=None, norm_cfg=dict(type='BN'), act_cfg=dict(type='ReLU'), align_corners=False): super(FeatureFusionModule, self).__init__() - self.scale_factor = scale_factor self.conv_cfg = conv_cfg self.norm_cfg = norm_cfg self.act_cfg = act_cfg @@ -239,7 +234,7 @@ def __init__(self, def forward(self, higher_res_feature, lower_res_feature): lower_res_feature = resize( lower_res_feature, - scale_factor=self.scale_factor, + size=higher_res_feature.size()[2:], mode='bilinear', align_corners=self.align_corners) lower_res_feature = self.dwconv(lower_res_feature) @@ -321,11 +316,6 @@ def __init__(self, raise AssertionError('Global Output Channels must be the same \ with Lower Input Channels!') - # Calculate scale factor used in FFM. - self.scale_factor = 1 - for factor in global_block_strides: - self.scale_factor *= factor - self.in_channels = in_channels self.downsample_dw_channels1 = downsample_dw_channels[0] self.downsample_dw_channels2 = downsample_dw_channels[1] @@ -361,7 +351,6 @@ def __init__(self, higher_in_channels, lower_in_channels, fusion_out_channels, - scale_factor=self.scale_factor, conv_cfg=self.conv_cfg, norm_cfg=self.norm_cfg, act_cfg=self.act_cfg, From fcb86ee9994da9865fecd2e35169324d01810144 Mon Sep 17 00:00:00 2001 From: johnzja Date: Fri, 21 Aug 2020 22:35:27 +0800 Subject: [PATCH 2/4] Fix fast_scnn resize problems 1 --- configs/fastscnn/fast_scnn_4x8_80k_lr0.12_ade.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 configs/fastscnn/fast_scnn_4x8_80k_lr0.12_ade.py diff --git a/configs/fastscnn/fast_scnn_4x8_80k_lr0.12_ade.py b/configs/fastscnn/fast_scnn_4x8_80k_lr0.12_ade.py new file mode 100644 index 0000000000..cc7a4b74b2 --- /dev/null +++ b/configs/fastscnn/fast_scnn_4x8_80k_lr0.12_ade.py @@ -0,0 +1,10 @@ +_base_ = [ + '../_base_/models/fast_scnn.py', '../_base_/datasets/ade20k.py', + '../_base_/default_runtime.py', '../_base_/schedules/schedule_80k.py' +] + +# Re-config the data sampler. +data = dict(samples_per_gpu=8, workers_per_gpu=4) + +# Re-config the optimizer. +optimizer = dict(type='SGD', lr=0.12, momentum=0.9, weight_decay=4e-5) From 2abd2eb68b8cdd2b6c5d93f8f2a92d3aa4b32769 Mon Sep 17 00:00:00 2001 From: johnzja Date: Fri, 21 Aug 2020 22:46:38 +0800 Subject: [PATCH 3/4] Fix fast_scnn resize problems 2 --- ...4x8_80k_lr0.12_ade.py => fast_scnn_4x8_80k_lr0.12_pascal.py} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename configs/fastscnn/{fast_scnn_4x8_80k_lr0.12_ade.py => fast_scnn_4x8_80k_lr0.12_pascal.py} (78%) diff --git a/configs/fastscnn/fast_scnn_4x8_80k_lr0.12_ade.py b/configs/fastscnn/fast_scnn_4x8_80k_lr0.12_pascal.py similarity index 78% rename from configs/fastscnn/fast_scnn_4x8_80k_lr0.12_ade.py rename to configs/fastscnn/fast_scnn_4x8_80k_lr0.12_pascal.py index cc7a4b74b2..6f7129fac8 100644 --- a/configs/fastscnn/fast_scnn_4x8_80k_lr0.12_ade.py +++ b/configs/fastscnn/fast_scnn_4x8_80k_lr0.12_pascal.py @@ -1,5 +1,5 @@ _base_ = [ - '../_base_/models/fast_scnn.py', '../_base_/datasets/ade20k.py', + '../_base_/models/fast_scnn.py', '../_base_/datasets/pascal_voc12.py', '../_base_/default_runtime.py', '../_base_/schedules/schedule_80k.py' ] From c13d9f7160ac1b23e16bccf79a500c039edf5534 Mon Sep 17 00:00:00 2001 From: johnzja Date: Sat, 22 Aug 2020 16:01:28 +0800 Subject: [PATCH 4/4] test for pascal voc --- .../fast_scnn_4x8_80k_lr0.12_pascal.py | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/configs/fastscnn/fast_scnn_4x8_80k_lr0.12_pascal.py b/configs/fastscnn/fast_scnn_4x8_80k_lr0.12_pascal.py index 6f7129fac8..23c2ea996d 100644 --- a/configs/fastscnn/fast_scnn_4x8_80k_lr0.12_pascal.py +++ b/configs/fastscnn/fast_scnn_4x8_80k_lr0.12_pascal.py @@ -8,3 +8,63 @@ # Re-config the optimizer. optimizer = dict(type='SGD', lr=0.12, momentum=0.9, weight_decay=4e-5) + +# update num_classes of the segmentor. +# model settings +norm_cfg = dict(type='SyncBN', requires_grad=True, momentum=0.01) +model = dict( + type='EncoderDecoder', + backbone=dict( + type='FastSCNN', + downsample_dw_channels=(32, 48), + global_in_channels=64, + global_block_channels=(64, 96, 128), + global_block_strides=(2, 2, 1), + global_out_channels=128, + higher_in_channels=64, + lower_in_channels=128, + fusion_out_channels=128, + out_indices=(0, 1, 2), + norm_cfg=norm_cfg, + align_corners=False), + decode_head=dict( + type='DepthwiseSeparableFCNHead', + in_channels=128, + channels=128, + concat_input=False, + num_classes=21, + in_index=-1, + norm_cfg=norm_cfg, + align_corners=False, + loss_decode=dict( + type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.)), + auxiliary_head=[ + dict( + type='FCNHead', + in_channels=128, + channels=32, + num_convs=1, + num_classes=21, + in_index=-2, + norm_cfg=norm_cfg, + concat_input=False, + align_corners=False, + loss_decode=dict( + type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), + dict( + type='FCNHead', + in_channels=64, + channels=32, + num_convs=1, + num_classes=21, + in_index=-3, + norm_cfg=norm_cfg, + concat_input=False, + align_corners=False, + loss_decode=dict( + type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), + ]) + +# model training and testing settings +train_cfg = dict() +test_cfg = dict(mode='whole')