Example #1
0
	def __init__(self, cfg):
		super(deeplabv3plus, self).__init__()
		self.backbone = None		
		self.backbone_layers = None
		input_channel = 2048		
		self.aspp = ASPP(dim_in=input_channel, 
				dim_out=cfg.MODEL_ASPP_OUTDIM, 
				rate=16//cfg.MODEL_OUTPUT_STRIDE)
#		self.dropout = torch.nn.Dropout(p=0.1, inplace=False)
		self.upsample4 = nn.UpsamplingBilinear2d(scale_factor=4)
		self.upsample_sub = nn.UpsamplingBilinear2d(scale_factor=cfg.MODEL_OUTPUT_STRIDE//4)

		indim = 256
		self.shortcut_conv = nn.Sequential(
				nn.Conv2d(indim, cfg.MODEL_SHORTCUT_DIM, cfg.MODEL_SHORTCUT_KERNEL, 1, padding=cfg.MODEL_SHORTCUT_KERNEL//2),
				nn.ReLU(inplace=True),		
		)		
		self.cat_conv = nn.Sequential(
				nn.Conv2d(cfg.MODEL_ASPP_OUTDIM+cfg.MODEL_SHORTCUT_DIM, cfg.MODEL_ASPP_OUTDIM, 3, 1, padding=1),
				nn.ReLU(inplace=True),
				nn.Conv2d(cfg.MODEL_ASPP_OUTDIM, cfg.MODEL_ASPP_OUTDIM, 3, 1, padding=1),
				nn.ReLU(inplace=True),
		)
		self.cls_conv = nn.Conv2d(cfg.MODEL_ASPP_OUTDIM, cfg.MODEL_NUM_CLASSES, 1, 1, padding=0)

		self.backbone = build_backbone(cfg.MODEL_BACKBONE, os=cfg.MODEL_OUTPUT_STRIDE)		
		self.backbone_layers = self.backbone.get_layers()
	def __init__(self, cfg):
		super(deeplabv3plus, self).__init__()
		self.backbone = build_backbone(cfg.MODEL_BACKBONE)		
		self.backbone_layers = self.backbone.get_layers()
		input_channel = 2048		
		self.aspp = ASPP(dim_in=input_channel, 
				dim_out=cfg.MODEL_ASPP_OUTDIM, 
				resolution_in=cfg.MODEL_ASPP_RESOLUTION)
		self.upsample = nn.UpsamplingBilinear2d(scale_factor=4)
		self.shortcut_conv = nn.Sequential(
				nn.Conv2d(256, cfg.MODEL_SHORTCUT_DIM, 1, 1, padding=0),
				nn.ReLU(inplace=True),		
		)		
		self.cat_conv = nn.Sequential(
				nn.Conv2d(cfg.MODEL_ASPP_OUTDIM+cfg.MODEL_SHORTCUT_DIM, cfg.MODEL_ASPP_OUTDIM, 3, 1, padding=1),
				nn.ReLU(inplace=True),
				nn.Conv2d(cfg.MODEL_ASPP_OUTDIM, cfg.MODEL_ASPP_OUTDIM, 3, 1, padding=1),
				nn.ReLU(inplace=True),				
				nn.Conv2d(cfg.MODEL_ASPP_OUTDIM, cfg.MODEL_NUM_CLASSES, 1, 1, padding=0),
		)
    def __init__(self, cfg):
        super(deeplabv3plus, self).__init__()
        self.backbone = None
        self.backbone_layers = None
        input_channel = 2048
        self.aspp = ASPP(dim_in=input_channel,
                         dim_out=cfg.MODEL_ASPP_OUTDIM,
                         rate=16 // cfg.MODEL_OUTPUT_STRIDE,
                         bn_mom=cfg.TRAIN_BN_MOM)
        self.dropout1 = nn.Dropout(0.5)
        self.upsample4 = nn.UpsamplingBilinear2d(scale_factor=4)
        self.upsample_sub = nn.UpsamplingBilinear2d(
            scale_factor=cfg.MODEL_OUTPUT_STRIDE // 4)

        indim = 256
        self.shortcut_conv = nn.Sequential(
            nn.Conv2d(indim,
                      cfg.MODEL_SHORTCUT_DIM,
                      cfg.MODEL_SHORTCUT_KERNEL,
                      1,
                      padding=cfg.MODEL_SHORTCUT_KERNEL // 2,
                      bias=True),
            SynchronizedBatchNorm2d(cfg.MODEL_SHORTCUT_DIM,
                                    momentum=cfg.TRAIN_BN_MOM),
            nn.ReLU(inplace=True),
        )
        self.cat_conv = nn.Sequential(
            nn.Conv2d(cfg.MODEL_ASPP_OUTDIM + cfg.MODEL_SHORTCUT_DIM,
                      cfg.MODEL_ASPP_OUTDIM,
                      3,
                      1,
                      padding=1,
                      bias=True),
            SynchronizedBatchNorm2d(cfg.MODEL_ASPP_OUTDIM,
                                    momentum=cfg.TRAIN_BN_MOM),
            nn.ReLU(inplace=True),
            nn.Dropout(0.5),
            nn.Conv2d(cfg.MODEL_ASPP_OUTDIM,
                      cfg.MODEL_ASPP_OUTDIM,
                      3,
                      1,
                      padding=1,
                      bias=True),
            SynchronizedBatchNorm2d(cfg.MODEL_ASPP_OUTDIM,
                                    momentum=cfg.TRAIN_BN_MOM),
            nn.ReLU(inplace=True),
            nn.Dropout(0.1),
        )
        self.cls_conv = nn.Conv2d(cfg.MODEL_ASPP_OUTDIM,
                                  cfg.MODEL_NUM_CLASSES,
                                  1,
                                  1,
                                  padding=0)
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_normal_(m.weight,
                                        mode='fan_out',
                                        nonlinearity='relu')
            elif isinstance(m, SynchronizedBatchNorm2d):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0)
        self.backbone = build_backbone(cfg.MODEL_BACKBONE,
                                       os=cfg.MODEL_OUTPUT_STRIDE)
        self.backbone_layers = self.backbone.get_layers()
Example #4
0
    def __init__(self, cfg, test=False):
        super(deeplabv3plus, self).__init__()
        if test:
            self.batch_size = cfg.TEST_BATCHES
        else:
            self.batch_size = cfg.TRAIN_BATCHES
        self.backbone = None
        self.backbone_layers = None
        input_channel = 2048
        self.aspp = ASPP(dim_in=input_channel,
                         dim_out=cfg.MODEL_ASPP_OUTDIM,
                         rate=16 // cfg.MODEL_OUTPUT_STRIDE,
                         bn_mom=cfg.TRAIN_BN_MOM)
        self.dropout1 = nn.Dropout(0.5)
        self.upsample4 = nn.UpsamplingBilinear2d(scale_factor=4)
        self.upsample_sub = nn.UpsamplingBilinear2d(
            scale_factor=cfg.MODEL_OUTPUT_STRIDE // 4)

        indim = 256
        self.shortcut_conv = nn.Sequential(
            nn.Conv2d(indim,
                      cfg.MODEL_SHORTCUT_DIM,
                      cfg.MODEL_SHORTCUT_KERNEL,
                      1,
                      padding=cfg.MODEL_SHORTCUT_KERNEL // 2,
                      bias=True),
            SynchronizedBatchNorm2d(cfg.MODEL_SHORTCUT_DIM,
                                    momentum=cfg.TRAIN_BN_MOM),
            nn.ReLU(inplace=True),
        )
        self.cat_conv = nn.Sequential(
            nn.Conv2d(cfg.MODEL_ASPP_OUTDIM + cfg.MODEL_SHORTCUT_DIM,
                      cfg.MODEL_ASPP_OUTDIM,
                      3,
                      1,
                      padding=1,
                      bias=True),
            SynchronizedBatchNorm2d(cfg.MODEL_ASPP_OUTDIM,
                                    momentum=cfg.TRAIN_BN_MOM),
            nn.ReLU(inplace=True),
            nn.Dropout(0.5),
            nn.Conv2d(cfg.MODEL_ASPP_OUTDIM,
                      cfg.MODEL_ASPP_OUTDIM,
                      3,
                      1,
                      padding=1,
                      bias=True),
            SynchronizedBatchNorm2d(cfg.MODEL_ASPP_OUTDIM,
                                    momentum=cfg.TRAIN_BN_MOM),
            nn.ReLU(inplace=True),
            nn.Dropout(0.1),
        )
        self.cls_conv = nn.Conv2d(cfg.MODEL_ASPP_OUTDIM,
                                  cfg.MODEL_NUM_CLASSES,
                                  1,
                                  1,
                                  padding=0)
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_normal_(m.weight,
                                        mode='fan_out',
                                        nonlinearity='relu')
            elif isinstance(m, SynchronizedBatchNorm2d):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0)
        self.backbone1 = build_backbone(cfg.MODEL_BACKBONE,
                                        os=cfg.MODEL_OUTPUT_STRIDE)
        self.backbone2 = build_backbone(cfg.MODEL_BACKBONE,
                                        os=cfg.MODEL_OUTPUT_STRIDE)
        self.backbone_layers1 = self.backbone1.get_layers()
        self.backbone_layers2 = self.backbone2.get_layers()
        self.tc_conv = nn.Sequential(
            nn.Conv2d(6, 96, 7, stride=3),  # 96*20*20
            nn.ReLU(inplace=True),  # 96*20*20
            nn.MaxPool2d(2),  # 96*10*10
            nn.Conv2d(96, 256, 5),  # 192*6*6
            nn.ReLU(),  # 192*6*6
            nn.MaxPool2d(2),  # 192*3*3
            nn.Conv2d(256, 512, 3),
            nn.ReLU()  # 256*1*1           
        )
        self.liner = nn.Sequential(nn.Linear(41472, 256), nn.ReLU())
        self.out = nn.Linear(256, 1)