def __init__(self,
                 n_classes=1,
                 sizes=(1, 2, 3, 6),
                 psp_size=1024,
                 backend='resnet34',
                 pretrained=True,
                 reduction=2):
        super().__init__()
        self.densenet = mextractors2.densenet121(pretrained=pretrained)

        self.conv1 = nn.Sequential(
            self.densenet.features.conv0,
            self.densenet.features.norm0,
            self.densenet.features.relu0,
            #self.densenet.features.pool0
        )  #64,64

        self.encoder2 = nn.Sequential(
            self.densenet.features.denseblock1,
            self.densenet.features.transition1)  #32,32

        self.encoder3 = nn.Sequential(
            self.densenet.features.denseblock2,
            self.densenet.features.transition2)  #16,16

        self.encoder4 = nn.Sequential(
            self.densenet.features.denseblock3,
            self.densenet.features.transition3)  #16,16

        self.encoder5 = nn.Sequential(
            self.densenet.features.denseblock4)  #16,16

        self.scse1 = ModifiedSCSEBlock(64)
        self.scse2 = ModifiedSCSEBlock(128)
        self.scse3 = ModifiedSCSEBlock(256)
        self.scse4 = ModifiedSCSEBlock(512)
        self.scse5 = ModifiedSCSEBlock(1024)
        self.scse6 = ModifiedSCSEBlock(1024)

        self.scse_center = ModifiedSCSEBlock(256)

        self.aspp = ASPP(depth=256)  # 16,16

        self.center = nn.Sequential(
            ConvBn2d(1024, 512, kernel_size=3,
                     padding=1), nn.ReLU(inplace=True),
            ConvBn2d(512, 256, kernel_size=3, padding=1),
            nn.ReLU(inplace=True), nn.MaxPool2d(kernel_size=2, stride=2))  #8,8

        self.decoder5 = Decoder(256 + 256, 256, 64, reduction)
        self.decoder4 = Decoder(64 + 128, 128, 64, reduction)
        self.decoder3 = Decoder(64 + 64, 64, 64, reduction)
        self.decoder2 = Decoder(64, 32, 64, reduction)

        self.drop_out2 = nn.Dropout2d(p=0.5)

        self.logit = nn.Sequential(
            nn.Conv2d(256, 64, kernel_size=3, padding=1),
            nn.ReLU(inplace=True), nn.Conv2d(64, 1, kernel_size=1, padding=0))
Exemplo n.º 2
0
    def __init__(self, pretrained=True):
        super().__init__()
        self.densenet = mextractors2.densenet121(pretrained=pretrained)

        self.conv1 = nn.Sequential(
            self.densenet.features.conv0,
            self.densenet.features.norm0,
            self.densenet.features.relu0,
            #self.densenet.features.pool0
        )  #64,64

        self.encoder2 = nn.Sequential(
            self.densenet.features.denseblock1,
            self.densenet.features.transition1)  #32,32

        self.encoder3 = nn.Sequential(
            self.densenet.features.denseblock2,
            self.densenet.features.transition2)  #16,16

        self.encoder4 = nn.Sequential(
            self.densenet.features.denseblock3,
            self.densenet.features.transition3)  #16,16

        self.encoder5 = nn.Sequential(
            self.densenet.features.denseblock4)  #16,16

        # self.scse1 = ModifiedSCSEBlock(64)
        # self.scse2 = ModifiedSCSEBlock(128)
        # self.scse3 = ModifiedSCSEBlock(256)
        # self.scse4 = ModifiedSCSEBlock(512)
        # self.scse5 = ModifiedSCSEBlock(1024)
        #
        # self.scse_center = ModifiedSCSEBlock(256)

        #self.psp = PSPModule(psp_size, 1024, sizes)#16,16

        self.context = nn.Sequential(ASP_OC_Module(1024, 512), )

        # self.center = nn.Sequential(
        #     ConvBn2d(1024,512,kernel_size=3,padding=1),
        #     nn.ReLU(inplace=True),
        #     ConvBn2d(512,256,kernel_size=3,padding=1),
        #     nn.ReLU(inplace=True),
        #     nn.MaxPool2d(kernel_size=2,stride=2)
        # )#8,8
        #
        #
        #
        self.decoder5 = Decoder(512 + 128, 128, 64)
        self.decoder4 = Decoder(64 + 64, 64, 64)
        self.decoder3 = Decoder(64, 32, 64)

        #
        self.drop_out2 = nn.Dropout2d(p=0.5)

        self.logit = nn.Sequential(
            nn.Conv2d(64 * 3, 64, kernel_size=3, padding=1),
            nn.ReLU(inplace=True), nn.Conv2d(64, 1, kernel_size=1, padding=0))
    def __init__(self,
                 n_classes=1,
                 sizes=(1, 2, 3, 6),
                 psp_size=1024,
                 backend='resnet34',
                 pretrained=True):
        super().__init__()
        self.densenet = mextractors2.densenet121(pretrained=pretrained)

        self.conv1 = nn.Sequential(
            self.densenet.features.conv0,
            self.densenet.features.norm0,
            self.densenet.features.relu0,
            #self.densenet.features.pool0
        )  #64,64

        self.encoder2 = nn.Sequential(
            self.densenet.features.denseblock1,
            self.densenet.features.transition1)  #32,32

        self.encoder3 = nn.Sequential(
            self.densenet.features.denseblock2,
            self.densenet.features.transition2)  #16,16

        self.encoder4 = nn.Sequential(
            self.densenet.features.denseblock3,
            self.densenet.features.transition3)  #16,16

        self.encoder5 = nn.Sequential(
            self.densenet.features.denseblock4)  #16,16

        self.psp = PSPModule(psp_size, 1024, sizes)  #16,16

        # self.center = nn.Sequential(
        #     ConvBn2d(1024,512,kernel_size=3,padding=1),
        #     nn.ReLU(inplace=True),
        #     ConvBn2d(512,256,kernel_size=3,padding=1),
        #     nn.ReLU(inplace=True),
        #     nn.MaxPool2d(kernel_size=2,stride=2)
        # )#8,8

        self.decoder5 = Decoder(64 + 128, 128, 64)
        self.decoder4 = Decoder(64 + 64, 64, 64)
        self.decoder3 = Decoder(64, 32, 64)

        self.decoder_p1 = Decoder_plain(1024 + 512, 512, 256)
        self.decoder_p2 = Decoder_plain(256 + 256, 256, 64)

        self.drop_out2 = nn.Dropout2d(p=0.5)

        self.logit = nn.Sequential(
            nn.Conv2d(256, 64, kernel_size=3, padding=1),
            nn.ReLU(inplace=True), nn.Conv2d(64, 1, kernel_size=1, padding=0))