コード例 #1
0
    def __init__(self, backbone_path=None):
        super(BASE3_NOCL, self).__init__()
        resnext = ResNeXt101(backbone_path)
        self.layer0 = resnext.layer0
        self.layer1 = resnext.layer1
        self.layer2 = resnext.layer2
        self.layer3 = resnext.layer3
        self.layer4 = resnext.layer4

        self.conv_4 = nn.Sequential(nn.Conv2d(2048, 512, 3, 1, 1), nn.BatchNorm2d(512), nn.ReLU())
        self.conv_3 = nn.Sequential(nn.Conv2d(1024, 256, 3, 1, 1), nn.BatchNorm2d(256), nn.ReLU())
        self.conv_2 = nn.Sequential(nn.Conv2d(512, 128, 3, 1, 1), nn.BatchNorm2d(128), nn.ReLU())
        self.conv_1 = nn.Sequential(nn.Conv2d(256, 64, 3, 1, 1), nn.BatchNorm2d(64), nn.ReLU())

        self.up_4 = nn.Sequential(nn.ConvTranspose2d(512, 64, 16, 8, 4), nn.BatchNorm2d(64), nn.ReLU())
        self.up_3 = nn.Sequential(nn.ConvTranspose2d(256, 64, 8, 4, 2), nn.BatchNorm2d(64), nn.ReLU())
        self.up_2 = nn.Sequential(nn.ConvTranspose2d(128, 64, 4, 2, 1), nn.BatchNorm2d(64), nn.ReLU())
        self.up_1 = nn.Sequential(nn.Conv2d(64, 64, 1, 1, 0), nn.BatchNorm2d(64), nn.ReLU())

        self.cbam_4 = CBAM(64)
        self.cbam_3 = CBAM(64)
        self.cbam_2 = CBAM(64)
        self.cbam_1 = CBAM(64)
        self.cbam_fusion = CBAM(256)

        self.layer4_predict = Predict(64)
        self.layer3_predict = Predict(64)
        self.layer2_predict = Predict(64)
        self.layer1_predict = Predict(64)

        self.fusion_predict = nn.Conv2d(256, 1, 3, 1, 1)

        for m in self.modules():
            if isinstance(m, nn.ReLU):
                m.inplace = True
コード例 #2
0
    def __init__(self, backbone_path=None):
        super(TAYLOR5_NOC, self).__init__()
        resnext = ResNeXt101(backbone_path)
        self.layer0 = resnext.layer0
        self.layer1 = resnext.layer1
        self.layer2 = resnext.layer2
        self.layer3 = resnext.layer3
        self.layer4 = resnext.layer4

        self.contrast_4 = Contrast_Module(2048)
        self.contrast_3 = Contrast_Module(1024)
        self.contrast_2 = Contrast_Module(512)
        self.contrast_1 = Contrast_Module(256)

        self.up_4 = nn.Sequential(nn.ConvTranspose2d(2048, 512, 4, 2, 1), nn.BatchNorm2d(512), nn.ReLU())
        self.up_3 = nn.Sequential(nn.ConvTranspose2d(1024, 256, 4, 2, 1), nn.BatchNorm2d(256), nn.ReLU())
        self.up_2 = nn.Sequential(nn.ConvTranspose2d(512, 128, 4, 2, 1), nn.BatchNorm2d(128), nn.ReLU())
        self.up_1 = nn.Sequential(nn.Conv2d(256, 64, 4, 2, 1), nn.BatchNorm2d(64), nn.ReLU())

        self.cbam_4 = CBAM(512)
        self.cbam_3 = CBAM(256)
        self.cbam_2 = CBAM(128)
        self.cbam_1 = CBAM(64)

        self.layer4_predict = nn.Conv2d(512, 1, 3, 1, 1)
        self.layer3_predict = nn.Conv2d(256, 1, 3, 1, 1)
        self.layer2_predict = nn.Conv2d(128, 1, 3, 1, 1)
        self.layer1_predict = nn.Conv2d(64, 1, 3, 1, 1)

        for m in self.modules():
            if isinstance(m, nn.ReLU):
                m.inplace = True
コード例 #3
0
ファイル: base7.py プロジェクト: Mhaiyang/iccv
    def __init__(self, backbone_path=None):
        super(BASE7, self).__init__()
        resnext = ResNeXt101(backbone_path)
        self.layer0 = resnext.layer0
        self.layer1 = resnext.layer1
        self.layer2 = resnext.layer2
        self.layer3 = resnext.layer3
        self.layer4 = resnext.layer4

        # Mirror Region Stream
        self.f_ccl_4 = CCL(2048, 512, 2)
        self.f_ccl_3 = CCL(1024, 256, 3)
        self.f_ccl_2 = CCL(512, 128, 4)
        self.f_ccl_1 = CCL(256, 64, 5)
        self.f_ccl_0 = CCL(64, 32, 6)

        self.f_fixed_4 = nn.Sequential(nn.BatchNorm2d(512), nn.ReLU(), nn.ConvTranspose2d(512, 64, 16, 8, 4),
                                       nn.BatchNorm2d(64), nn.ReLU())
        self.f_fixed_3 = nn.Sequential(nn.BatchNorm2d(256), nn.ReLU(), nn.ConvTranspose2d(256, 64, 8, 4, 2),
                                       nn.BatchNorm2d(64), nn.ReLU())
        self.f_fixed_2 = nn.Sequential(nn.BatchNorm2d(128), nn.ReLU(), nn.ConvTranspose2d(128, 64, 4, 2, 1),
                                       nn.BatchNorm2d(64), nn.ReLU())
        self.f_fixed_1 = nn.Sequential(nn.BatchNorm2d(64), nn.ReLU(), nn.Conv2d(64, 64, 3, 1, 1),
                                       nn.BatchNorm2d(64), nn.ReLU())
        self.f_fixed_0 = nn.Sequential(nn.BatchNorm2d(32), nn.ReLU(), nn.Conv2d(32, 64, 4, 2, 1),
                                       nn.BatchNorm2d(64), nn.ReLU())
        self.f_attention = CBAM(320)

        self.f_predict = nn.Conv2d(320, 1, 3, 1, 1)
        # self.f_predict = nn.Sequential(nn.BatchNorm2d(320), nn.ReLU(), nn.Conv2d(320, 1, 3, 1, 1))

        # Non-Mirror Region Stream
        self.b_ccl_4 = CCL(2048, 512, 2)
        self.b_ccl_3 = CCL(1024, 256, 3)
        self.b_ccl_2 = CCL(512, 128, 4)
        self.b_ccl_1 = CCL(256, 64, 5)
        self.b_ccl_0 = CCL(64, 32, 6)

        self.b_fixed_4 = nn.Sequential(nn.BatchNorm2d(512), nn.ReLU(), nn.ConvTranspose2d(512, 64, 16, 8, 4),
                                       nn.BatchNorm2d(64), nn.ReLU())
        self.b_fixed_3 = nn.Sequential(nn.BatchNorm2d(256), nn.ReLU(), nn.ConvTranspose2d(256, 64, 8, 4, 2),
                                       nn.BatchNorm2d(64), nn.ReLU())
        self.b_fixed_2 = nn.Sequential(nn.BatchNorm2d(128), nn.ReLU(), nn.ConvTranspose2d(128, 64, 4, 2, 1),
                                       nn.BatchNorm2d(64), nn.ReLU())
        self.b_fixed_1 = nn.Sequential(nn.BatchNorm2d(64), nn.ReLU(), nn.Conv2d(64, 64, 3, 1, 1),
                                       nn.BatchNorm2d(64), nn.ReLU())
        self.b_fixed_0 = nn.Sequential(nn.BatchNorm2d(32), nn.ReLU(), nn.Conv2d(32, 64, 4, 2, 1),
                                       nn.BatchNorm2d(64), nn.ReLU())
        self.b_attention = CBAM(320)

        self.b_predict = nn.Conv2d(320, 1, 3, 1, 1)
        # self.b_predict = nn.Sequential(nn.BatchNorm2d(320), nn.ReLU(), nn.Conv2d(320, 1, 3, 1, 1))

        # Feature Mosaic
        self.output_predict = nn.Conv2d(320, 1, 1)
        # self.output_predict = nn.Sequential(nn.BatchNorm2d(320), nn.ReLU(), nn.Conv2d(320, 1, 3, 1, 1))

        for m in self.modules():
            if isinstance(m, nn.ReLU):
                m.inplace = True
コード例 #4
0
    def __init__(self, args, backbone_path=None):
        super(LitMirrorNet, self).__init__()
        # global test_iter
        # test_iter = 0
        resnext = ResNeXt101(backbone_path)
        self.val_iter = 0
        self.test_iter = 0
        self.args = args
        self.testing_path = args.msd_testing_root
        self.training_path = args.msd_training_root
        self.eval_path = args.msd_eval_root

        self.layer0 = resnext.layer0
        self.layer1 = resnext.layer1
        self.layer2 = resnext.layer2
        self.layer3 = resnext.layer3
        self.layer4 = resnext.layer4

        self.contrast_4 = Contrast_Module(2048)
        self.contrast_3 = Contrast_Module(1024)
        self.contrast_2 = Contrast_Module(512)
        self.contrast_1 = Contrast_Module(256)

        self.up_4 = nn.Sequential(nn.ConvTranspose2d(2048, 512, 4, 2, 1),
                                  nn.BatchNorm2d(512), nn.ReLU())
        self.up_3 = nn.Sequential(nn.ConvTranspose2d(1024, 256, 4, 2, 1),
                                  nn.BatchNorm2d(256), nn.ReLU())
        self.up_2 = nn.Sequential(nn.ConvTranspose2d(512, 128, 4, 2, 1),
                                  nn.BatchNorm2d(128), nn.ReLU())
        self.up_1 = nn.Sequential(nn.Conv2d(256, 64, 4, 2, 1),
                                  nn.BatchNorm2d(64), nn.ReLU())

        self.cbam_4 = CBAM(512)
        self.cbam_3 = CBAM(256)
        self.cbam_2 = CBAM(128)
        self.cbam_1 = CBAM(64)

        self.layer4_predict = nn.Conv2d(512, 1, 3, 1, 1)
        self.layer3_predict = nn.Conv2d(256, 1, 3, 1, 1)
        self.layer2_predict = nn.Conv2d(128, 1, 3, 1, 1)
        self.layer1_predict = nn.Conv2d(64, 1, 3, 1, 1)

        for m in self.modules():
            if isinstance(m, nn.ReLU):
                m.inplace = True

        ###############################
        # Defining the transoformations
        self.img_transform = transforms.Compose([
            transforms.Resize((self.args.scale, self.args.scale)),
            transforms.ToTensor(),
            transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
        ])
        self.mask_transform = transforms.Compose([
            transforms.Resize((self.args.scale, self.args.scale)),
            transforms.ToTensor()
        ])
コード例 #5
0
ファイル: base2.py プロジェクト: Mhaiyang/iccv
    def __init__(self):
        super(BASE2, self).__init__()
        resnext = ResNeXt101()
        self.layer0 = resnext.layer0
        self.layer1 = resnext.layer1
        self.layer2 = resnext.layer2
        self.layer3 = resnext.layer3
        self.layer4 = resnext.layer4

        self.ccl_4 = CCL(2048, 512, 2)
        self.ccl_3 = CCL(1024, 256, 3)
        self.ccl_2 = CCL(512, 128, 4)
        self.ccl_1 = CCL(256, 64, 5)

        self.sc_4 = nn.Conv2d(2048, 512, 1)
        self.sc_3 = nn.Conv2d(1024, 256, 1)
        self.sc_2 = nn.Conv2d(512, 128, 1)
        self.sc_1 = nn.Conv2d(256, 64, 1)

        self.layer4_fusion = nn.Sequential(
            nn.Conv2d(1024, 512, 1),
            nn.BatchNorm2d(512), nn.ReLU()
        )
        self.layer3_fusion = nn.Sequential(
            nn.Conv2d(512, 256, 1),
            nn.BatchNorm2d(256), nn.ReLU()
        )
        self.layer2_fusion = nn.Sequential(
            nn.Conv2d(256, 128, 1),
            nn.BatchNorm2d(128), nn.ReLU()
        )
        self.layer1_fusion = nn.Sequential(
            nn.Conv2d(128, 64, 1),
            nn.BatchNorm2d(64), nn.ReLU()
        )

        self.cbam_4 = CBAM(512)
        self.cbam_3 = CBAM(256)
        self.cbam_2 = CBAM(128)
        self.cbam_1 = CBAM(64)
        self.cbam_fusion = CBAM(256)

        self.up_4 = nn.ConvTranspose2d(512, 64, 16, 8, 4)
        self.up_3 = nn.ConvTranspose2d(256, 64, 8, 4, 2)
        self.up_2 = nn.ConvTranspose2d(128, 64, 4, 2, 1)
        self.up_1 = nn.Conv2d(64, 64, 1, 1, 0)

        self.layer4_predict = Predict(512)
        self.layer3_predict = Predict(256)
        self.layer2_predict = Predict(128)
        self.layer1_predict = Predict(64)

        self.fusion_predict = Predict(256)

        for m in self.modules():
            if isinstance(m, nn.ReLU):
                m.inplace = True
コード例 #6
0
ファイル: pmd.py プロジェクト: tmn04/PMD2020_2
    def __init__(self, backbone_path=None):
        super(PMD, self).__init__()
        resnext = ResNeXt101(backbone_path)
        self.layer0 = resnext.layer0
        self.layer1 = resnext.layer1
        self.layer2 = resnext.layer2
        self.layer3 = resnext.layer3
        self.layer4 = resnext.layer4

        self.edge_extract = nn.Sequential(nn.Conv2d(256, 128, 3, 1, 1),
                                          nn.BatchNorm2d(128),
                                          nn.Conv2d(128, 64, 3, 1, 1),
                                          nn.BatchNorm2d(64))

        self.edge_predict = nn.Sequential(nn.Conv2d(64 + 512, 1, 3, 1, 1))

        self.contrast_4 = Contrast_Module_Deep(2048, d1=2, d2=4)  # 2048x 12x12
        self.contrast_3 = Contrast_Module_Deep(1024, d1=4, d2=8)  # 1024x 24x24
        self.contrast_2 = Contrast_Module_Deep(512, d1=4, d2=8)  # 512x 48x48
        self.contrast_1 = Contrast_Module_Deep(256, d1=4, d2=8)  # 256x 96x96

        self.ra_4 = Relation_Attention(2048, 2048)
        self.ra_3 = Relation_Attention(1024, 1024)
        self.ra_2 = Relation_Attention(512, 512)
        self.ra_1 = Relation_Attention(256, 256)

        self.up_4 = nn.Sequential(nn.ConvTranspose2d(2048, 512, 4, 2, 1),
                                  nn.BatchNorm2d(512), nn.ReLU())
        self.up_3 = nn.Sequential(nn.ConvTranspose2d(1024, 256, 4, 2, 1),
                                  nn.BatchNorm2d(256), nn.ReLU())
        self.up_2 = nn.Sequential(nn.ConvTranspose2d(512, 128, 4, 2, 1),
                                  nn.BatchNorm2d(128), nn.ReLU())
        self.up_1 = nn.Sequential(nn.ConvTranspose2d(256, 64, 4, 2, 1),
                                  nn.BatchNorm2d(64), nn.ReLU())

        self.cbam_4 = CBAM(512)
        self.cbam_3 = CBAM(256)
        self.cbam_2 = CBAM(128)
        self.cbam_1 = CBAM(64)

        self.layer4_predict = nn.Conv2d(512, 1, 3, 1, 1)
        self.layer3_predict = nn.Conv2d(256, 1, 3, 1, 1)
        self.layer2_predict = nn.Conv2d(128, 1, 3, 1, 1)
        self.layer1_predict = nn.Conv2d(64, 1, 3, 1, 1)

        # self.refinement = Refinement_Net(1+1+3)
        # self.refinement = RCCAModule(1+1+3, 512, 1)
        self.refinement = nn.Conv2d(1 + 1 + 3 + 1 + 1 + 1, 1, 1, 1, 0)

        for m in self.modules():
            if isinstance(m, nn.ReLU):
                m.inplace = True
コード例 #7
0
ファイル: DSC.py プロジェクト: xw-hu/DSC-PyTorch
    def __init__(self):
        super(DSC, self).__init__()

        resnext = ResNeXt101()
        self.layer0 = resnext.layer0
        self.layer1 = resnext.layer1
        self.layer2 = resnext.layer2
        self.layer3 = resnext.layer3
        self.layer4 = resnext.layer4

        self.layer4_conv1 = LayerConv(2048, 512, 7, 1, 3, True)
        self.layer4_conv2 = LayerConv(512, 512, 7, 1, 3, True)
        self.layer4_dsc = DSC_Module(512, 512)
        self.layer4_conv3 = LayerConv(1024, 32, 1, 1, 0, False)

        self.layer3_conv1 = LayerConv(1024, 256, 5, 1, 2, True)
        self.layer3_conv2 = LayerConv(256, 256, 5, 1, 2, True)
        self.layer3_dsc = DSC_Module(256, 256)
        self.layer3_conv3 = LayerConv(512, 32, 1, 1, 0, False)

        self.layer2_conv1 = LayerConv(512, 128, 5, 1, 2, True)
        self.layer2_conv2 = LayerConv(128, 128, 5, 1, 2, True)
        self.layer2_dsc = DSC_Module(128, 128)
        self.layer2_conv3 = LayerConv(256, 32, 1, 1, 0, False)

        self.layer1_conv1 = LayerConv(256, 64, 3, 1, 1, True)
        self.layer1_conv2 = LayerConv(64, 64, 3, 1, 1, True)
        self.layer1_dsc = DSC_Module(64, 64, alpha=0.8)
        self.layer1_conv3 = LayerConv(128, 32, 1, 1, 0, False)

        self.layer0_conv1 = LayerConv(64, 64, 3, 1, 1, True)
        self.layer0_conv2 = LayerConv(64, 64, 3, 1, 1, True)
        self.layer0_dsc = DSC_Module(64, 64, alpha=0.8)
        self.layer0_conv3 = LayerConv(128, 32, 1, 1, 0, False)

        self.relu = nn.ReLU()

        self.global_conv = LayerConv(160, 32, 1, 1, 0, True)

        self.layer4_predict = Predict(32, 1, 1)
        self.layer3_predict_ori = Predict(32, 1, 1)
        self.layer3_predict = Predict(2, 1, 1)
        self.layer2_predict_ori = Predict(32, 1, 1)
        self.layer2_predict = Predict(3, 1, 1)
        self.layer1_predict_ori = Predict(32, 1, 1)
        self.layer1_predict = Predict(4, 1, 1)
        self.layer0_predict_ori = Predict(32, 1, 1)
        self.layer0_predict = Predict(5, 1, 1)
        self.global_predict = Predict(32, 1, 1)
        self.fusion_predict = Predict(6, 1, 1)
コード例 #8
0
    def __init__(self):
        super(DSC, self).__init__()
        resnext = ResNeXt101()
        self.layer0 = resnext.layer0
        self.layer1 = resnext.layer1
        self.layer2 = resnext.layer2
        self.layer3 = resnext.layer3
        self.layer4 = resnext.layer4

        self.layer4_conv1 = LayerConv(2048, 1024, 7, 1, 3, True)
        self.layer4_conv2 = LayerConv(1024, 1024, 7, 1, 3, True)
        self.layer4_conv3 = LayerConv(1024, 32, 1, 1, 0, False)

        self.layer3_conv1 = LayerConv(1024, 512, 5, 1, 2, True)
        self.layer3_conv2 = LayerConv(512, 512, 5, 1, 2, True)
        self.layer3_conv3 = LayerConv(512, 32, 1, 1, 0, False)

        self.layer2_conv1 = LayerConv(512, 256, 5, 1, 2, True)
        self.layer2_conv2 = LayerConv(256, 256, 5, 1, 2, True)
        self.layer2_conv3 = LayerConv(256, 32, 1, 1, 0, False)

        self.layer1_conv1 = LayerConv(256, 128, 3, 1, 1, True)
        self.layer1_conv2 = LayerConv(128, 128, 3, 1, 1, True)
        self.layer1_conv3 = LayerConv(128, 32, 1, 1, 0, False)

        self.layer0_conv1 = LayerConv(64, 128, 3, 1, 1, True)
        self.layer0_conv2 = LayerConv(128, 128, 3, 1, 1, True)
        self.layer0_conv3 = LayerConv(128, 32, 1, 1, 0, False)

        self.relu = nn.ReLU()

        self.global_conv = GlobalConv(160, 32, 1, 1, 0, True)

        self.layer4_predict = Predict(32, 1, 1)
        self.layer3_predict_ori = Predict(32, 1, 1)
        self.layer3_predict = Predict(2, 1, 1)
        self.layer2_predict_ori = Predict(32, 1, 1)
        self.layer2_predict = Predict(3, 1, 1)
        self.layer1_predict_ori = Predict(32, 1, 1)
        self.layer1_predict = Predict(4, 1, 1)
        self.layer0_predict_ori = Predict(32, 1, 1)
        self.layer0_predict = Predict(5, 1, 1)
        self.global_predict = Predict(32, 1, 1)
        self.fusion_predict = Predict(6, 1, 1)

        for m in self.modules():
            if isinstance(m, nn.ReLU):
                m.inplace = True
コード例 #9
0
ファイル: fuse.py プロジェクト: Mhaiyang/iccv
    def __init__(self, backbone_path=None):
        super(FUSE, self).__init__()
        resnext = ResNeXt101()
        self.layer0 = resnext.layer0
        self.layer1 = resnext.layer1
        self.layer2 = resnext.layer2
        self.layer3 = resnext.layer3
        self.layer4 = resnext.layer4

        self.cbam512 = CBAM(512)
        self.cbam256 = CBAM(256)
        self.cbam128 = CBAM(128)
        self.cbam64 = CBAM(64)

        self.f3 = Up(2048, 512, 1024, 512)
        self.f2 = Up(512, 256, 512, 256)
        self.f1 = Up(256, 128, 256, 128)
        self.f0 = Up(128, 64, 64, 64)

        self.b3 = Up(2048, 512, 1024, 512)
        self.b2 = Up(512, 256, 512, 256)
        self.b1 = Up(256, 128, 256, 128)
        self.b0 = Up(128, 64, 64, 64)

        self.e3 = Up(2048, 512, 1024, 512)
        self.e2 = Up(512, 256, 512, 256)
        self.e1 = Up(256, 128, 256, 128)
        self.e0 = Up(128, 64, 64, 64)

        self.predict_f3 = Predict(512)
        self.predict_f2 = Predict(256)
        self.predict_f1 = Predict(128)
        self.predict_f0 = Predict(64)

        self.predict_b3 = Predict(512)
        self.predict_b2 = Predict(256)
        self.predict_b1 = Predict(128)
        self.predict_b0 = Predict(64)

        self.predict_edge = nn.Conv2d(64, 1, 3, 1, padding=1)

        self.predict_fb = Fuse()

        for m in self.modules():
            if isinstance(m, nn.ReLU):
                m.inplace = True
コード例 #10
0
ファイル: gdnet.py プロジェクト: tuyaliang/CVPR2020_GDNet
    def __init__(self, backbone_path=None):
        super(GDNet, self).__init__()
        # params

        # backbone
        resnext = ResNeXt101(backbone_path)
        self.layer0 = resnext.layer0
        self.layer1 = resnext.layer1
        self.layer2 = resnext.layer2
        self.layer3 = resnext.layer3
        self.layer4 = resnext.layer4

        self.h5_conv = LCFI(2048, 1, 2, 3, 4)
        self.h4_conv = LCFI(1024, 1, 2, 3, 4)
        self.h3_conv = LCFI(512, 1, 2, 3, 4)
        self.l2_conv = LCFI(256, 1, 2, 3, 4)

        # h fusion
        self.h5_up = nn.UpsamplingBilinear2d(scale_factor=2)
        self.h3_down = nn.AvgPool2d((2, 2), stride=2)
        self.h_fusion = CBAM(896)
        self.h_fusion_conv = nn.Sequential(nn.Conv2d(896, 896, 3, 1, 1),
                                           nn.BatchNorm2d(896), nn.ReLU())

        # l fusion
        self.l_fusion_conv = nn.Sequential(nn.Conv2d(64, 64, 3, 1, 1),
                                           nn.BatchNorm2d(64), nn.ReLU())
        self.h2l = nn.ConvTranspose2d(896, 1, 8, 4, 2)

        # final fusion
        self.h_up_for_final_fusion = nn.ConvTranspose2d(896, 256, 8, 4, 2)
        self.final_fusion = CBAM(320)
        self.final_fusion_conv = nn.Sequential(nn.Conv2d(320, 320, 3, 1, 1),
                                               nn.BatchNorm2d(320), nn.ReLU())

        # predict conv
        self.h_predict = nn.Conv2d(896, 1, 3, 1, 1)
        self.l_predict = nn.Conv2d(64, 1, 3, 1, 1)
        self.final_predict = nn.Conv2d(320, 1, 3, 1, 1)

        for m in self.modules():
            if isinstance(m, nn.ReLU):
                m.inplace = True
コード例 #11
0
ファイル: base6.py プロジェクト: Mhaiyang/iccv
    def __init__(self, backbone_path=None):
        super(BASE6, self).__init__()
        resnext = ResNeXt101(backbone_path)
        self.layer0 = resnext.layer0
        self.layer1 = resnext.layer1
        self.layer2 = resnext.layer2
        self.layer3 = resnext.layer3
        self.layer4 = resnext.layer4

        # Context Stream
        self.ccl_4 = CCL(2048, 512, 2)
        self.ccl_3 = CCL(1024, 256, 3)
        self.ccl_2 = CCL(512, 128, 4)
        self.ccl_1 = CCL(256, 64, 5)
        self.ccl_0 = CCL(64, 32, 6)

        self.context_fixed_4 = nn.Sequential(
            nn.BatchNorm2d(512), nn.ReLU(),
            nn.ConvTranspose2d(512, 64, 16, 8, 4), nn.BatchNorm2d(64),
            nn.ReLU())
        self.context_fixed_3 = nn.Sequential(
            nn.BatchNorm2d(256), nn.ReLU(),
            nn.ConvTranspose2d(256, 64, 8, 4,
                               2), nn.BatchNorm2d(64), nn.ReLU())
        self.context_fixed_2 = nn.Sequential(
            nn.BatchNorm2d(128), nn.ReLU(),
            nn.ConvTranspose2d(128, 64, 4, 2,
                               1), nn.BatchNorm2d(64), nn.ReLU())
        self.context_fixed_1 = nn.Sequential(nn.BatchNorm2d(64), nn.ReLU(),
                                             nn.Conv2d(64, 64, 3, 1, 1),
                                             nn.BatchNorm2d(64), nn.ReLU())
        self.context_fixed_0 = nn.Sequential(nn.BatchNorm2d(32), nn.ReLU(),
                                             nn.Conv2d(32, 64, 4, 2, 1),
                                             nn.BatchNorm2d(64), nn.ReLU())
        self.context_attention = CBAM(320)

        self.context_predict = nn.Conv2d(320, 1, 3, 1, 1)

        # Boundary Stream
        self.boundary_conv_4 = nn.Conv2d(2048, 512, 3, 1, 1)
        self.boundary_conv_3 = nn.Conv2d(1024, 256, 3, 1, 1)
        self.boundary_conv_2 = nn.Conv2d(512, 128, 3, 1, 1)
        self.boundary_conv_1 = nn.Conv2d(256, 64, 3, 1, 1)
        self.boundary_conv_0 = nn.Conv2d(64, 32, 3, 1, 1)

        self.boundary_fixed_4 = nn.Sequential(
            nn.BatchNorm2d(512), nn.ReLU(),
            nn.ConvTranspose2d(512, 32, 16, 8, 4), nn.BatchNorm2d(32),
            nn.ReLU())
        self.boundary_fixed_3 = nn.Sequential(
            nn.BatchNorm2d(256), nn.ReLU(),
            nn.ConvTranspose2d(256, 32, 8, 4,
                               2), nn.BatchNorm2d(32), nn.ReLU())
        self.boundary_fixed_2 = nn.Sequential(
            nn.BatchNorm2d(128), nn.ReLU(),
            nn.ConvTranspose2d(128, 32, 4, 2,
                               1), nn.BatchNorm2d(32), nn.ReLU())
        self.boundary_fixed_1 = nn.Sequential(nn.BatchNorm2d(64), nn.ReLU(),
                                              nn.Conv2d(64, 32, 3, 1, 1),
                                              nn.BatchNorm2d(32), nn.ReLU())
        self.boundary_fixed_0 = nn.Sequential(nn.BatchNorm2d(32), nn.ReLU(),
                                              nn.Conv2d(32, 32, 4, 2, 1),
                                              nn.BatchNorm2d(32), nn.ReLU())

        self.boundary_attention = CBAM(160)

        self.boundary_predict = nn.Conv2d(160, 1, 3, 1, 1)

        # Attention Fusion
        self.attention_fusion = CBAM(480)

        self.output_predict = nn.Conv2d(480, 1, 3, 1, 1)

        for m in self.modules():
            if isinstance(m, nn.ReLU):
                m.inplace = True
コード例 #12
0
    def __init__(self):
        super(BASE, self).__init__()
        resnext = ResNeXt101()
        self.layer0 = resnext.layer0
        self.layer1 = resnext.layer1
        self.layer2 = resnext.layer2
        self.layer3 = resnext.layer3
        self.layer4 = resnext.layer4

        self.ccl = CCL(2048, 512)

        self.cbam_4 = CBAM(512)
        self.cbam_3 = CBAM(512)
        self.cbam_2 = CBAM(256)
        self.cbam_1 = CBAM(256)
        self.cbam_0 = CBAM(128)

        self.up_4 = nn.ConvTranspose2d(512, 512, 4, 2, 1)
        self.up_3 = nn.ConvTranspose2d(512, 256, 4, 2, 1)
        self.up_2 = nn.ConvTranspose2d(256, 256, 4, 2, 1)
        self.up_1 = nn.ConvTranspose2d(256, 128, 4, 2, 1)

        self.sc_3 = nn.Conv2d(1024, 512, 1)
        self.sc_2 = nn.Conv2d(512, 256, 1)
        self.sc_1 = nn.Conv2d(256, 256, 1)
        self.sc_0 = nn.Conv2d(64, 128, 1)

        self.activation_3 = Activation(512)
        self.activation_2 = Activation(256)
        self.activation_1 = Activation(256)
        self.activation_0 = Activation(128)

        self.layer4_feature = nn.Sequential(
            nn.ConvTranspose2d(512, 32, 64, 32, 16), nn.BatchNorm2d(32),
            nn.ReLU())
        self.layer3_feature = nn.Sequential(
            nn.ConvTranspose2d(512, 32, 32, 16, 8), nn.BatchNorm2d(32),
            nn.ReLU())
        self.layer2_feature = nn.Sequential(
            nn.ConvTranspose2d(256, 32, 16, 8, 4), nn.BatchNorm2d(32),
            nn.ReLU())
        self.layer1_feature = nn.Sequential(
            nn.ConvTranspose2d(256, 32, 8, 4, 2), nn.BatchNorm2d(32),
            nn.ReLU())
        self.layer0_feature = nn.Sequential(
            nn.ConvTranspose2d(128, 32, 4, 2, 1), nn.BatchNorm2d(32),
            nn.ReLU())

        self.layer4_predict = nn.Conv2d(32, 1, 1)
        self.layer3_predict = nn.Conv2d(32, 1, 1)
        self.layer2_predict = nn.Conv2d(32, 1, 1)
        self.layer1_predict = nn.Conv2d(32, 1, 1)
        self.layer0_predict = nn.Conv2d(32, 1, 1)

        self.global_predict = nn.Conv2d(160, 1, 1)

        self.fusion_predict = nn.Conv2d(5, 1, 1)

        for m in self.modules():
            if isinstance(m, nn.ReLU):
                m.inplace = True
コード例 #13
0
    def __init__(self, backbone_path=None):
        super(BASE8, self).__init__()
        resnext = ResNeXt101(backbone_path)
        self.layer0 = resnext.layer0
        self.layer1 = resnext.layer1
        self.layer2 = resnext.layer2
        self.layer3 = resnext.layer3
        self.layer4 = resnext.layer4

        # Mirror Region Stream
        self.f_ccl_4 = CCL(2048, 512, 2)
        self.f_ccl_3 = CCL(1024, 256, 3)
        self.f_ccl_2 = CCL(512, 128, 4)
        self.f_ccl_1 = CCL(256, 64, 5)

        self.f_sc_4 = nn.Conv2d(2048, 512, 1)
        self.f_sc_3 = nn.Conv2d(1024, 256, 1)
        self.f_sc_2 = nn.Conv2d(512, 128, 1)
        self.f_sc_1 = nn.Conv2d(256, 64, 1)

        self.f_fusion_4 = nn.Sequential(nn.Conv2d(1024, 512, 1), nn.BatchNorm2d(512), nn.ReLU())
        self.f_fusion_3 = nn.Sequential(nn.Conv2d(512, 256, 1), nn.BatchNorm2d(256), nn.ReLU())
        self.f_fusion_2 = nn.Sequential(nn.Conv2d(256, 128, 1), nn.BatchNorm2d(128), nn.ReLU())
        self.f_fusion_1 = nn.Sequential(nn.Conv2d(128, 64, 1), nn.BatchNorm2d(64), nn.ReLU())

        self.f_up_4 = nn.Sequential(nn.ConvTranspose2d(512, 64, 16, 8, 4), nn.BatchNorm2d(64), nn.ReLU())
        self.f_up_3 = nn.Sequential(nn.ConvTranspose2d(256, 64, 8, 4, 2), nn.BatchNorm2d(64), nn.ReLU())
        self.f_up_2 = nn.Sequential(nn.ConvTranspose2d(128, 64, 4, 2, 1), nn.BatchNorm2d(64), nn.ReLU())
        self.f_up_1 = nn.Sequential(nn.Conv2d(64, 64, 1, 1, 0), nn.BatchNorm2d(64), nn.ReLU())

        self.f_cbam_4 = CBAM(64)
        self.f_cbam_3 = CBAM(64)
        self.f_cbam_2 = CBAM(64)
        self.f_cbam_1 = CBAM(64)
        self.f_cbam_concat = CBAM(256)

        self.f_predict_4 = Predict(64)
        self.f_predict_3 = Predict(64)
        self.f_predict_2 = Predict(64)
        self.f_predict_1 = Predict(64)
        self.f_predict_concat = nn.Conv2d(256, 1, 3, 1, 1)

        # Non-Mirror Region Stream
        self.b_ccl_4 = CCL(2048, 512, 2)
        self.b_ccl_3 = CCL(1024, 256, 3)
        self.b_ccl_2 = CCL(512, 128, 4)
        self.b_ccl_1 = CCL(256, 64, 5)

        self.b_sc_4 = nn.Conv2d(2048, 512, 1)
        self.b_sc_3 = nn.Conv2d(1024, 256, 1)
        self.b_sc_2 = nn.Conv2d(512, 128, 1)
        self.b_sc_1 = nn.Conv2d(256, 64, 1)

        self.b_fusion_4 = nn.Sequential(nn.Conv2d(1024, 512, 1), nn.BatchNorm2d(512), nn.ReLU())
        self.b_fusion_3 = nn.Sequential(nn.Conv2d(512, 256, 1), nn.BatchNorm2d(256), nn.ReLU())
        self.b_fusion_2 = nn.Sequential(nn.Conv2d(256, 128, 1), nn.BatchNorm2d(128), nn.ReLU())
        self.b_fusion_1 = nn.Sequential(nn.Conv2d(128, 64, 1), nn.BatchNorm2d(64), nn.ReLU())

        self.b_up_4 = nn.Sequential(nn.ConvTranspose2d(512, 64, 16, 8, 4), nn.BatchNorm2d(64), nn.ReLU())
        self.b_up_3 = nn.Sequential(nn.ConvTranspose2d(256, 64, 8, 4, 2), nn.BatchNorm2d(64), nn.ReLU())
        self.b_up_2 = nn.Sequential(nn.ConvTranspose2d(128, 64, 4, 2, 1), nn.BatchNorm2d(64), nn.ReLU())
        self.b_up_1 = nn.Sequential(nn.Conv2d(64, 64, 1, 1, 0), nn.BatchNorm2d(64), nn.ReLU())

        self.b_cbam_4 = CBAM(64)
        self.b_cbam_3 = CBAM(64)
        self.b_cbam_2 = CBAM(64)
        self.b_cbam_1 = CBAM(64)
        self.b_cbam_concat = CBAM(256)

        self.b_predict_4 = Predict(64)
        self.b_predict_3 = Predict(64)
        self.b_predict_2 = Predict(64)
        self.b_predict_1 = Predict(64)
        self.b_predict_concat = nn.Conv2d(256, 1, 3, 1, 1)

        # Feature Mosaic
        # self.output_predict = nn.Conv2d(256, 1, 3, 1, 1)

        for m in self.modules():
            if isinstance(m, nn.ReLU):
                m.inplace = True
コード例 #14
0
ファイル: base9.py プロジェクト: Mhaiyang/iccv
    def __init__(self, backbone_path=None):
        super(BASE9, self).__init__()
        resnext = ResNeXt101(backbone_path)
        self.layer0 = resnext.layer0
        self.layer1 = resnext.layer1
        self.layer2 = resnext.layer2
        self.layer3 = resnext.layer3
        self.layer4 = resnext.layer4

        # Context Stream
        self.context_ccl_4 = CCL(2048, 512, 2)
        self.context_ccl_3 = CCL(1024, 256, 3)
        self.context_ccl_2 = CCL(512, 128, 4)
        self.context_ccl_1 = CCL(256, 64, 5)

        self.context_sc_4 = nn.Conv2d(2048, 512, 1)
        self.context_sc_3 = nn.Conv2d(1024, 256, 1)
        self.context_sc_2 = nn.Conv2d(512, 128, 1)
        self.context_sc_1 = nn.Conv2d(256, 64, 1)

        self.context_fusion_4 = nn.Sequential(nn.Conv2d(1024, 512, 1), nn.BatchNorm2d(512), nn.ReLU())
        self.context_fusion_3 = nn.Sequential(nn.Conv2d(512, 256, 1), nn.BatchNorm2d(256), nn.ReLU())
        self.context_fusion_2 = nn.Sequential(nn.Conv2d(256, 128, 1), nn.BatchNorm2d(128), nn.ReLU())
        self.context_fusion_1 = nn.Sequential(nn.Conv2d(128, 64, 1), nn.BatchNorm2d(64), nn.ReLU())

        self.context_up_4 = nn.Sequential(nn.ConvTranspose2d(512, 64, 16, 8, 4), nn.BatchNorm2d(64), nn.ReLU())
        self.context_up_3 = nn.Sequential(nn.ConvTranspose2d(256, 64, 8, 4, 2), nn.BatchNorm2d(64), nn.ReLU())
        self.context_up_2 = nn.Sequential(nn.ConvTranspose2d(128, 64, 4, 2, 1), nn.BatchNorm2d(64), nn.ReLU())
        self.context_up_1 = nn.Sequential(nn.Conv2d(64, 64, 1, 1, 0), nn.BatchNorm2d(64), nn.ReLU())

        self.context_cbam_4 = CBAM(64)
        self.context_cbam_3 = CBAM(64)
        self.context_cbam_2 = CBAM(64)
        self.context_cbam_1 = CBAM(64)
        self.context_cbam_concat = CBAM(256)

        self.context_predict_4 = Predict(64)
        self.context_predict_3 = Predict(64)
        self.context_predict_2 = Predict(64)
        self.context_predict_1 = Predict(64)
        self.context_predict_concat = nn.Conv2d(256, 1, 3, 1, 1)

        # Boundary Stream
        self.boundary_conv_4 = nn.Sequential(nn.Conv2d(2048, 256, 3, 1, 1), nn.BatchNorm2d(256), nn.ReLU())
        self.boundary_conv_3 = nn.Sequential(nn.Conv2d(1024, 128, 3, 1, 1), nn.BatchNorm2d(128), nn.ReLU())
        self.boundary_conv_2 = nn.Sequential(nn.Conv2d(512, 64, 3, 1, 1), nn.BatchNorm2d(64), nn.ReLU())
        self.boundary_conv_1 = nn.Sequential(nn.Conv2d(256, 32, 3, 1, 1), nn.BatchNorm2d(32), nn.ReLU())

        self.boundary_up_4 = nn.Sequential(nn.ConvTranspose2d(256, 32, 16, 8, 4), nn.BatchNorm2d(32), nn.ReLU())
        self.boundary_up_3 = nn.Sequential(nn.ConvTranspose2d(128, 32, 8, 4, 2), nn.BatchNorm2d(32), nn.ReLU())
        self.boundary_up_2 = nn.Sequential(nn.ConvTranspose2d(64, 32, 4, 2, 1), nn.BatchNorm2d(32), nn.ReLU())
        self.boundary_up_1 = nn.Sequential(nn.Conv2d(32, 32, 1, 1, 0), nn.BatchNorm2d(32), nn.ReLU())

        self.boundary_cbam_4 = CBAM(32)
        self.boundary_cbam_3 = CBAM(32)
        self.boundary_cbam_2 = CBAM(32)
        self.boundary_cbam_1 = CBAM(32)
        self.boundary_cbam_concat = CBAM(128)

        self.boundary_predict_concat = nn.Conv2d(128, 1, 3, 1, 1)

        # Attention Fusion
        self.attention_fusion_cbam = CBAM(384, no_spatial=True)

        self.attention_fusion_predict = nn.Conv2d(384, 1, 3, 1, 1)

        for m in self.modules():
            if isinstance(m, nn.ReLU):
                m.inplace = True
コード例 #15
0
    def __init__(self):
        super(EDGE_CBAM_X_CCL, self).__init__()
        resnext = ResNeXt101()
        self.layer0 = resnext.layer0
        self.layer1 = resnext.layer1
        self.layer2 = resnext.layer2
        self.layer3 = resnext.layer3
        self.layer4 = resnext.layer4

        self.ccl_f = CCL(2048, 512, 5)
        self.ccl_e = CCL(2048, 512, 5)
        self.ccl_b = CCL(2048, 512, 5)

        self.f4_up = nn.ConvTranspose2d(512, 256, 4, 2, 1)
        self.f3_up = nn.ConvTranspose2d(256, 128, 4, 2, 1)
        self.f2_up = nn.ConvTranspose2d(128, 64, 4, 2, 1)

        self.e4_up = nn.ConvTranspose2d(512, 256, 4, 2, 1)
        self.e3_up = nn.ConvTranspose2d(256, 128, 4, 2, 1)
        self.e2_up = nn.ConvTranspose2d(128, 64, 4, 2, 1)

        self.b4_up = nn.ConvTranspose2d(512, 256, 4, 2, 1)
        self.b3_up = nn.ConvTranspose2d(256, 128, 4, 2, 1)
        self.b2_up = nn.ConvTranspose2d(128, 64, 4, 2, 1)

        self.sc_f4 = nn.Conv2d(2048, 512, 1)
        self.sc_f3 = nn.Conv2d(1024, 256, 1)
        self.sc_f2 = nn.Conv2d(512, 128, 1)
        self.sc_f1 = nn.Conv2d(256, 64, 1)

        self.sc_e4 = nn.Conv2d(2048, 512, 1)
        self.sc_e3 = nn.Conv2d(1024, 256, 1)
        self.sc_e2 = nn.Conv2d(512, 128, 1)
        self.sc_e1 = nn.Conv2d(256, 64, 1)

        self.sc_b4 = nn.Conv2d(2048, 512, 1)
        self.sc_b3 = nn.Conv2d(1024, 256, 1)
        self.sc_b2 = nn.Conv2d(512, 128, 1)
        self.sc_b1 = nn.Conv2d(256, 64, 1)

        self.f4_fusion = nn.Sequential(
            nn.Conv2d(1024, 512, 1),
            nn.BatchNorm2d(512), nn.ReLU()
        )
        self.f3_fusion = nn.Sequential(
            nn.Conv2d(512, 256, 1),
            nn.BatchNorm2d(256), nn.ReLU()
        )
        self.f2_fusion = nn.Sequential(
            nn.Conv2d(256, 128, 1),
            nn.BatchNorm2d(128), nn.ReLU()
        )
        self.f1_fusion = nn.Sequential(
            nn.Conv2d(128, 64, 1),
            nn.BatchNorm2d(64), nn.ReLU()
        )

        self.e4_activate = nn.Sequential(
            nn.BatchNorm2d(512), nn.ReLU()
        )
        self.e3_active = nn.Sequential(
            nn.BatchNorm2d(256), nn.ReLU()
        )
        self.e2_active = nn.Sequential(
            nn.BatchNorm2d(128), nn.ReLU()
        )
        self.e1_active = nn.Sequential(
            nn.BatchNorm2d(64), nn.ReLU()
        )

        self.b4_fusion = nn.Sequential(
            nn.Conv2d(1024, 512, 1),
            nn.BatchNorm2d(512), nn.ReLU()
        )
        self.b3_fusion = nn.Sequential(
            nn.Conv2d(512, 256, 1),
            nn.BatchNorm2d(256), nn.ReLU()
        )
        self.b2_fusion = nn.Sequential(
            nn.Conv2d(256, 128, 1),
            nn.BatchNorm2d(128), nn.ReLU()
        )
        self.b1_fusion = nn.Sequential(
            nn.Conv2d(128, 64, 1),
            nn.BatchNorm2d(64), nn.ReLU()
        )

        self.cbam_f4 = CBAM(512)
        self.cbam_f3 = CBAM(256)
        self.cbam_f2 = CBAM(128)
        self.cbam_f1 = CBAM(64)
        self.cbam_fe = CBAM(128)

        self.cbam_b4 = CBAM(512)
        self.cbam_b3 = CBAM(256)
        self.cbam_b2 = CBAM(128)
        self.cbam_b1 = CBAM(64)
        self.cbam_be = CBAM(128)

        self.f4_predict = Predict(512)
        self.f3_predict = Predict(256)
        self.f2_predict = Predict(128)
        self.f1_predict = Predict(64)
        self.fe_predict = Predict(128)

        self.b4_predict = Predict(512)
        self.b3_predict = Predict(256)
        self.b2_predict = Predict(128)
        self.b1_predict = Predict(64)
        self.be_predict = Predict(128)

        self.e_predict = Predict(64)

        for m in self.modules():
            if isinstance(m, nn.ReLU):
                m.inplace = True