def __init__(self): super(SegmentationModuleBase, self).__init__() # For cache self.mapping_to_detectron = None self.orphans_in_detectron = None self.iter = 0 self.draw = False builder = semseg_heads.ModelBuilder() #define encoder if cfg.SEM.USE_RESNET: self.encoder = get_func(cfg.MODEL.CONV_BODY)() else: 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 3DSD loss self.crit = nn.NLLLoss(ignore_index=255 * cfg.DISP.MAX_DISPLACEMENT + 1) self.SmoothL1Loss = nn.SmoothL1Loss( reduction='none') #elementwise_mean self.disp_gain = 1.0 * cfg.DISP.EXPECT_MAXDISP / cfg.DISP.MAX_DISPLACEMENT print('epe of each pixel is set to %.2f' % self.disp_gain) self.BCELoss = nn.BCELoss(reduction='elementwise_mean')
def __init__(self): super(SegmentationModuleBase, self).__init__() print("hello") # For cache self.mapping_to_detectron = None self.orphans_in_detectron = None self.iter=0 self.draw=False builder = semseg_heads.ModelBuilder() #define encoder if cfg.SEM.USE_RESNET: self.encoder = get_func(cfg.MODEL.CONV_BODY)() else: 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='') self.crit = nn.NLLLoss(ignore_index=255) self.deep_sup_scale = cfg.SEM.DEEP_SUB_SCALE if cfg.DISP.ORIGINAL: self.conv_last_disp = nn.Conv2d(cfg.DISP.DIM*2,1,kernel_size=3,padding=1,bias=False) self.conv_last_disp.apply(self._init_weights_normal) if cfg.DISP.USE_CRL_DISPFUL: self.conv_last_disp = CRL.DispFulNetSubset() if cfg.DISP.USE_CRL_DISPRES: self.conv_last_disp = CRL.DispResNetSubset(), self.conv_last_disp.apply(self._init_weights_normal) self.SmoothL1Loss = nn.SmoothL1Loss(reduction='none') #elementwise_mean #self.disp_loss = self._disp_loss #self.hardtanh = nn.Hardtanh(-1, 1,inplace=True) 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) ) self.disp_deepsup.apply(self._init_weights_kaiming)
def __init__(self): super(SegmentationModuleBase, self).__init__() print("hello") # For cache self.mapping_to_detectron = None self.orphans_in_detectron = None self.iter=0 self.draw=False builder = semseg_heads.ModelBuilder() #define encoder if cfg.SEM.USE_RESNET: self.encoder = get_func(cfg.MODEL.CONV_BODY)() else: 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='') self.minipsm = semseg_heads.MiniPSMNet() self.fusion = semseg_heads.FusionNet() 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.SmoothL1Loss = nn.SmoothL1Loss(reduction='none') #elementwise_mean self.multiScaleLoss = Lossfuction.MultiScaleLoss(scales=4,downscale=1,loss='L1').to('cuda')