Exemple #1
0
 def __init__(self):
     super(Offset_Head, self).__init__()
     self.thresh = 1e-8
     self.is_vec = True
     self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
     self.fc1 = make_fc(256, 256, False)
     self.fc2 = make_fc(256, 256, False)
     self.fc3 = make_fc(256, 2, False)
     self.align_pooling = BilinearPooling(trans_std=0.005)
    def __init__(self, cfg, in_channels):
        super(FPN2MLPFeatureExtractor, self).__init__()

        resolution = cfg.MODEL.ROI_BOX_HEAD.POOLER_RESOLUTION
        scales = cfg.MODEL.ROI_BOX_HEAD.POOLER_SCALES
        sampling_ratio = cfg.MODEL.ROI_BOX_HEAD.POOLER_SAMPLING_RATIO
        pooler = Pooler(
            output_size=(resolution, resolution),
            scales=scales,
            sampling_ratio=sampling_ratio,
        )
        input_size = in_channels * resolution ** 2
        representation_size = cfg.MODEL.ROI_BOX_HEAD.MLP_HEAD_DIM
        use_gn = cfg.MODEL.ROI_BOX_HEAD.USE_GN
        self.pooler = pooler
        self.fc6 = make_fc(input_size, representation_size, use_gn)
        self.fc7 = make_fc(representation_size, representation_size, use_gn)
        self.out_channels = representation_size
    def __init__(self, cfg, in_channels):
        super(FPNXconv1fcFeatureExtractor, self).__init__()

        resolution = cfg.MODEL.ROI_BOX_HEAD.POOLER_RESOLUTION
        scales = cfg.MODEL.ROI_BOX_HEAD.POOLER_SCALES
        sampling_ratio = cfg.MODEL.ROI_BOX_HEAD.POOLER_SAMPLING_RATIO
        use_torchvision = cfg.MODEL.ROI_BOX_HEAD.USE_TORCHVISION
        pooler = Pooler(
            output_size=(resolution, resolution),
            scales=scales,
            sampling_ratio=sampling_ratio,
            use_torchvision=use_torchvision,
        )
        self.pooler = pooler

        use_gn = cfg.MODEL.ROI_BOX_HEAD.USE_GN
        conv_head_dim = cfg.MODEL.ROI_BOX_HEAD.CONV_HEAD_DIM
        num_stacked_convs = cfg.MODEL.ROI_BOX_HEAD.NUM_STACKED_CONVS
        dilation = cfg.MODEL.ROI_BOX_HEAD.DILATION

        xconvs = []
        for ix in range(num_stacked_convs):
            xconvs.append(
                nn.Conv2d(in_channels,
                          conv_head_dim,
                          kernel_size=3,
                          stride=1,
                          padding=dilation,
                          dilation=dilation,
                          bias=False if use_gn else True))
            in_channels = conv_head_dim
            if use_gn:
                xconvs.append(group_norm(in_channels))
            xconvs.append(nn.ReLU(inplace=True))

        self.add_module("xconvs", nn.Sequential(*xconvs))
        for modules in [
                self.xconvs,
        ]:
            for l in modules.modules():
                if isinstance(l, nn.Conv2d):
                    torch.nn.init.normal_(l.weight, std=0.01)
                    if not use_gn:
                        torch.nn.init.constant_(l.bias, 0)

        input_size = conv_head_dim * resolution**2
        representation_size = cfg.MODEL.ROI_BOX_HEAD.MLP_HEAD_DIM
        self.fc6 = make_fc(input_size, representation_size, use_gn=False)
        self.out_channels = representation_size
Exemple #4
0
    def __init__(self, gap, gcp, mix):
        super(Cls_Head, self).__init__()
        self.gap = gap
        self.gcp = gcp
        self.mix = mix
        self.thresh = 1e-8
        self.is_vec = True
        self.gcp_mode = 0
        if self.gap == True:
            self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
            self.maxpool = nn.AdaptiveMaxPool2d((1, 1))
            if self.mix == True: self.fc_gap = make_fc(2048, 1024, False)
            else: self.fc_gap = make_fc(512, 80, False)
        if self.gcp == True:
            self.reduce_dim = 64
            self.layer_reduce = nn.Conv2d(2048,
                                          self.reduce_dim,
                                          kernel_size=1,
                                          stride=1,
                                          padding=0,
                                          bias=False)
            if self.mix == True:
                if self.gcp_mode == 0:
                    self.fc_gcp = make_fc(self.reduce_dim * self.reduce_dim,
                                          1024, False)
                if self.gcp_mode == 1:
                    self.fc_gcp = make_fc(
                        int(self.reduce_dim * (self.reduce_dim + 1) / 2), 1024,
                        False)
            if self.mix == False:
                if self.gcp_mode == 0:
                    self.fc_gcp = make_fc(self.reduce_dim * self.reduce_dim,
                                          80, False)
                if self.gcp_mode == 1:
                    self.fc_gcp = make_fc(
                        int(self.reduce_dim * (self.reduce_dim + 1) / 2), 80,
                        False)
        if self.mix == True:
            self.fc_mix = make_fc(1024, 80, False)

        self.classification_loss_func = nn.BCEWithLogitsLoss()