Пример #1
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
Пример #2
0
 def __init__(self, in_planes, out_planes, scale, norm_layer=nn.BatchNorm2d):
     super(PredictHead, self).__init__()
     self.head_layers = nn.Sequential(
         RefineResidual(in_planes, in_planes, norm_layer=norm_layer, has_relu=True),
         nn.Conv2d(in_planes, out_planes, kernel_size=1,
                   stride=1, padding=0))
     self.scale = scale
Пример #3
0
 def __init__(self, in_planes, out_planes, scale, norm_layer=nn.BatchNorm2d):
     #remeber the scale means  upsample times
     super(DFNHead, self).__init__()
     self.rrb = RefineResidual(in_planes, out_planes * 9, 3, has_bias=False,
                               has_relu=False, norm_layer=norm_layer)
     self.conv = nn.Conv2d(out_planes * 9, out_planes, kernel_size=1,
                           stride=1, padding=0)
     self.scale = scale
Пример #4
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