(self,
                 inplanes,
                 planes,
                 stride=1,
                 dilation=1,
                 downsample=None,
                 style='pytorch',
                 with_cp=False,
                 conv_cfg=None,
                 norm_cfg=dict(type='BN'),
                 dcn=None,
                 gcb=None,
                 gen_attention=None)
Bottleneck block for ResNet.
        If style is "pytorch", the stride-two layer is the 3x3 conv layer,
        if it is "caffe", the stride-two layer is the first 1x1 conv layer.
Bottleneck block for ResNet.
        If style is "pytorch", the stride-two layer is the 3x3 conv layer,
        if it is "caffe", the stride-two layer is the first 1x1 conv layer.
Bottleneck block for ResNet . If style is pytorch the stride - two layer is the 3x3 conv layer if it is caffe the stride - two layer is the first 1x1 conv layer .
def __init__(self,
                 inplanes,
                 planes,
                 stride=1,
                 dilation=1,
                 downsample=None,
                 style='pytorch',
                 with_cp=False,
                 conv_cfg=None,
                 norm_cfg=dict(type='BN'),
                 dcn=None,
                 gcb=None,
                 gen_attention=None):
        """Bottleneck block for ResNet.
        If style is "pytorch", the stride-two layer is the 3x3 conv layer,
        if it is "caffe", the stride-two layer is the first 1x1 conv layer.
        """
        super(Bottleneck, self).__init__()
        assert style in ['pytorch', 'caffe']
        assert dcn is None or isinstance(dcn, dict)
        assert gcb is None or isinstance(gcb, dict)
        assert gen_attention is None or isinstance(gen_attention, dict)

        self.inplanes = inplanes
        self.planes = planes
        self.stride = stride
        self.dilation = dilation
        self.style = style
        self.with_cp = with_cp
        self.conv_cfg = conv_cfg
        self.norm_cfg = norm_cfg
        self.dcn = dcn
        self.with_dcn = dcn is not None
        self.gcb = gcb
        self.with_gcb = gcb is not None
        self.gen_attention = gen_attention
        self.with_gen_attention = gen_attention is not None

        if self.style == 'pytorch':
            self.conv1_stride = 1
            self.conv2_stride = stride
        else:
            self.conv1_stride = stride
            self.conv2_stride = 1

        self.norm1_name, norm1 = build_norm_layer(norm_cfg, planes, postfix=1)
        self.norm2_name, norm2 = build_norm_layer(norm_cfg, planes, postfix=2)
        self.norm3_name, norm3 = build_norm_layer(
            norm_cfg, planes * self.expansion, postfix=3)

        self.conv1 = build_conv_layer(
            conv_cfg,
            inplanes,
            planes,
            kernel_size=1,
            stride=self.conv1_stride,
            bias=False)
        self.add_module(self.norm1_name, norm1)
        fallback_on_stride = False
        self.with_modulated_dcn = False
        if self.with_dcn:
            fallback_on_stride = dcn.get('fallback_on_stride', False)
            self.with_modulated_dcn = dcn.get('modulated', False)
        if not self.with_dcn or fallback_on_stride:
            self.conv2 = build_conv_layer(
                conv_cfg,
                planes,
                planes,
                kernel_size=3,
                stride=self.conv2_stride,
                padding=dilation,
                dilation=dilation,
                bias=False)
        else:
            assert conv_cfg is None, 'conv_cfg must be None for DCN'
            self.deformable_groups = dcn.get('deformable_groups', 1)
            if not self.with_modulated_dcn:
                conv_op = DeformConv
                offset_channels = 18
            else:
                conv_op = ModulatedDeformConv
                offset_channels = 27
            self.conv2_offset = nn.Conv2d(
                planes,
                self.deformable_groups * offset_channels,
                kernel_size=3,
                stride=self.conv2_stride,
                padding=dilation,
                dilation=dilation)
            self.conv2 = conv_op(
                planes,
                planes,
                kernel_size=3,
                stride=self.conv2_stride,
                padding=dilation,
                dilation=dilation,
                deformable_groups=self.deformable_groups,
                bias=False)
        self.add_module(self.norm2_name, norm2)
        self.conv3 = build_conv_layer(
            conv_cfg,
            planes,
            planes * self.expansion,
            kernel_size=1,
            bias=False)
        self.add_module(self.norm3_name, norm3)

        self.relu = nn.ReLU(inplace=True)
        self.downsample = downsample

        if self.with_gcb:
            gcb_inplanes = planes * self.expansion
            self.context_block = ContextBlock(inplanes=gcb_inplanes, **gcb)

        # gen_attention
        if self.with_gen_attention:
            self.gen_attention_block = GeneralizedAttention(
                planes, **gen_attention)
def __init__ ( self , inplanes , planes , stride = 1 , dilation = 1 , downsample = None , style = 'pytorch' , with_cp = False , conv_cfg = None , norm_cfg = dict ( type = 'BN' ) , dcn = None , gcb = None , gen_attention = None ) : super ( Bottleneck , self ) . __init__ ( ) assert style in [ 'pytorch' , 'caffe' ] assert dcn is None or isinstance ( dcn , dict ) assert gcb is None or isinstance ( gcb , dict ) assert gen_attention is None or isinstance ( gen_attention , dict ) self . inplanes = inplanes self . planes = planes self . stride = stride self . dilation = dilation self . style = style self . with_cp = with_cp self . conv_cfg = conv_cfg self . norm_cfg = norm_cfg self . dcn = dcn self . with_dcn = dcn is not None self . gcb = gcb self . with_gcb = gcb is not None self . gen_attention = gen_attention self . with_gen_attention = gen_attention is not None if self . style == 'pytorch' : self . conv1_stride = 1 self . conv2_stride = stride else : self . conv1_stride = stride self . conv2_stride = 1 self . norm1_name , norm1 = build_norm_layer ( norm_cfg , planes , postfix = 1 ) self . norm2_name , norm2 = build_norm_layer ( norm_cfg , planes , postfix = 2 ) self . norm3_name , norm3 = build_norm_layer ( norm_cfg , planes * self . expansion , postfix = 3 ) self . conv1 = build_conv_layer ( conv_cfg , inplanes , planes , kernel_size = 1 , stride = self . conv1_stride , bias = False ) self . add_module ( self . norm1_name , norm1 ) fallback_on_stride = False self . with_modulated_dcn = False if self . with_dcn : fallback_on_stride = dcn . get ( 'fallback_on_stride' , False ) self . with_modulated_dcn = dcn . get ( 'modulated' , False ) if not self . with_dcn or fallback_on_stride : self . conv2 = build_conv_layer ( conv_cfg , planes , planes , kernel_size = 3 , stride = self . conv2_stride , padding = dilation , dilation = dilation , bias = False ) else : assert conv_cfg is None , 'conv_cfg must be None for DCN' self . deformable_groups = dcn . get ( 'deformable_groups' , 1 ) if not self . with_modulated_dcn : conv_op = DeformConv offset_channels = 18 else : conv_op = ModulatedDeformConv offset_channels = 27 self . conv2_offset = nn . Conv2d ( planes , self . deformable_groups * offset_channels , kernel_size = 3 , stride = self . conv2_stride , padding = dilation , dilation = dilation ) self . conv2 = conv_op ( planes , planes , kernel_size = 3 , stride = self . conv2_stride , padding = dilation , dilation = dilation , deformable_groups = self . deformable_groups , bias = False ) self . add_module ( self . norm2_name , norm2 ) self . conv3 = build_conv_layer ( conv_cfg , planes , planes * self . expansion , kernel_size = 1 , bias = False ) self . add_module ( self . norm3_name , norm3 ) self . relu = nn . ReLU ( inplace = True ) self . downsample = downsample if self . with_gcb : gcb_inplanes = planes * self . expansion self . context_block = ContextBlock ( inplanes = gcb_inplanes , * * gcb ) # gen_attention if self . with_gen_attention : self . gen_attention_block = GeneralizedAttention ( planes , * * gen_attention )