示例#1
0
 def __init__(self,
              out_planes,
              criterion,
              edge_criterion,
              pretrained_model=None,
              norm_layer=nn.BatchNorm2d):
     super(MCNet, self).__init__()
     self.backbone = resnet101(pretrained_model,
                               norm_layer=norm_layer,
                               bn_eps=config.bn_eps,
                               bn_momentum=config.bn_momentum,
                               deep_stem=False,
                               stem_width=64)
     self.backbone.layer4.apply(partial(self._nostride_dilate,
                                        dilate=4))  # output_stride=16
     self.business_layer = []
     self.decoder_level1 = Decoder_level1(out_planes, norm_layer=norm_layer)
     self.meem = MEEM(norm_layer=norm_layer)
     self.cam_1 = CAM1(norm_layer=norm_layer)
     self.cmcm = CMCM()
     self.decoder_layer_level2 = Decoder_level2(out_planes,
                                                norm_layer=norm_layer)
     self.business_layer.append(self.decoder_level1)
     self.business_layer.append(self.meem)
     self.business_layer.append(self.cam_1)
     self.business_layer.append(self.decoder_layer_level2)
     self.criterion = criterion
     self.edge_criterion = edge_criterion
示例#2
0
    def __init__(self, out_planes, is_training,
                 criterion, pretrained_model=None,
                 norm_layer=nn.BatchNorm2d):
        super(conf, self).__init__()
        
        self.is_training = is_training
        self.business_layer = []

        if is_training:
            self.criterion = criterion
        
        self.encoder = resnet101(pretrained_model, norm_layer=norm_layer,
                                     bn_eps=config.bn_eps,
                                     bn_momentum=config.bn_momentum,
                                     deep_stem=True, stem_width=64)

        self.context_ff = AttentionFusion(1024, 2048, 128)
        self.spatial_conv = ConvBnRelu(256, 128, 1, 1, 0, dilation=1,
                                   has_bn=True, norm_layer=norm_layer,
                                   has_relu=True, has_bias=False)

        self.loc_conf = LocationConfidence(128+128, 1)
        
        self.refine_block = RefineOutput(128, out_planes, 4)
        self.spatial_refine_block = RefineOutput(128, out_planes, 4)
        self.context_refine_block = RefineOutput(128, out_planes, 16)

        self.business_layer.append(self.context_ff)
        self.business_layer.append(self.loc_conf)
        self.business_layer.append(self.spatial_conv)
        self.business_layer.append(self.refine_block)
        self.business_layer.append(self.spatial_refine_block)
        self.business_layer.append(self.context_refine_block)
示例#3
0
    def __init__(self,
                 out_planes,
                 criterion,
                 inplace=True,
                 pretrained_model=None,
                 norm_layer=nn.BatchNorm2d):
        super(FCN, self).__init__()
        self.backbone = resnet101(pretrained_model,
                                  inplace=inplace,
                                  norm_layer=norm_layer,
                                  bn_eps=config.bn_eps,
                                  bn_momentum=config.bn_momentum,
                                  deep_stem=True,
                                  stem_width=64)

        self.business_layer = []
        self.head = _FCNHead(2048, out_planes, inplace, norm_layer=norm_layer)
        self.aux_head = _FCNHead(1024,
                                 out_planes,
                                 inplace,
                                 norm_layer=norm_layer)

        self.business_layer.append(self.head)
        self.business_layer.append(self.aux_head)

        self.criterion = criterion
示例#4
0
    def __init__(self, out_planes, criterion, pretrained_model=None,
                 norm_layer=nn.BatchNorm2d):
        super(CPNet, self).__init__()
        self.backbone = resnet101(pretrained_model, norm_layer=norm_layer,
                                  bn_eps=config.bn_eps,
                                  bn_momentum=config.bn_momentum,
                                  deep_stem=True, stem_width=64)
        self.backbone.layer3.apply(partial(self._nostride_dilate, dilate=2))
        self.backbone.layer4.apply(partial(self._nostride_dilate, dilate=4))

        self.business_layer = []

        self.context = ObjectContext(2048, 512, norm_layer)

        self.head_layer = nn.Sequential(
            ConvBnRelu(2048 + 1024, 512, 3, 1, 1,
                       has_bn=True,
                       has_relu=True, has_bias=False, norm_layer=norm_layer),
            nn.Dropout2d(0.1, inplace=False),
            nn.Conv2d(512, out_planes, kernel_size=1)
        )
        self.aux_layer = nn.Sequential(
            ConvBnRelu(1024, 512, 3, 1, 1,
                       has_bn=True,
                       has_relu=True, has_bias=False, norm_layer=norm_layer),
            nn.Dropout2d(0.1, inplace=False),
            nn.Conv2d(512, out_planes, kernel_size=1)
        )
        self.business_layer.append(self.context)
        self.business_layer.append(self.head_layer)
        self.business_layer.append(self.aux_layer)

        self.criterion = criterion
        self.bce_criterion = nn.BCELoss(reduction='mean')
示例#5
0
    def __init__(self, output_shape, num_points, pretrained=True):
        super(CPN, self).__init__()

        self.resnet101 = base_model.resnet101(pretrained=pretrained)

        self.global_net = globalNet([2048, 1024, 512, 256], output_shape,
                                    num_points)

        self.refine_net = refineNet(256, output_shape, num_points)
示例#6
0
    def __init__(self,
                 out_planes,
                 criterion,
                 inplace=True,
                 pretrained_model=None,
                 norm_layer=nn.BatchNorm2d):
        super(Network, self).__init__()
        business_channel_num = config.business_channel_num

        self.backbone = resnet101(pretrained_model,
                                  inplace=inplace,
                                  norm_layer=norm_layer,
                                  bn_eps=config.bn_eps,
                                  bn_momentum=config.bn_momentum,
                                  deep_stem=True,
                                  stem_width=64)
        block_channel_nums = self.backbone.layer_channel_nums

        self.latent_layers = nn.ModuleList()
        self.refine_layers = nn.ModuleList()
        self.global_context = nn.Sequential(
            nn.AdaptiveAvgPool2d(1),
            ConvBnRelu(block_channel_nums[-1],
                       business_channel_num,
                       1,
                       1,
                       0,
                       has_bn=True,
                       has_relu=True,
                       has_bias=False,
                       norm_layer=norm_layer))
        self.predict_layer = PredictHead(business_channel_num,
                                         out_planes,
                                         4,
                                         norm_layer=norm_layer)
        for idx, channel in enumerate(block_channel_nums[::-1]):
            self.latent_layers.append(
                RefineResidual(channel,
                               business_channel_num,
                               3,
                               norm_layer=norm_layer,
                               has_relu=True))
            self.refine_layers.append(
                RefineResidual(business_channel_num,
                               business_channel_num,
                               3,
                               norm_layer=norm_layer,
                               has_relu=True))

        self.business_layers = [
            self.global_context, self.latent_layers, self.refine_layers,
            self.predict_layer
        ]

        self.criterion = criterion
示例#7
0
    def __init__(self, out_planes, is_training,
                 criterion, pretrained_model=None,
                 norm_layer=nn.BatchNorm2d):
        super(BiSeNet, self).__init__()
        self.context_path = resnet101(pretrained_model, norm_layer=norm_layer,
                                      bn_eps=config.bn_eps,
                                      bn_momentum=config.bn_momentum,
                                      deep_stem=True, stem_width=64)

        self.business_layer = []
        self.is_training = is_training

        self.spatial_path = SpatialPath(3, 128, norm_layer)

        conv_channel = 128
        self.global_context = nn.Sequential(
            nn.AdaptiveAvgPool2d(1),
            ConvBnRelu(2048, conv_channel, 1, 1, 0,
                       has_bn=True,
                       has_relu=True, has_bias=False, norm_layer=norm_layer)
        )

        # stage = [512, 256, 128, 64]
        arms = [AttentionRefinement(2048, conv_channel, norm_layer),
                AttentionRefinement(1024, conv_channel, norm_layer)]
        refines = [ConvBnRelu(conv_channel, conv_channel, 3, 1, 1,
                              has_bn=True, norm_layer=norm_layer,
                              has_relu=True, has_bias=False),
                   ConvBnRelu(conv_channel, conv_channel, 3, 1, 1,
                              has_bn=True, norm_layer=norm_layer,
                              has_relu=True, has_bias=False)]

        heads = [BiSeNetHead(conv_channel, out_planes, 16,
                             True, norm_layer),
                 BiSeNetHead(conv_channel, out_planes, 8,
                             True, norm_layer),
                 BiSeNetHead(conv_channel * 2, out_planes, 8,
                             False, norm_layer)]

        self.ffm = FeatureFusion(conv_channel * 2, conv_channel * 2,
                                 1, norm_layer)

        self.arms = nn.ModuleList(arms)
        self.refines = nn.ModuleList(refines)
        self.heads = nn.ModuleList(heads)

        self.business_layer.append(self.spatial_path)
        self.business_layer.append(self.global_context)
        self.business_layer.append(self.arms)
        self.business_layer.append(self.refines)
        self.business_layer.append(self.heads)
        self.business_layer.append(self.ffm)

        if is_training:
            self.criterion = criterion
示例#8
0
    def __init__(self, num_point):
        super(CPN, self).__init__()

        self.resnet101 = base_model.resnet101(pretrained=True)
        #print resnet101

        self.global_net = globalNet([2048, 1024, 512, 256], (64, 64),
                                    num_point)
        #print global_net

        self.refine_net = refineNet(256, (64, 64), num_point)
示例#9
0
    def __init__(self,
                 out_planes,
                 criterion,
                 pretrained_model=None,
                 norm_layer=nn.BatchNorm2d):
        super(CPNet, self).__init__()
        self.backbone = resnet101(pretrained_model,
                                  norm_layer=norm_layer,
                                  bn_eps=config.bn_eps,
                                  bn_momentum=config.bn_momentum,
                                  deep_stem=True,
                                  stem_width=64)
        self.generate_dilation(self.backbone.layer3, dilation=2)
        self.generate_dilation(self.backbone.layer4,
                               dilation=4,
                               multi_grid=[1, 2, 4])

        self.business_layer = []

        self.context = ObjectContext(2048, 512, norm_layer)

        self.head_layer = nn.Sequential(
            ConvBnRelu(2048 + 512,
                       512,
                       1,
                       1,
                       0,
                       has_bn=True,
                       has_relu=True,
                       has_bias=False,
                       norm_layer=norm_layer), nn.Dropout2d(0.1,
                                                            inplace=False),
            nn.Conv2d(512, out_planes, kernel_size=1))
        self.aux_layer = nn.Sequential(
            ConvBnRelu(1024,
                       512,
                       1,
                       1,
                       0,
                       has_bn=True,
                       has_relu=True,
                       has_bias=False,
                       norm_layer=norm_layer), nn.Dropout2d(0.1,
                                                            inplace=False),
            nn.Conv2d(512, out_planes, kernel_size=1))
        self.business_layer.append(self.context)
        self.business_layer.append(self.head_layer)
        self.business_layer.append(self.aux_layer)

        self.criterion = criterion
        self.aux_criterion = PriorLoss(0.125, config.num_classes, 255)
示例#10
0
    def __init__(self, out_planes, is_training, BN2D = BatchNorm2d):
        super(Network_Res101, self).__init__()
        self.layers = []
        self.is_training = is_training
       
        conv_channel = 128
        # use base model of resnet 101 from resnet.py
        self.context = resnet101(pretrained_model=None, norm_layer=BN2D, bn_eps=config.bn_eps, bn_momentum=config.bn_momentum, deep_stem=False, stem_width=64)
        self.context_refine = nn.Sequential(
                        nn.AdaptiveAvgPool2d(1),
                        ConvBnRelu(2048,conv_channel, 1, 1, 0, has_bn=True, has_relu=True, has_bias=False, norm_layer=BN2D)
                )
        
        # ARM for ResBlock 2,3,4 of resnet output
        arms = [AttentionRefinement(2048, conv_channel, norm_layer=BN2D),
                AttentionRefinement(1024, conv_channel, norm_layer=BN2D),
                AttentionRefinement(512, conv_channel, norm_layer=BN2D)]

         # Refinement of corresponding output
        refines = [
                    ConvBnRelu(conv_channel, conv_channel, 3, 1, 1, has_bn=True, norm_layer=BN2D, has_relu=True, has_bias=False),
                    ConvBnRelu(conv_channel, conv_channel, 3, 1, 1, has_bn=True, norm_layer=BN2D, has_relu=True, has_bias=False),
                    ConvBnRelu(conv_channel, conv_channel, 3, 1, 1, has_bn=True, norm_layer=BN2D, has_relu=True, has_bias=False)]
        

        
        self.arms = nn.ModuleList(arms)
        self.refines = nn.ModuleList(refines)
        # Refinement on first layer of resnet output
        self.res_top_refine = ConvBnRelu(256, conv_channel, 3, 1, 1, has_bn=True, norm_layer=BN2D, has_relu=True, has_bias=False)

        self.ffm = FeatureFusion(conv_channel*2, conv_channel, 1, BN2D)
        # classifier for final output
        self.class_refine = nn.Sequential(
                ConvBnRelu(conv_channel, conv_channel//2, 3, 1, 1, has_bn=True, has_relu=True, has_bias=False, norm_layer=BN2D),
                nn.Conv2d(conv_channel//2, out_planes, kernel_size=1, stride=1, padding=0)
            )


        self.layers.append(self.context)
        self.layers.append(self.class_refine)
        self.layers.append(self.context_refine)
        self.layers.append(self.arms)
        self.layers.append(self.ffm)
        self.layers.append(self.refines)
        self.layers.append(self.res_top_refine)
        self.loss = nn.CrossEntropyLoss(reduction='mean',ignore_index=255)	
示例#11
0
    def __init__(self, out_planes, criterion, pretrained_model=None,
                 norm_layer=nn.BatchNorm2d):
        super(PSPNet, self).__init__()
        self.backbone = resnet101(pretrained_model, norm_layer=norm_layer,
                                  bn_eps=config.bn_eps,
                                  bn_momentum=config.bn_momentum,
                                  deep_stem=True, stem_width=64)
        self.backbone.layer3.apply(partial(self._nostride_dilate, dilate=2))
        self.backbone.layer4.apply(partial(self._nostride_dilate, dilate=4))

        self.business_layer = []
        self.psp_layer = PyramidPooling('psp', out_planes, 2048,
                                        norm_layer=norm_layer)
        self.aux_layer = nn.Sequential(
            ConvBnRelu(1024, 1024, 3, 1, 1,
                       has_bn=True,
                       has_relu=True, has_bias=False, norm_layer=norm_layer),
            nn.Dropout2d(0.1, inplace=False),
            nn.Conv2d(1024, out_planes, kernel_size=1)
        )
        self.business_layer.append(self.psp_layer)
        self.business_layer.append(self.aux_layer)

        self.criterion = criterion
示例#12
0
    def __init__(self, out_planes, criterion, aux_criterion, alpha,
                 pretrained_model=None,
                 norm_layer=nn.BatchNorm2d):
        super(DFN, self).__init__()
        self.backbone = resnet101(pretrained_model, norm_layer=norm_layer,
                                  bn_eps=config.bn_eps,
                                  bn_momentum=config.bn_momentum,
                                  deep_stem=False, stem_width=64)
        self.business_layer = []

        smooth_inner_channel = 512
        self.global_context = nn.Sequential(
            nn.AdaptiveAvgPool2d(1),
            ConvBnRelu(2048, smooth_inner_channel, 1, 1, 0,
                       has_bn=True,
                       has_relu=True, has_bias=False, norm_layer=norm_layer)
        )
        self.business_layer.append(self.global_context)

        stage = [2048, 1024, 512, 256]
        self.smooth_pre_rrbs = []
        self.cabs = []
        self.smooth_aft_rrbs = []
        self.smooth_heads = []

        #every stage we have dfn layer output?
        # top to bottom 2048 -> 256
        for i, channel in enumerate(stage):
            self.smooth_pre_rrbs.append(
                RefineResidual(channel, smooth_inner_channel, 3, has_bias=False,
                               has_relu=True, norm_layer=norm_layer))
            self.cabs.append(
                ChannelAttention(smooth_inner_channel * 2,
                                 smooth_inner_channel, 1))
            self.smooth_aft_rrbs.append(
                RefineResidual(smooth_inner_channel, smooth_inner_channel, 3,
                               has_bias=False,
                               has_relu=True, norm_layer=norm_layer))
            self.smooth_heads.append(
                DFNHead(smooth_inner_channel, out_planes, scale=2 ** (5 - i),
                        norm_layer=norm_layer))

        stage.reverse()
        border_inner_channel = 21
        self.border_pre_rrbs = []
        self.border_aft_rrbs = []
        self.border_heads = []


        for i, channel in enumerate(stage):
            self.border_pre_rrbs.append(
                RefineResidual(channel, border_inner_channel, 3, has_bias=False,
                               has_relu=True, norm_layer=norm_layer))
            self.border_aft_rrbs.append(
                RefineResidual(border_inner_channel, border_inner_channel, 3,
                               has_bias=False,
                               has_relu=True, norm_layer=norm_layer))
            self.border_heads.append(
                DFNHead(border_inner_channel, 1, 4, norm_layer=norm_layer))

        self.smooth_pre_rrbs = nn.ModuleList(self.smooth_pre_rrbs)
        self.cabs = nn.ModuleList(self.cabs)
        self.smooth_aft_rrbs = nn.ModuleList(self.smooth_aft_rrbs)
        self.smooth_heads = nn.ModuleList(self.smooth_heads)
        self.border_pre_rrbs = nn.ModuleList(self.border_pre_rrbs)
        self.border_aft_rrbs = nn.ModuleList(self.border_aft_rrbs)
        self.border_heads = nn.ModuleList(self.border_heads)

        #smooth model
        self.business_layer.append(self.smooth_pre_rrbs)
        self.business_layer.append(self.cabs)
        self.business_layer.append(self.smooth_aft_rrbs)
        self.business_layer.append(self.smooth_heads)

        #border_layer model
        self.business_layer.append(self.border_pre_rrbs)
        self.business_layer.append(self.border_aft_rrbs)
        self.business_layer.append(self.border_heads)

        self.criterion = criterion
        self.aux_criterion = aux_criterion
        self.alpha = alpha