示例#1
0
    def __init__(self,
                 num_class=150,
                 fc_dim=4096,
                 use_softmax=False,
                 pool_scales=(1, 2, 3, 6)):
        super(PPMBilinearDeepsup, self).__init__()
        self.use_softmax = use_softmax

        self.ppm = []
        for scale in pool_scales:
            self.ppm.append(
                nn.Sequential(
                    nn.AdaptiveAvgPool2d(scale),
                    nn.Conv2d(fc_dim, 512, kernel_size=1, bias=False),
                    SynchronizedBatchNorm2d(512), nn.ReLU(inplace=True)))
        self.ppm = nn.ModuleList(self.ppm)
        #self.cbr_deepsup = conv3x3_bn_relu(fc_dim // 2, fc_dim // 4, 1)

        self.aspp_last = nn.Sequential(
            nn.Conv2d(fc_dim + len(pool_scales) * 512,
                      512,
                      kernel_size=3,
                      padding=1,
                      bias=False), SynchronizedBatchNorm2d(512),
            nn.ReLU(inplace=True), nn.Dropout2d(0.1))
        #self.conv_last_deepsup = nn.Conv2d(fc_dim // 4, num_class, 1, 1, 0)
        #self.dropout_deepsup = nn.Dropout2d(0.1)
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                our_kaiming_normal_(m.weight, 0.1)
                if m.bias is not None:
                    constant_(m.bias, 0)
            elif isinstance(m, nn.BatchNorm2d):
                constant_(m.weight, 1)
                constant_(m.bias, 0)
示例#2
0
    def __init__(self, block, layers, num_classes=1000):
        self.inplanes = 128
        super(ResNet, self).__init__()
        self.conv1 = conv3x3(3, 64, stride=2)
        self.bn1 = SynchronizedBatchNorm2d(64)
        self.relu1 = nn.ReLU(inplace=True)
        self.conv2 = conv3x3(64, 64)
        self.bn2 = SynchronizedBatchNorm2d(64)
        self.relu2 = nn.ReLU(inplace=True)
        self.conv3 = conv3x3(64, 128)
        self.bn3 = SynchronizedBatchNorm2d(128)
        self.relu3 = nn.ReLU(inplace=True)
        self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)

        self.layer1 = self._make_layer(block, 64, layers[0])
        self.layer2 = self._make_layer(block, 128, layers[1], stride=2)
        self.layer3 = self._make_layer(block, 256, layers[2], stride=2)
        self.layer4 = self._make_layer(block, 512, layers[3], stride=2)
        self.avgpool = nn.AvgPool2d(7, stride=1)
        self.fc = nn.Linear(512 * block.expansion, num_classes)

        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
                m.weight.data.normal_(0, math.sqrt(2. / n))
            elif isinstance(m, SynchronizedBatchNorm2d):
                m.weight.data.fill_(1)
                m.bias.data.zero_()
示例#3
0
    def __init__(self,
                 num_class=150,
                 fc_dim=4096,
                 use_softmax=False,
                 pool_scales=(1, 2, 3, 6)):
        super(PPMBilinear, self).__init__()
        self.use_softmax = use_softmax

        self.ppm = []
        for scale in pool_scales:
            self.ppm.append(
                nn.Sequential(
                    nn.AdaptiveAvgPool2d(scale),
                    nn.Conv2d(fc_dim, 512, kernel_size=1, bias=False),
                    SynchronizedBatchNorm2d(512), nn.ReLU(inplace=True)))
        self.ppm = nn.ModuleList(self.ppm)

        self.aspp_conv = nn.Sequential(
            nn.Conv2d(fc_dim + len(pool_scales) * 512,
                      512,
                      kernel_size=3,
                      padding=1,
                      bias=False), SynchronizedBatchNorm2d(512),
            nn.ReLU(inplace=True))
        self.conv_last = nn.Sequential(
            nn.Dropout2d(0.1), nn.Conv2d(512, num_class, kernel_size=1))
示例#4
0
 def __init__(self, inplanes, planes, stride=1, downsample=None):
     super(BasicBlock, self).__init__()
     self.conv1 = conv3x3(inplanes, planes, stride)
     self.bn1 = SynchronizedBatchNorm2d(planes)
     self.relu = nn.ReLU(inplace=True)
     self.conv2 = conv3x3(planes, planes)
     self.bn2 = SynchronizedBatchNorm2d(planes)
     self.downsample = downsample
     self.stride = stride
示例#5
0
    def __init__(self):
        super(Generalized_SEMSEG, self).__init__()

        builder = semseg_heads.ModelBuilder()
        self.encoder = builder.build_encoder(
            arch=cfg.SEM.ARCH_ENCODER,
            fc_dim=cfg.SEM.FC_DIM,
            weights=cfg.RESNETS.IMAGENET_PRETRAINED_WEIGHTS)

        #define shape weights
        self.decoder = builder.build_decoder(arch=cfg.SEM.DECODER_TYPE,
                                             fc_dim=cfg.SEM.FC_DIM,
                                             num_class=cfg.MODEL.NUM_CLASSES,
                                             use_softmax=not self.training,
                                             weights='')

        ##define semseg loss
        self.conv_last_semseg = nn.Sequential(
            nn.Conv2d(cfg.SEM.DIM * 2, cfg.MODEL.NUM_CLASSES, kernel_size=1))
        self.conv_last_semseg.apply(self._init_weights_kaiming)
        self.crit = nn.NLLLoss(ignore_index=255)
        self.deep_sup_scale = cfg.SEM.DEEP_SUB_SCALE
        if len(cfg.SEM.DOWNSAMPLE) > 1:
            self.semseg_deepsup = nn.Sequential(
                nn.Conv2d(cfg.SEM.FC_DIM // 2,
                          cfg.SEM.FC_DIM // 4,
                          kernel_size=3,
                          stride=1,
                          padding=1,
                          bias=None),
                SynchronizedBatchNorm2d(cfg.SEM.FC_DIM // 4),
                nn.ReLU(inplace=True), nn.Dropout2d(0.1),
                nn.Conv2d(cfg.SEM.FC_DIM // 4,
                          cfg.MODEL.NUM_CLASSES,
                          kernel_size=1))
            #self.semseg_deepsup.apply(self._init_weights_kaiming)

        if len(cfg.SEM.DOWNSAMPLE) > 1:
            self.disp_deepsup = nn.Sequential(
                nn.Conv2d(cfg.SEM.FC_DIM // 2,
                          cfg.SEM.FC_DIM // 4,
                          kernel_size=3,
                          stride=1,
                          padding=1,
                          bias=None),
                SynchronizedBatchNorm2d(cfg.SEM.FC_DIM // 4),
                nn.ReLU(inplace=True), nn.Dropout2d(0.1),
                nn.Conv2d(cfg.SEM.FC_DIM // 4,
                          1,
                          kernel_size=3,
                          stride=1,
                          padding=1,
                          bias=None))
示例#6
0
 def __init__(self, inplanes, planes, stride=1, downsample=None):
     super(Bottleneck, self).__init__()
     self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False)
     self.bn1 = SynchronizedBatchNorm2d(planes)
     self.conv2 = nn.Conv2d(planes,
                            planes,
                            kernel_size=3,
                            stride=stride,
                            padding=1,
                            bias=False)
     self.bn2 = SynchronizedBatchNorm2d(planes)
     self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False)
     self.bn3 = SynchronizedBatchNorm2d(planes * 4)
     self.relu = nn.ReLU(inplace=True)
     self.downsample = downsample
     self.stride = stride
示例#7
0
    def __init__(self,
                 num_class=150,
                 fc_dim=4096,
                 use_softmax=False,
                 pool_scales=(1, 2, 3, 6),
                 fpn_inplanes=(256, 512, 1024, 2048),
                 fpn_dim=256):
        super(UPerNet, self).__init__()
        self.use_softmax = use_softmax

        # PPM Module
        self.ppm_pooling = []
        self.ppm_conv = []

        for scale in pool_scales:
            self.ppm_pooling.append(nn.AdaptiveAvgPool2d(scale))
            self.ppm_conv.append(
                nn.Sequential(
                    nn.Conv2d(fc_dim, 512, kernel_size=1, bias=False),
                    SynchronizedBatchNorm2d(512), nn.ReLU(inplace=True)))
        self.ppm_pooling = nn.ModuleList(self.ppm_pooling)
        self.ppm_conv = nn.ModuleList(self.ppm_conv)
        self.ppm_last_conv = conv3x3_bn_relu(fc_dim + len(pool_scales) * 512,
                                             fpn_dim, 1)

        # FPN Module
        self.fpn_in = []
        for fpn_inplane in fpn_inplanes[:-1]:  # skip the top layer
            self.fpn_in.append(
                nn.Sequential(
                    nn.Conv2d(fpn_inplane, fpn_dim, kernel_size=1, bias=False),
                    SynchronizedBatchNorm2d(fpn_dim), nn.ReLU(inplace=True)))
        self.fpn_in = nn.ModuleList(self.fpn_in)

        self.fpn_out = []
        for i in range(len(fpn_inplanes) - 1):  # skip the top layer
            self.fpn_out.append(
                nn.Sequential(conv3x3_bn_relu(fpn_dim, fpn_dim, 1), ))
        self.fpn_out = nn.ModuleList(self.fpn_out)

        self.conv_last = nn.Sequential(
            conv3x3_bn_relu(len(fpn_inplanes) * fpn_dim, fpn_dim, 1))
示例#8
0
 def __init__(self, inplanes, planes, stride=1, downsample=None):
     super(Bottleneck_GE, self).__init__()
     self.conv1 = nn.Conv2d(inplanes, planes, kernel_size=1, bias=False)
     self.bn1 = SynchronizedBatchNorm2d(planes)
     self.conv2 = nn.Conv2d(planes,
                            planes,
                            kernel_size=3,
                            stride=stride,
                            padding=1,
                            bias=False)
     self.bn2 = SynchronizedBatchNorm2d(planes)
     self.conv3 = nn.Conv2d(planes, planes * 4, kernel_size=1, bias=False)
     self.bn3 = SynchronizedBatchNorm2d(planes * 4)
     self.relu = nn.ReLU(inplace=True)
     self.downsample = downsample
     self.stride = stride
     self.Sigmoid = nn.Sigmoid()
     ge_list = []
     if cfg.SEM.USE_GE_BLOCK:
         for i in range(3):
             ge_list.append(self._conv(inplanes, inplanes, groups=inplanes))
     self.ge_model_list = nn.ModuleList(ge_list)
示例#9
0
    def _make_layer(self, block, planes, blocks, stride=1):
        downsample = None
        if stride != 1 or self.inplanes != planes * block.expansion:
            downsample = nn.Sequential(
                nn.Conv2d(self.inplanes,
                          planes * block.expansion,
                          kernel_size=1,
                          stride=stride,
                          bias=False),
                SynchronizedBatchNorm2d(planes * block.expansion),
            )

        layers = []
        layers.append(block(self.inplanes, planes, stride, downsample))
        self.inplanes = planes * block.expansion
        for i in range(1, blocks):
            layers.append(block(self.inplanes, planes))

        return nn.Sequential(*layers)
示例#10
0
def conv3x3_bn_relu(in_planes, out_planes, stride=1):
    return nn.Sequential(
        conv3x3(in_planes, out_planes, stride),
        SynchronizedBatchNorm2d(out_planes),
        nn.ReLU(inplace=True),
    )