Esempio n. 1
0
    def __init__(self, out_planes, criterion, pretrained_model=None,
                 norm_layer=nn.BatchNorm2d):
        super(CPNet, self).__init__()
        self.backbone = resnet50(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, 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
Esempio n. 2
0
    def __init__(self, out_planes, criterion, pretrained_model=None,
                 norm_layer=nn.BatchNorm2d):
        super(CPNet, self).__init__()
        self.backbone = resnet50(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')
Esempio n. 3
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 = resnet50(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.latent_layers = nn.ModuleList()
        self.refine_layers = nn.ModuleList()
        self.predict_layer = PredictHead(business_channel_num,
                                         out_planes,
                                         4,
                                         norm_layer=norm_layer)
        for idx, channel in enumerate(self.backbone.layer_channel_nums[::-1]):
            self.latent_layers.append(
                ConvBnRelu(channel,
                           business_channel_num,
                           3,
                           1,
                           1,
                           has_bn=False,
                           has_relu=False,
                           has_bias=False,
                           norm_layer=norm_layer))
            self.refine_layers.append(
                ConvBnRelu(business_channel_num,
                           business_channel_num,
                           1,
                           1,
                           0,
                           has_bn=False,
                           has_relu=False,
                           has_bias=False,
                           norm_layer=norm_layer))

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

        self.criterion = criterion
Esempio n. 4
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 = resnet50(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)
Esempio n. 5
0
    def __init__(self, out_planes, criterion, pretrained_model=None,
                 norm_layer=nn.BatchNorm2d):
        super(PSPNet, self).__init__()
        self.backbone = resnet50(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.psa_layer = PointwiseSpatialAttention('psa', 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.psa_layer)
        self.business_layer.append(self.aux_layer)

        self.criterion = criterion
    def __init__(self, out_planes, is_training, BN2D=BatchNorm2d):
        super(Network_Res50, self).__init__()
        self.layers = []
        self.is_training = is_training

        conv_channel = 128
        # use base model of resnet 50 from resnet.py
        self.context = resnet50(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)
    def __init__(self, out_planes, criterion=None, pretrained_model=None,
                 norm_layer=nn.BatchNorm2d):
        super(PSPNet, self).__init__()
        self.backbone = resnet50(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

        ngf = 64
        ngf2 = ngf//2
        use_selu = True
        in_nc = 3
        out_nc = 2
        #------------road edge detection------------#
        self.edge_conv1 = nn.Sequential(*self._conv_block(in_nc+out_nc, ngf2, norm_layer, use_selu, num_block=2))
        self.side_edge_conv1 = nn.Conv2d(ngf2, out_nc, kernel_size=1, stride=1, bias=False) 

        self.edge_conv2 = nn.Sequential(*self._conv_block(ngf2, ngf2*2, norm_layer, use_selu, num_block=2))
        self.side_edge_conv2 = nn.Conv2d(ngf2*2, out_nc, kernel_size=1, stride=1, bias=False)

        self.edge_conv3 = nn.Sequential(*self._conv_block(ngf2*2, ngf2*4, norm_layer, use_selu, num_block=2))
        self.side_edge_conv3 = nn.Conv2d(ngf2*4, out_nc, kernel_size=1, stride=1, bias=False)

        self.edge_conv4 = nn.Sequential(*self._conv_block(ngf2*4, ngf2*8, norm_layer, use_selu, num_block=2))
        self.side_edge_conv4 = nn.Conv2d(ngf2*8, out_nc, kernel_size=1, stride=1, bias=False)

        self.fuse_edge_conv = nn.Conv2d(out_nc*4, out_nc, kernel_size=1, stride=1, bias=False)

        #------------road centerline extraction------------#
        self.centerline_conv1 = nn.Sequential(*self._conv_block(in_nc+out_nc, ngf2, norm_layer, use_selu, num_block=2))
        self.side_centerline_conv1 = nn.Conv2d(ngf2, out_nc, kernel_size=1, stride=1, bias=False) 

        self.centerline_conv2 = nn.Sequential(*self._conv_block(ngf2, ngf2*2, norm_layer, use_selu, num_block=2))
        self.side_centerline_conv2 = nn.Conv2d(ngf2*2, out_nc, kernel_size=1, stride=1, bias=False)

        self.centerline_conv3 = nn.Sequential(*self._conv_block(ngf2*2, ngf2*4, norm_layer, use_selu, num_block=2))
        self.side_centerline_conv3 = nn.Conv2d(ngf2*4, out_nc, kernel_size=1, stride=1, bias=False)

        self.centerline_conv4 = nn.Sequential(*self._conv_block(ngf2*4, ngf2*8, norm_layer, use_selu, num_block=2))
        self.side_centerline_conv4 = nn.Conv2d(ngf2*8, out_nc, kernel_size=1, stride=1, bias=False)

        self.fuse_centerline_conv = nn.Conv2d(out_nc*4, out_nc, kernel_size=1, stride=1, bias=False)

        self.maxpool = nn.MaxPool2d(2, stride=2)

        self.business_layer.append(self.edge_conv1)
        self.business_layer.append(self.edge_conv2)
        self.business_layer.append(self.edge_conv3)
        self.business_layer.append(self.edge_conv4)
        self.business_layer.append(self.side_edge_conv1)
        self.business_layer.append(self.side_edge_conv2)
        self.business_layer.append(self.side_edge_conv3)
        self.business_layer.append(self.side_edge_conv4)
        self.business_layer.append(self.fuse_edge_conv)


        self.business_layer.append(self.centerline_conv1)
        self.business_layer.append(self.centerline_conv2)
        self.business_layer.append(self.centerline_conv3)
        self.business_layer.append(self.centerline_conv4)
        self.business_layer.append(self.side_centerline_conv1)
        self.business_layer.append(self.side_centerline_conv2)
        self.business_layer.append(self.side_centerline_conv3)
        self.business_layer.append(self.side_centerline_conv4)
        self.business_layer.append(self.fuse_centerline_conv)

        self.edge_criterion = nn.CrossEntropyLoss(reduction='mean', ignore_index=-1, weight=torch.Tensor([0.015, 0.985]))
        self.centerline_criterion = nn.CrossEntropyLoss(reduction='mean', ignore_index=-1, weight=torch.Tensor([0.01, 0.99]))