Basic convolutional block for UNet. This module consists of several plain convolutional layers. Args: in_channels (int): Number of input channels. out_channels (int): Number of output channels. num_convs (int): Number of convolutional layers. Default: 2. str
| 14 | |
| 15 | |
| 16 | class BasicConvBlock(nn.Module): |
| 17 | """Basic convolutional block for UNet. |
| 18 | |
| 19 | This module consists of several plain convolutional layers. |
| 20 | |
| 21 | Args: |
| 22 | in_channels (int): Number of input channels. |
| 23 | out_channels (int): Number of output channels. |
| 24 | num_convs (int): Number of convolutional layers. Default: 2. |
| 25 | stride (int): Whether use stride convolution to downsample |
| 26 | the input feature map. If stride=2, it only uses stride convolution |
| 27 | in the first convolutional layer to downsample the input feature |
| 28 | map. Options are 1 or 2. Default: 1. |
| 29 | dilation (int): Whether use dilated convolution to expand the |
| 30 | receptive field. Set dilation rate of each convolutional layer and |
| 31 | the dilation rate of the first convolutional layer is always 1. |
| 32 | Default: 1. |
| 33 | with_cp (bool): Use checkpoint or not. Using checkpoint will save some |
| 34 | memory while slowing down the training speed. Default: False. |
| 35 | conv_cfg (dict | None): Config dict for convolution layer. |
| 36 | Default: None. |
| 37 | norm_cfg (dict | None): Config dict for normalization layer. |
| 38 | Default: dict(type='BN'). |
| 39 | act_cfg (dict | None): Config dict for activation layer in ConvModule. |
| 40 | Default: dict(type='ReLU'). |
| 41 | dcn (bool): Use deformable convolution in convolutional layer or not. |
| 42 | Default: None. |
| 43 | plugins (dict): plugins for convolutional layers. Default: None. |
| 44 | """ |
| 45 | |
| 46 | def __init__(self, |
| 47 | in_channels, |
| 48 | out_channels, |
| 49 | num_convs=2, |
| 50 | stride=1, |
| 51 | dilation=1, |
| 52 | with_cp=False, |
| 53 | conv_cfg=None, |
| 54 | norm_cfg=dict(type='BN'), |
| 55 | act_cfg=dict(type='ReLU'), |
| 56 | dcn=None, |
| 57 | plugins=None): |
| 58 | super(BasicConvBlock, self).__init__() |
| 59 | assert dcn is None, 'Not implemented yet.' |
| 60 | assert plugins is None, 'Not implemented yet.' |
| 61 | |
| 62 | self.with_cp = with_cp |
| 63 | convs = [] |
| 64 | for i in range(num_convs): |
| 65 | convs.append( |
| 66 | ConvModule( |
| 67 | in_channels=in_channels if i == 0 else out_channels, |
| 68 | out_channels=out_channels, |
| 69 | kernel_size=3, |
| 70 | stride=stride if i == 0 else 1, |
| 71 | dilation=1 if i == 0 else dilation, |
| 72 | padding=1 if i == 0 else dilation, |
| 73 | conv_cfg=conv_cfg, |