Esempio n. 1
0
    def _init_layers(self):

        self.tl_fadp = DeformConv(self.in_channels, self.in_channels, 3, 1, 1)
        self.br_fadp = DeformConv(self.in_channels, self.in_channels, 3, 1, 1)
        self.mid_tl_fadp = DeformConv(self.in_channels, self.in_channels, 3, 1,
                                      1)
        self.mid_br_fadp = DeformConv(self.in_channels, self.in_channels, 3, 1,
                                      1)

        self.tl_offset = nn.Conv2d(2, 18, 1, bias=False)
        self.br_offset = nn.Conv2d(2, 18, 1, bias=False)
        self.mid_tl_offset = nn.Conv2d(2, 18, 1, bias=False)
        self.mid_br_offset = nn.Conv2d(2, 18, 1, bias=False)

        self.tl_pool = TopLeftPool(self.in_channels)
        self.br_pool = BottomRightPool(self.in_channels)
        self.mid_tl_pool = TopLeftPool(self.in_channels)
        self.mid_br_pool = BottomRightPool(self.in_channels)

        self.tl_heat = make_kp_layer(out_dim=self.num_classes)
        self.br_heat = make_kp_layer(out_dim=self.num_classes)

        self.tl_off_c = make_kp_layer(out_dim=2)
        self.br_off_c = make_kp_layer(out_dim=2)

        self.tl_off_c_2 = make_kp_layer(out_dim=2)
        self.br_off_c_2 = make_kp_layer(out_dim=2)

        self.tl_off = make_kp_layer(out_dim=2)
        self.br_off = make_kp_layer(out_dim=2)

        # middle supervision

        self.mid_tl_heat = make_kp_layer(out_dim=self.num_classes)
        self.mid_br_heat = make_kp_layer(out_dim=self.num_classes)

        self.mid_tl_off_c = make_kp_layer(out_dim=2)
        self.mid_br_off_c = make_kp_layer(out_dim=2)

        self.mid_tl_off_c_2 = make_kp_layer(out_dim=2)
        self.mid_br_off_c_2 = make_kp_layer(out_dim=2)

        self.mid_tl_off = make_kp_layer(out_dim=2)
        self.mid_br_off = make_kp_layer(out_dim=2)

        if self.with_mask:
            for i in range(4):
                self.convs.append(
                    ConvModule(self.in_channels,
                               self.in_channels,
                               3,
                               padding=1))
                self.mid_convs.append(
                    ConvModule(self.in_channels,
                               self.in_channels,
                               3,
                               padding=1))

            self.conv_logits = nn.Conv2d(self.in_channels, 81, 1)
            self.mid_conv_logits = nn.Conv2d(self.in_channels, 81, 1)
Esempio n. 2
0
 def _init_layers(self):
     self.relu = nn.ReLU(inplace=True)
     self.cls_convs = nn.ModuleList()
     self.reg_convs = nn.ModuleList()
     for i in range(self.stacked_convs):
         chn = self.in_channels if i == 0 else self.feat_channels
         self.cls_convs.append(
             ConvModule(
                 chn,
                 self.feat_channels,
                 3,
                 stride=1,
                 padding=1,
                 conv_cfg=self.conv_cfg,
                 norm_cfg=self.norm_cfg,
             ))
         self.reg_convs.append(
             ConvModule(
                 chn,
                 self.feat_channels,
                 3,
                 stride=1,
                 padding=1,
                 conv_cfg=self.conv_cfg,
                 norm_cfg=self.norm_cfg,
             ))
     pts_out_dim = 4 if self.use_grid_points else 2 * self.num_points
     self.reppoints_cls_conv = DeformConv(
         self.feat_channels,
         self.point_feat_channels,
         self.dcn_kernel,
         1,
         self.dcn_pad,
     )
     self.reppoints_cls_out = nn.Conv2d(self.point_feat_channels,
                                        self.cls_out_channels, 1, 1, 0)
     self.reppoints_pts_init_conv = nn.Conv2d(self.feat_channels,
                                              self.point_feat_channels, 3,
                                              1, 1)
     self.reppoints_pts_init_out = nn.Conv2d(self.point_feat_channels,
                                             pts_out_dim, 1, 1, 0)
     self.reppoints_pts_refine_conv = DeformConv(
         self.feat_channels,
         self.point_feat_channels,
         self.dcn_kernel,
         1,
         self.dcn_pad,
     )
     self.reppoints_pts_refine_out = nn.Conv2d(self.point_feat_channels,
                                               pts_out_dim, 1, 1, 0)
Esempio n. 3
0
 def __init__(self,
              in_channels,
              out_channels,
              displacements=(8, 8, 4, 2),
              strides=(2, 1, 1, 1),
              kernel_size=3,
              deformable_groups=4):
     super(CorrelationAdaptor, self).__init__()
     assert len(displacements) == len(strides)
     offset_channels = kernel_size * kernel_size * 2
     self.point_corrs = nn.ModuleList([
         PointwiseCorrelation(disp, s)
         for disp, s in zip(displacements, strides)
     ])
     self.conv_offsets = nn.ModuleList([
         nn.Conv2d((2 * disp + 1) * (2 * disp + 1),
                   deformable_groups * offset_channels,
                   kernel_size=1,
                   bias=False) for disp in displacements
     ])
     self.conv_adaptions = nn.ModuleList([
         DeformConv(in_channels,
                    out_channels,
                    kernel_size=kernel_size,
                    padding=(kernel_size - 1) // 2,
                    deformable_groups=deformable_groups)
         for _ in displacements
     ])
     self.relu = nn.ReLU(inplace=True)
Esempio n. 4
0
 def __init__(self, in_channels, out_channels, rates):
     super(ASPP, self).__init__()
     self.stages = nn.ModuleList()
     #non_local = NonLocal2D(
     #        in_channels,
     #        reduction=1,
     #        use_scale=False,
     #        conv_cfg=None,
     #        norm_cfg=None)
     #self.stages.append(non_local)
     self.offsets = nn.ModuleList()
     for i, rate in enumerate(rates):
         deform_conv_op = DeformConv(in_channels,
                                     out_channels,
                                     kernel_size=3,
                                     stride=1,
                                     padding=rate,
                                     dilation=rate,
                                     deformable_groups=1,
                                     bias=False)
         conv_offset = ConvModule(in_channels=in_channels,
                                  out_channels=18,
                                  kernel_size=3,
                                  stride=1,
                                  padding=rate,
                                  dilation=rate,
                                  conv_cfg=None,
                                  norm_cfg=None)
         self.stages.append(deform_conv_op)
         self.offsets.append(conv_offset)
Esempio n. 5
0
 def __init__(self,
              in_channels,
              out_channels,
              kernel_size,
              stride=1,
              padding=0,
              dilation=1,
              groups=1,
              deformable_groups=1,
              bias=True):
     super(DeformConvWithOffset, self).__init__()
     self.conv_offset = nn.Conv2d(in_channels,
                                  kernel_size * kernel_size * 2 *
                                  deformable_groups,
                                  kernel_size=3,
                                  stride=1,
                                  padding=1)
     self.conv_offset.weight.data.zero_()
     self.conv_offset.bias.data.zero_()
     self.conv = DeformConv(in_channels,
                            out_channels,
                            kernel_size=kernel_size,
                            stride=stride,
                            padding=padding,
                            dilation=dilation,
                            groups=groups,
                            deformable_groups=deformable_groups,
                            bias=False)
Esempio n. 6
0
 def __init__(self):
     super(Net, self).__init__()
     self.deform_conv1 = DeformConv(in_channel,
                                    out_channel,
                                    kernel_size,
                                    padding=1,
                                    bias=True)
     self.conv1 = nn.Conv2d(out_channel,
                            out_channel,
                            kernel_size,
                            padding=(1, 1))
     self.deform_conv2 = DeformConv(out_channel,
                                    out_channel,
                                    kernel_size,
                                    padding=1,
                                    bias=False)
Esempio n. 7
0
    def _init_layers(self):
        self.relu = nn.ReLU(inplace=True)
        self.cls_convs = nn.ModuleList()
        self.reg_convs = nn.ModuleList()
        for i in range(self.stacked_convs):
            chn = self.in_channels if i == 0 else self.feat_channels
            self.cls_convs.append(
                nn.Conv2d(chn, self.feat_channels, 3, stride=1, padding=1))
            self.reg_convs.append(
                nn.Conv2d(chn, self.feat_channels, 3, stride=1, padding=1))

        self.conv_loc = nn.Conv2d(self.feat_channels, 1, 1)
        self.conv_shape = nn.Conv2d(self.feat_channels, self.num_anchors * 2,
                                    1)
        deformable_groups = 4
        offset_channels = 3 * 3 * 2
        self.conv_offset_cls = nn.Conv2d(self.num_anchors * 2,
                                         deformable_groups * offset_channels,
                                         1,
                                         bias=False)
        self.conv_adaption_cls = DeformConv(
            self.feat_channels,
            self.feat_channels,
            kernel_size=3,
            padding=1,
            deformable_groups=deformable_groups)
        self.conv_offset_reg = nn.Conv2d(self.num_anchors * 2,
                                         deformable_groups * offset_channels,
                                         1,
                                         bias=False)
        self.conv_adaption_reg = DeformConv(
            self.feat_channels,
            self.feat_channels,
            kernel_size=3,
            padding=1,
            deformable_groups=deformable_groups)
        self.retina_cls = MaskedConv2d(self.feat_channels,
                                       self.num_anchors *
                                       self.cls_out_channels,
                                       3,
                                       padding=1)
        self.retina_reg = MaskedConv2d(self.feat_channels,
                                       self.num_anchors * 4,
                                       3,
                                       padding=1)
 def __init__(self, in_channels, out_channels, dilation=1, adapt=True):
     super(AdaptiveConv, self).__init__()
     self.adapt = adapt
     if self.adapt:
         assert dilation == 1
         self.conv = DeformConv(in_channels, out_channels, 3, padding=1)
     else:  # fallback to normal Conv2d
         self.conv = nn.Conv2d(in_channels,
                               out_channels,
                               3,
                               padding=dilation,
                               dilation=dilation)
Esempio n. 9
0
 def __init__(self, in_channels, out_channels, kernel_size=3, deformable_groups=4):
     super(FeatureAdaption, self).__init__()
     offset_channels = kernel_size * kernel_size * 2
     self.conv_offset = nn.Conv2d(
         2, deformable_groups * offset_channels, 1, bias=False
     )
     self.conv_adaption = DeformConv(
         in_channels,
         out_channels,
         kernel_size=kernel_size,
         padding=(kernel_size - 1) // 2,
         deformable_groups=deformable_groups,
     )
     self.relu = nn.ReLU(inplace=True)
Esempio n. 10
0
    def __init__(self,
                 in_channels,
                 hidden_size,
                 kernel_size=3,
                 displacement=4):
        super(AlignedSTMNCell, self).__init__()
        padding = kernel_size // 2
        self.input_size = in_channels
        self.hidden_size = hidden_size
        self.reset_gate = nn.Conv2d(in_channels + hidden_size,
                                    hidden_size,
                                    kernel_size,
                                    padding=padding)
        self.update_gate = nn.Conv2d(in_channels + hidden_size,
                                     hidden_size,
                                     kernel_size,
                                     padding=padding)
        self.out_gate = nn.Conv2d(in_channels + hidden_size,
                                  hidden_size,
                                  kernel_size,
                                  padding=padding)

        # bottleneck = 256
        offset_channels = kernel_size * kernel_size * 2
        corr_channels = (2 * displacement + 1)**2
        raise NotImplementedError
        self.correlation = Correlation(pad_size=displacement,
                                       kernel_size=1,
                                       max_displacement=displacement,
                                       stride1=1,
                                       stride2=1)
        # self.corr_conv = nn.Sequential(
        #     nn.Conv2d(
        #         in_channels=corr_channels,
        #         out_channels=bottleneck,
        #         kernel_size=kernel_size,
        #         padding=(kernel_size - 1) // 2,
        #         stride=1),
        #     nn.ReLU(inplace=True))
        self.conv_offset = nn.Conv2d(corr_channels,
                                     offset_channels,
                                     kernel_size=1,
                                     bias=False)
        self.conv_align = DeformConv(in_channels=in_channels,
                                     out_channels=in_channels,
                                     kernel_size=kernel_size,
                                     padding=(kernel_size - 1) // 2,
                                     deformable_groups=1)
        self.relu = nn.ReLU(inplace=True)
Esempio n. 11
0
def add_dcn_dilas():
    planes = [512,1024,256,256]
    deformable_groups = 1
    conv_layers = []
    for i in range(4):
        conv_layers += [DeformConv(
            planes[i],
            256,
            kernel_size=3,
            stride=1,
            padding=5-i,
            dilation=5-i,
            deformable_groups=deformable_groups,
            bias=False)]
    return conv_layers
    def __init__(self,
                 in_channels,
                 out_channels,
                 displacements=(4, 2),
                 strides=(2, 1),
                 kernel_size=3,
                 deformable_groups=4):
        """

        Args:
            in_channels: tuple of int
            out_channels: tuple of int, same length as in_channels
            displacements: tuple of int
            strides:tuple of int, same length as displacements
            kernel_size: int
            deformable_groups: int
        """
        super(ConcatCorrelationAdaptor, self).__init__()
        assert len(displacements) == len(strides)
        self.in_channels = in_channels
        self.out_channels = out_channels

        raise NotImplementedError
        self.point_corrs = nn.ModuleList([
            PointwiseCorrelation(disp, s)
            for disp, s in zip(displacements, strides)
        ])

        num_corr_channels = 0
        for d in displacements:
            num_corr_channels += (2 * d + 1) * (2 * d + 1)

        offset_channels = kernel_size * kernel_size * 2
        self.conv_offsets = nn.ModuleList([
            nn.Conv2d(num_corr_channels,
                      deformable_groups * offset_channels,
                      kernel_size=1,
                      bias=False) for _ in in_channels
        ])
        self.conv_adaptions = nn.ModuleList([
            DeformConv(in_channels[i],
                       out_channels[i],
                       kernel_size=kernel_size,
                       padding=(kernel_size - 1) // 2,
                       deformable_groups=deformable_groups)
            for i, _ in enumerate(in_channels)
        ])
        self.relu = nn.ReLU(inplace=True)
Esempio n. 13
0
 def __init__(self,
              in_channels,
              out_channels,
              kernel_size=3,
              deformable_groups=4):
     super(FeatureAdaption, self).__init__()
     offset_channels = kernel_size * kernel_size * 2
     self.conv_offset = nn.Conv2d(
         2, deformable_groups * offset_channels, 1,
         bias=False)  #计算偏移的普通卷积,输入为w,h的通道为2,输出为3*3*2*deformat,计算所有的偏移
     self.conv_adaption = DeformConv(
         in_channels,
         out_channels,
         kernel_size=kernel_size,
         padding=(kernel_size - 1) // 2,
         deformable_groups=deformable_groups)  #DCN卷积层
     self.relu = nn.ReLU(inplace=True)
Esempio n. 14
0
    def __init__(
        self,
        feature_in_channels,
        feature_out_channels,
        num_fpn_levels=4,
        deform_kernel_size=3,
        offset_in_channels=2,
        offset_kernel_size=1,
        with_activation=None,
    ):
        super(ARPNDeformFeature, self).__init__()
        self.feature_in_channels = feature_in_channels
        self.feature_out_channels = feature_out_channels
        self.num_fpn_levels = num_fpn_levels
        self.deform_kernel_size = deform_kernel_size
        self.offset_kernel_size = offset_kernel_size
        self.offset_in_channels = offset_in_channels
        self.with_activation = with_activation

        self.offset_convs = nn.ModuleList()
        self.deform_convs = nn.ModuleList()

        for i in range(self.num_fpn_levels):
            offset_conv = nn.Conv2d(
                self.offset_in_channels,
                self.deform_kernel_size**2 * 2,
                kernel_size=offset_kernel_size,
                padding=offset_kernel_size // 2,
                stride=1,
            )

            deform_conv = DeformConv(
                self.feature_in_channels,
                self.feature_out_channels,
                kernel_size=self.deform_kernel_size,
                stride=1,
                padding=1,
            )
            self.offset_convs.append(offset_conv)
            self.deform_convs.append(deform_conv)

        if self.with_activation:
            self.activate = nn.ReLU(inplace=inplace)
Esempio n. 15
0
 def __init__(self,
              in_channels,
              out_channels,
              kernel_size=3,
              deformable_groups=4,
              flag_norm=True):
     super(FeatureAlign, self).__init__()
     offset_channels = kernel_size * kernel_size * 2
     self.conv_offset = nn.Conv2d(4,
                                  deformable_groups * offset_channels,
                                  1,
                                  bias=False)
     self.conv_adaption = DeformConv(in_channels,
                                     out_channels,
                                     kernel_size=kernel_size,
                                     padding=(kernel_size - 1) // 2,
                                     deformable_groups=deformable_groups)
     self.relu = nn.ReLU(inplace=True)
     self.norm = nn.GroupNorm(32, in_channels)
     self.flag_norm = flag_norm
Esempio n. 16
0
 def _init_layers(self):
     self.relu = nn.ReLU(inplace=True)
     self.conv_loc = nn.Conv2d(self.feat_channels, 1, 1)
     self.conv_shape = nn.Conv2d(self.feat_channels, self.num_anchors * 2,
                                 1)
     deformable_groups = 4
     offset_channels = 3 * 3 * 2
     self.conv_offset = nn.Conv2d(self.num_anchors * 2,
                                  deformable_groups * offset_channels,
                                  1,
                                  bias=False)
     self.conv_adaption = DeformConv(self.feat_channels,
                                     self.feat_channels,
                                     kernel_size=3,
                                     padding=1,
                                     deformable_groups=deformable_groups)
     self.conv_cls = MaskedConv2d(self.feat_channels,
                                  self.num_anchors * self.cls_out_channels,
                                  1)
     self.conv_reg = MaskedConv2d(self.feat_channels, self.num_anchors * 4,
                                  1)
Esempio n. 17
0
 def _init_layers(self):
     self.relu = nn.ReLU(inplace=True)
     self.cls_convs = nn.ModuleList()
     self.reg_convs = nn.ModuleList()
     for i in range(self.stacked_convs):
         chn = self.in_channels if i == 0 else self.feat_channels
         self.cls_convs.append(
             ConvModule(chn,
                        self.feat_channels,
                        3,
                        stride=1,
                        padding=1,
                        conv_cfg=self.conv_cfg,
                        norm_cfg=self.norm_cfg,
                        bias=self.norm_cfg is None))
         self.reg_convs.append(
             ConvModule(chn,
                        self.feat_channels,
                        3,
                        stride=1,
                        padding=1,
                        conv_cfg=self.conv_cfg,
                        norm_cfg=self.norm_cfg,
                        bias=self.norm_cfg is None))
     self.fcos_cls = nn.Conv2d(self.feat_channels,
                               self.cls_out_channels,
                               3,
                               padding=1)
     self.fcos_reg = nn.Conv2d(self.feat_channels, 4, 3, padding=1)
     self.fcos_centerness = nn.Conv2d(self.feat_channels, 1, 3, padding=1)
     self.fcos_offset_conv = nn.Conv2d(self.feat_channels,
                                       self.feat_channels,
                                       3,
                                       padding=1)
     self.fcos_offset = nn.Conv2d(self.feat_channels, 18, 1, 1, 0)
     self.fcos_cls_conv = DeformConv(self.feat_channels, self.feat_channels,
                                     3, 1, 1)
     self.result = nn.Conv2d(4, 1, 3, padding=1)
     self.norm = nn.BatchNorm2d(1)
     self.scales = nn.ModuleList([Scale(1.0) for _ in self.strides])
Esempio n. 18
0
 def _init_shape_index_layers(self, num_anchors):
     shape_align_conv = nn.ModuleList()
     norm = nn.ModuleList()
     for i in range(num_anchors):
         if self.modulated_dcn:
             shape_align_conv.append(
                 ModulatedDeformConv(self.in_channels,
                                     self.feat_channels,
                                     self.dcn_kernel,
                                     stride=1,
                                     padding=self.dcn_pad,
                                     bias=False))
         else:
             shape_align_conv.append(
                 DeformConv(self.in_channels,
                            self.feat_channels,
                            self.dcn_kernel,
                            stride=1,
                            padding=self.dcn_pad,
                            bias=False))
         n_name, n = build_norm_layer(self.norm_cfg, self.feat_channels)
         norm.append(n)
     return shape_align_conv, norm
Esempio n. 19
0
    def _init_layers(self):
        self.relu = nn.ReLU(inplace=True)
        self.cls_convs = nn.ModuleList()
        self.reg_convs = nn.ModuleList()
        self.ang_convs = nn.ModuleList()

        for i in range(self.stacked_convs):
            chn = self.in_channels if i == 0 else self.feat_channels
            self.cls_convs.append(
                ConvModule(chn,
                           self.feat_channels,
                           3,
                           stride=1,
                           padding=1,
                           conv_cfg=self.conv_cfg,
                           norm_cfg=self.norm_cfg))
            self.reg_convs.append(
                ConvModule(chn,
                           self.feat_channels,
                           3,
                           stride=1,
                           padding=1,
                           conv_cfg=self.conv_cfg,
                           norm_cfg=self.norm_cfg))

        pts_out_dim = 4 if self.use_grid_points else 2 * self.num_points
        self.reppoints_cls_conv = DeformConv(self.feat_channels,
                                             self.point_feat_channels,
                                             self.dcn_kernel, 1, self.dcn_pad)
        self.reppoints_cls_out = nn.Conv2d(self.point_feat_channels,
                                           self.cls_out_channels, 1, 1, 0)
        self.reppoints_pts_init_conv = nn.Conv2d(self.feat_channels,
                                                 self.point_feat_channels, 3,
                                                 1, 1)
        self.reppoints_pts_init_out = nn.Conv2d(self.point_feat_channels,
                                                pts_out_dim, 1, 1, 0)
        self.reppoints_pts_refine_conv = DeformConv(self.feat_channels,
                                                    self.point_feat_channels,
                                                    self.dcn_kernel, 1,
                                                    self.dcn_pad)
        self.reppoints_pts_refine_out = nn.Conv2d(self.point_feat_channels,
                                                  pts_out_dim, 1, 1, 0)

        self.reppoints_angle_conv = DeformConv(
            128 if self.use_reduced else 256 + pts_out_dim +
            self.cls_out_channels, self.point_feat_channels, self.dcn_kernel,
            1, self.dcn_pad)
        self.reppoints_angle_out = nn.Conv2d(self.point_feat_channels, 1, 1, 1,
                                             0)

        self.ang_out_convs = nn.ModuleList()

        if self.use_reduced:
            channel_arr = [(self.feat_channels, 256), (256, 128), (128, 32),
                           (32, 1)]

            for in_c, out_c in channel_arr:
                self.ang_out_convs.append(
                    ConvModule(in_c,
                               out_c,
                               1,
                               stride=1,
                               padding=0,
                               inplace=False,
                               activate_last=False))

        else:
            for i in range(self.stacked_convs):
                chn = self.in_channels if i == 0 else self.feat_channels
                self.ang_convs.append(
                    ConvModule(chn,
                               self.feat_channels,
                               3,
                               stride=1,
                               padding=1,
                               conv_cfg=self.conv_cfg,
                               norm_cfg=self.norm_cfg))
    def __init__(self,
                 num_ins,
                 fusion_level,
                 num_convs=4,
                 in_channels=256,
                 conv_out_channels=256,
                 num_classes=183,
                 ignore_label=255,
                 loss_weight=0.2,
                 conv_cfg=None,
                 norm_cfg=dict(type='BN')):
        super(FusedSemanticHead_DCN, self).__init__()
        self.num_ins = num_ins
        self.fusion_level = fusion_level
        self.num_convs = num_convs
        self.in_channels = in_channels
        self.conv_out_channels = conv_out_channels
        self.num_classes = num_classes
        self.ignore_label = ignore_label
        self.loss_weight = loss_weight
        self.conv_cfg = conv_cfg
        self.norm_cfg = norm_cfg
        self.fp16_enabled = False

        offset_channels = 18
        deformable_groups = 1
        dilation = 1
        self.dc1_offset = nn.Conv2d(self.in_channels,
                                    deformable_groups * offset_channels,
                                    kernel_size=3,
                                    stride=1,
                                    padding=dilation,
                                    dilation=dilation)
        self.dc1 = DeformConv(self.in_channels,
                              self.in_channels,
                              kernel_size=3,
                              stride=1,
                              padding=dilation,
                              dilation=dilation,
                              deformable_groups=deformable_groups,
                              bias=False)
        self.dc2_offset = nn.Conv2d(self.in_channels,
                                    deformable_groups * offset_channels,
                                    kernel_size=3,
                                    stride=1,
                                    padding=dilation,
                                    dilation=dilation)
        self.dc2 = DeformConv(self.in_channels,
                              self.in_channels,
                              kernel_size=3,
                              stride=1,
                              padding=dilation,
                              dilation=dilation,
                              deformable_groups=deformable_groups,
                              bias=False)
        self.norm2_name, self.norm2 = build_norm_layer(norm_cfg,
                                                       self.in_channels,
                                                       postfix=2)
        self.relu = nn.ReLU(inplace=False)

        self.convs = nn.ModuleList()
        for i in range(self.num_convs):
            in_channels = self.in_channels if i == 0 else conv_out_channels
            self.convs.append(
                ConvModule(in_channels,
                           conv_out_channels,
                           3,
                           padding=1,
                           conv_cfg=self.conv_cfg,
                           norm_cfg=self.norm_cfg))
        self.conv_embedding = ConvModule(conv_out_channels,
                                         conv_out_channels,
                                         1,
                                         conv_cfg=self.conv_cfg,
                                         norm_cfg=self.norm_cfg)
        self.conv_logits = nn.Conv2d(conv_out_channels, self.num_classes, 1)

        self.criterion = nn.CrossEntropyLoss(ignore_index=ignore_label)
Esempio n. 21
0
    def _init_layers(self):
        """
        Initializing the layers of the head. As given in Figure 3. of the paper
        """

        self.relu = nn.ReLU(inplace=True)
        self.cls_convs = nn.ModuleList()
        self.reg_convs = nn.ModuleList()

        ## Stacking the first 3 convolution layer in the head
        for i in range(self.stacked_convs):
            # For i=0 it is attached to the FPN, so channels = in_channels
            chn = self.in_channels if i == 0 else self.feat_channels
            #Stacking 3 convolutions for the classification head
            self.cls_convs.append(
                ConvModule(
                    chn,
                    self.feat_channels,
                    3,
                    stride=1,
                    padding=1,
                    conv_cfg=self.conv_cfg,
                    norm_cfg=self.norm_cfg))
            #Stacking 3 convolutions for the regression head
            self.reg_convs.append(
                ConvModule(
                    chn,
                    self.feat_channels,
                    3,
                    stride=1,
                    padding=1,
                    conv_cfg=self.conv_cfg,
                    norm_cfg=self.norm_cfg))
        
        #! What is grid_points and how does it affect the pts_out_dim
        pts_out_dim = 4 if self.use_grid_points else 2 * self.num_points

        # Deformable convolution for classification layer
        self.reppoints_cls_conv = DeformConv(self.feat_channels,
                                             self.point_feat_channels,
                                             self.dcn_kernel, 1, self.dcn_pad)
        
        # Output convolution for the classification layer                                     
        self.reppoints_cls_out = nn.Conv2d(self.point_feat_channels,
                                           self.cls_out_channels, 1, 1, 0)
        
        #Regression layer initial convolution
        self.reppoints_pts_init_conv = nn.Conv2d(self.feat_channels,
                                                 self.point_feat_channels, 3,
                                                 1, 1)
        
        #Regression layer initial RepPoint convolutions
        self.reppoints_pts_init_out = nn.Conv2d(self.point_feat_channels,
                                                pts_out_dim, 1, 1, 0)
        
        #Deformable convolution for refinement stage of the regression head
        self.reppoints_pts_refine_conv = DeformConv(self.feat_channels,
                                                    self.point_feat_channels,
                                                    self.dcn_kernel, 1,
                                                    self.dcn_pad)
        
        #Convolution for the refined output of the regression head
        self.reppoints_pts_refine_out = nn.Conv2d(self.point_feat_channels,
                                                  pts_out_dim, 1, 1, 0)