Пример #1
0
    def __init__(self, in_channels, out_channels, norm_layer):
        super(DANetHead, self).__init__()
        inter_channels = in_channels // 4
        self.conv5a = nn.Sequential(
            nn.Conv2d(in_channels, inter_channels, 3, padding=1, bias=False),
            norm_layer(inter_channels), nn.ReLU())

        self.conv5c = nn.Sequential(
            nn.Conv2d(in_channels, inter_channels, 3, padding=1, bias=False),
            norm_layer(inter_channels), nn.ReLU())

        self.sa = PAM_Module(inter_channels)
        self.sc = CAM_Module(inter_channels)
        self.conv51 = nn.Sequential(
            nn.Conv2d(inter_channels, inter_channels, 3, padding=1,
                      bias=False), norm_layer(inter_channels), nn.ReLU())
        self.conv52 = nn.Sequential(
            nn.Conv2d(inter_channels, inter_channels, 3, padding=1,
                      bias=False), norm_layer(inter_channels), nn.ReLU())

        self.conv6 = nn.Sequential(nn.Dropout2d(0.1, False),
                                   nn.Conv2d(512, out_channels, 1))
        self.conv7 = nn.Sequential(nn.Dropout2d(0.1, False),
                                   nn.Conv2d(512, out_channels, 1))

        self.conv8 = nn.Sequential(nn.Dropout2d(0.1, False),
                                   nn.Conv2d(512, out_channels, 1))
Пример #2
0
    def __init__(self, BAND_A, BAND_B, classes):
        super(SAR_simple, self).__init__()
        
        self.name = 'sar_simple_'

        # sar
        self.conv21 = nn.Sequential(
            nn.Conv2d(BAND_B, 32, kernel_size=3, padding=0),
            nn.BatchNorm2d(32, momentum=1, affine=True),
            mish()
        )
        self.conv22 = nn.Sequential(
            nn.Conv2d(32, 64, kernel_size=3, padding=1),
            nn.BatchNorm2d(64, momentum=1, affine=True),
            mish()
        )
        self.conv23 = nn.Sequential(
            nn.Conv2d(64, 64, kernel_size=3, padding=1),
            nn.BatchNorm2d(64, momentum=1, affine=True),
            mish()
        )
        self.conv24 = nn.Sequential(
            nn.Conv2d(64, 64, kernel_size=3, padding=1),
            nn.BatchNorm2d(64, momentum=1, affine=True),
            mish()
        )
        self.conv25 = nn.Sequential(
            nn.Conv2d(64, 32, kernel_size=3, padding=1),
            nn.BatchNorm2d(32, momentum=1, affine=True),
            mish()
        )
        
        # fusion
        self.batch_norm_optical = nn.Sequential(
            nn.BatchNorm2d(32, momentum=1, affine=True),
            mish(),
            nn.Dropout(p=0.5)
        )
        self.batch_norm_sar = nn.Sequential(
            nn.BatchNorm2d(32, momentum=1, affine=True),
            mish(),
            nn.Dropout(p=0.5)
        )

        self.global_pooling = nn.AdaptiveAvgPool2d(1)
        self.fc = nn.Sequential(
            nn.Linear(32, classes),
            # nn.Softmax(dim=-1)
        )

        self.cam = CAM_Module(32)
        self.pam = PAM_Module(32)
Пример #3
0
    def __init__(self, input_channels=3, pretrained=True):
        super(CAMUNet, self).__init__()
        self.resnet = resnet50(pretrained=pretrained, input_channels=input_channels)
        self.aspp   = _ASPPModule(2048, 256)
        self.conv   =  nn.Conv2d(256, 1, (1, 1), stride=1)
        self.pdcmblock0 = PDCM(64)
        self.pdcmblock1 = PDCM(256)
        self.pdcmblock2 = PDCM(512)
        self.pdcmblock3 = PDCM(1024)
        self.pdcmblock4 = PDCM(256)
        self.upsample_2_2 = nn.ConvTranspose2d(64, 64, 4, stride=2, bias=False)
        self.upsample_2_3 = nn.ConvTranspose2d(64, 64, 4, stride=2, bias=False)
        self.upsample_2_4 = nn.ConvTranspose2d(64, 64, 4, stride=2, bias=False)
        self.upsample_2_5 = nn.ConvTranspose2d(32, 32, 4, stride=2, bias=False)
        
        self.cam_conv1_1  = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(128, 64, 3, stride=1, padding=1)),
            ('bn'  , nn.BatchNorm2d(64)),
            ('relu', nn.PReLU(num_parameters=64))]))
        self.cam1         = CAM_Module(64)
        self.cam_conv1_2  = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(64, 64, 3, stride=1, padding=1)),
            ('bn'  , nn.BatchNorm2d(64)),
            ('relu', nn.PReLU(num_parameters=64))]))
        self.cam_drop1    = nn.Dropout2d(0.1, False)
        self.cam_conv1_3  = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(64, 32, 1, stride=1)),
            ('bn'  , nn.BatchNorm2d(32)),
            ('relu', nn.PReLU(num_parameters=32))]))
        self.cam_down_c1  =  nn.Conv2d(32, 1, 1, stride=1)
        
        self.cam_conv2_1  = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(320, 128, 3, stride=1, padding=1)),
            ('bn'  , nn.BatchNorm2d(128)),
            ('relu', nn.PReLU(num_parameters=128))]))
        self.cam2         = CAM_Module(128)
        self.cam_conv2_2  = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(128, 64, 3, stride=1, padding=1)),
            ('bn'  , nn.BatchNorm2d(64)),
            ('relu', nn.PReLU(num_parameters=64))]))
        self.cam_drop2    = nn.Dropout2d(0.1, False)
        self.cam_conv2_3  = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(64, 64, 1, stride=1)),
            ('bn'  , nn.BatchNorm2d(64)),
            ('relu', nn.PReLU(num_parameters=64))]))
        self.cam_down_c2  =  nn.Conv2d(64, 1, 1, stride=1)
        
        self.cam_conv3_1  = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(576, 256, 3, stride=1, padding=1)),
            ('bn'  , nn.BatchNorm2d(256)),
            ('relu', nn.PReLU(num_parameters=256))]))
        self.cam3         = CAM_Module(256)
        self.cam_conv3_2  = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(256, 128, 3, stride=1, padding=1)),
            ('bn'  , nn.BatchNorm2d(128)),
            ('relu', nn.PReLU(num_parameters=128))]))
        self.cam_drop3    = nn.Dropout2d(0.1, False)
        self.cam_conv3_3  = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(128, 64, 1, stride=1)),
            ('bn'  , nn.BatchNorm2d(64)),
            ('relu', nn.PReLU(num_parameters=64))]))
        self.cam_down_c3  =  nn.Conv2d(64, 1, 1, stride=1)

        self.cam_conv4_1  = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(1056, 512, 3, stride=1, padding=1)),
            ('bn'  , nn.BatchNorm2d(512)),
            ('relu', nn.PReLU(num_parameters=512))]))
        self.cam4         = CAM_Module(512)
        self.cam_conv4_2  = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(512, 256, 3, stride=1, padding=1)),
            ('bn'  , nn.BatchNorm2d(256)),
            ('relu', nn.PReLU(num_parameters=256))]))
        self.cam_drop4    = nn.Dropout2d(0.1, False)
        self.cam_conv4_3  = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(256, 64, 1, stride=1)),
            ('bn'  , nn.BatchNorm2d(64)),
            ('relu', nn.PReLU(num_parameters=64))]))
        self.cam_down_c4  =  nn.Conv2d(64, 1, 1, stride=1)
        
        self.cam_conv5_1  = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(256, 128, 3, stride=1, padding=1)),
            ('bn'  , nn.BatchNorm2d(128)),
            ('relu', nn.PReLU(num_parameters=128))]))
        self.cam5         = CAM_Module(128)
        self.cam_conv5_2  = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(128, 64, 3, stride=1, padding=1)),
            ('bn'  , nn.BatchNorm2d(64)),
            ('relu', nn.PReLU(num_parameters=64))]))
        self.cam_drop5    = nn.Dropout2d(0.1, False)
        self.cam_conv5_3  = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(64, 32, 1, stride=1)),
            ('bn'  , nn.BatchNorm2d(32)),
            ('relu', nn.PReLU(num_parameters=32))]))
        self.cam_down_c5  =  nn.Conv2d(32, 1, 1, stride=1)

        self.conv_cat_1 = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(32, 32, 3, stride=1, padding=1)),
            ('bn'  , nn.BatchNorm2d(32)),
            ('relu', nn.PReLU(num_parameters=32))]))
        self.conv_cat_2 = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(64, 16, 3, stride=1, padding=1)),
            ('bn'  , nn.BatchNorm2d(16)),
            ('relu', nn.PReLU(num_parameters=16))]))
        self.conv_cat_3 = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(64, 16, 3, stride=1, padding=1)),
            ('bn'  , nn.BatchNorm2d(16)),
            ('relu', nn.PReLU(num_parameters=16))]))
        self.conv_cat_4 = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(64, 16, 3, stride=1, padding=1)),
            ('bn'  , nn.BatchNorm2d(16)),
            ('relu', nn.PReLU(num_parameters=16))]))
        self.conv_cat_5 = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(32, 16, 3, stride=1, padding=1)),
            ('bn'  , nn.BatchNorm2d(16)),
            ('relu', nn.PReLU(num_parameters=16))]))

        self.conv_p1_0 = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(32, 32, 3, stride=1, padding=1)),
            ('relu', nn.PReLU(num_parameters=32))]))
        self.conv_p1_1 = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(32, 32, 3, stride=1, padding=1)),
            ('relu', nn.PReLU(num_parameters=32))]))
        self.conv_p1_2 = nn.Conv2d(32, 1, 1, stride=1)

        self.conv_p2_up_0 = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(16, 16, 3, stride=1, padding=1)),
            ('relu', nn.PReLU(num_parameters=16))]))
        self.conv_p2_up_1 = nn.Conv2d(16, 1, 1, stride=1)

        self.conv_p3_up_0 = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(16, 16, 3, stride=1, padding=1)),
            ('relu', nn.PReLU(num_parameters=16))]))
        self.conv_p3_up_1 = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(16, 16, 3, stride=1, padding=1)),
            ('relu', nn.PReLU(num_parameters=16))]))
        self.conv_p3_up_2 = nn.Conv2d(16, 1, 1, stride=1)

        self.conv_p4_up_0 = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(16, 16, 3, stride=1, padding=1)),
            ('relu', nn.PReLU(num_parameters=16))]))
        self.conv_p4_up_1 = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(16, 16, 3, stride=1, padding=1)),
            ('relu', nn.PReLU(num_parameters=16))]))
        self.conv_p4_up_2 = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(16, 16, 3, stride=1, padding=1)),
            ('relu', nn.PReLU(num_parameters=16))]))
        self.conv_p4_up_3 = nn.Conv2d(16, 1, 1, stride=1)

        self.conv_p5_up_0 = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(16, 16, 3, stride=1, padding=1)),
            ('relu', nn.PReLU(num_parameters=16))]))
        self.conv_p5_up_1 = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(16, 16, 3, stride=1, padding=1)),
            ('relu', nn.PReLU(num_parameters=16))]))
        self.conv_p5_up_2 = nn.Sequential(OrderedDict([
            ('conv', nn.Conv2d(16, 16, 3, stride=1, padding=1)),
            ('relu', nn.PReLU(num_parameters=16))]))
        self.conv_p5_up_3 = nn.Conv2d(16, 1, 1, stride=1)

        self.fuse         =  nn.Conv2d(36, 1, 1, stride=1)

        if pretrained:                                                         
            for key in self.state_dict():
                if 'resnet' not in key:
                    self.init_layer(key)