def __init__(self,
              backbone='resnet',
              output_stride=16,
              num_classes=21,
              nInputChannels=3,
              sync_bn=True,
              freeze_bn=False):
     super(SegmentationNetwork, self).__init__()
     output_shape = 128
     channel_settings = [512, 1024, 512, 256]
     self.Coarse_net = CoarseNet(channel_settings, output_shape,
                                 num_classes)
     self.Fine_net = FineNet(channel_settings[-1], output_shape,
                             num_classes)
     BatchNorm = nn.BatchNorm2d
     self.backbone = build_backbone(backbone,
                                    output_stride,
                                    BatchNorm,
                                    nInputChannels,
                                    pretrained=False)
     self.psp4 = PSPModule(in_features=2048,
                           out_features=512,
                           sizes=(1, 2, 3, 6),
                           n_classes=256)
     self.upsample = nn.Upsample(size=(512, 512),
                                 mode='bilinear',
                                 align_corners=True)
     if freeze_bn:
         self.freeze_bn()
Exemple #2
0
    def __init__(self, backbone='resnet_edge', output_stride=16, num_classes=21,
                 sync_bn=True, freeze_bn=False):
        super(DeepLab, self).__init__()
        if backbone == 'drn':
            output_stride = 8
        if freeze_bn ==True:
            print("Use frozen BN in DeepLab")
            BatchNorm=FrozenBatchNorm2d
        elif sync_bn == True:
            BatchNorm = SynchronizedBatchNorm2d
        else:
            BatchNorm = nn.BatchNorm2d

        self.backbone = build_backbone(backbone, output_stride, BatchNorm)
        self.aspp = build_aspp(backbone, output_stride, BatchNorm)
        self.decoder = build_decoder(num_classes, backbone, BatchNorm)
Exemple #3
0
    def __init__(self, backbone='resnet', output_stride=16, num_classes=21,
                 sync_bn=False, freeze_bn=False):
        super(DeepLab, self).__init__()
        if backbone == 'drn':
            output_stride = 8

        if sync_bn:
            BatchNorm = SynchronizedBatchNorm2d
        else:
            BatchNorm = nn.BatchNorm2d

        self.backbone = build_backbone(backbone, output_stride, BatchNorm)
        self.aspp = build_aspp(backbone, output_stride, BatchNorm)
        self.decoder = build_decoder(num_classes, backbone, BatchNorm)

        if freeze_bn:
            self.freeze_bn()
Exemple #4
0
    def __init__(self, backbone='resnet', output_stride=16, num_classes=21,
                 sync_bn=False, num_domain=3, freeze_bn=False, lam =0.9):
        super(DeepLab, self).__init__()
        if backbone == 'drn':
            output_stride = 8

        if sync_bn == True:
            BatchNorm = SynchronizedBatchNorm2d
        else:
            BatchNorm = nn.BatchNorm2d
        self.lam = lam
        self.centroids = nn.Parameter(torch.randn(num_domain, 304, 64, 64), requires_grad=False)
        self.backbone = build_backbone(backbone, output_stride, BatchNorm)
        self.aspp = build_aspp(backbone, output_stride, BatchNorm)
        self.decoder = build_decoder(num_classes, num_domain, backbone, BatchNorm)
        self.last_conv_mask = nn.Sequential(BatchNorm(3),
                                                nn.ReLU(),
                                                nn.Dropout(0.5),
                                                nn.Conv2d(3, num_domain, kernel_size=1, stride=1))
        # build encoder for domain code
        self.encoder_d = build_encoderDC(num_domain, backbone, BatchNorm)

        if freeze_bn:
            self.freeze_bn()
Exemple #5
0
    def __init__(self,
                 backbone='resnet',
                 output_stride=16,
                 num_classes=21,
                 sync_bn=True,
                 freeze_bn=False,
                 dcn=False,
                 g_in_dim=3):

        super(DeepLab, self).__init__()

        if sync_bn == True:
            BatchNorm = SynchronizedBatchNorm2d
        else:
            BatchNorm = nn.BatchNorm2d

        self.backbone = build_backbone(backbone,
                                       output_stride,
                                       BatchNorm,
                                       g_in_dim=g_in_dim)
        self.aspp = build_aspp(backbone, output_stride, BatchNorm, dcn)
        self.decoder = build_decoder(num_classes, backbone, BatchNorm, dcn)

        self.freeze_bn = freeze_bn