def __init__(self, voxel_layer, voxel_encoder, middle_encoder, backbone, neck=None, bbox_head=None, train_cfg=None, test_cfg=None, pretrained=None): super(VoxelNet, self).__init__( backbone=backbone, neck=neck, bbox_head=bbox_head, train_cfg=train_cfg, test_cfg=test_cfg, pretrained=pretrained, ) self.voxel_layer = Voxelization(**voxel_layer) self.voxel_encoder = builder.build_voxel_encoder(voxel_encoder) self.middle_encoder = builder.build_middle_encoder(middle_encoder) self.img_encoder = ImgFeatExtractor() self.refmap_encoder = nn.Sequential( nn.Conv2d(1, 64, kernel_size=3, padding=1, stride=1), nn.BatchNorm2d(64), nn.ReLU(), nn.Conv2d(64, 64, kernel_size=3, padding=1, stride=2), nn.BatchNorm2d(64), nn.ReLU()) self.ref_to_cls = nn.Sequential(nn.Conv2d(64, 18, kernel_size=1), nn.BatchNorm2d(18), nn.ReLU())
def __init__(self, pts_voxel_layer=None, pts_voxel_encoder=None, pts_middle_encoder=None, img_backbone=None, img_seg_head=None, pts_backbone=None, pts_neck=None, pts_bbox_head=None, train_cfg=None, test_cfg=None, pretrained=None, pts_fc=[], contrast_criterion=None, max_pts=4096, lambda_contrast=0.1): super(FusionContrastV2, self).__init__() if img_backbone: self.img_backbone = builder.build_backbone(img_backbone) if img_seg_head: self.img_seg_head = builder.build_head(img_seg_head) if pts_voxel_layer: self.pts_voxel_layer = Voxelization(**pts_voxel_layer) if pts_voxel_encoder: self.pts_voxel_encoder = builder.build_voxel_encoder( pts_voxel_encoder) if pts_middle_encoder: self.pts_middle_encoder = builder.build_middle_encoder( pts_middle_encoder) if pts_backbone: self.pts_backbone = builder.build_backbone(pts_backbone) if pts_neck: self.pts_neck = builder.build_neck(pts_neck) if pts_bbox_head: pts_train_cfg = train_cfg.pts if train_cfg else None pts_bbox_head.update(train_cfg=pts_train_cfg) pts_test_cfg = test_cfg.pts if test_cfg else None pts_bbox_head.update(test_cfg=pts_test_cfg) self.pts_bbox_head = builder.build_head(pts_bbox_head) if contrast_criterion: self.contrast_criterion = builder.build_loss(contrast_criterion) self.max_pts = max_pts self.lambda_contrast = lambda_contrast fc_layers = [] for i, (in_c, out_c) in enumerate(zip(pts_fc[:-1], pts_fc[1:])): fc_layers.append(nn.Linear(in_c, out_c)) if i == len(pts_fc) - 2: break fc_layers.append(nn.ReLU(inplace=True)) self.fc_layers = nn.Sequential(*fc_layers) self.train_cfg = train_cfg self.test_cfg = test_cfg self.init_weights(pretrained=pretrained)
def __init__(self, pts_voxel_layer=None, pts_voxel_encoder=None, pts_middle_encoder=None, pts_fusion_layer=None, img_backbone=None, pts_backbone=None, img_neck=None, pts_neck=None, pts_bbox_head=None, img_roi_head=None, img_rpn_head=None, train_cfg=None, test_cfg=None, pretrained=None): super(MVXTwoStageDetector, self).__init__() if 'type' in pts_voxel_layer: self.pts_voxel_cfg = pts_voxel_layer else: self.pts_voxel_layer = Voxelization(**pts_voxel_layer) #if pts_voxel_encoder: # self.pts_voxel_encoder = builder.build_voxel_encoder( # pts_voxel_encoder) if pts_middle_encoder: self.pts_middle_encoder = builder.build_middle_encoder( pts_middle_encoder) if pts_backbone: self.pts_backbone = builder.build_backbone(pts_backbone) if pts_fusion_layer: self.pts_fusion_layer = builder.build_fusion_layer( pts_fusion_layer) if pts_neck is not None: self.pts_neck = builder.build_neck(pts_neck) if pts_bbox_head: pts_train_cfg = train_cfg.pts if train_cfg else None pts_bbox_head.update(train_cfg=pts_train_cfg) pts_test_cfg = test_cfg.pts if test_cfg else None pts_bbox_head.update(test_cfg=pts_test_cfg) self.pts_bbox_head = builder.build_head(pts_bbox_head) if img_backbone: self.img_backbone = builder.build_backbone(img_backbone) if img_neck is not None: self.img_neck = builder.build_neck(img_neck) if img_rpn_head is not None: self.img_rpn_head = builder.build_head(img_rpn_head) if img_roi_head is not None: self.img_roi_head = builder.build_head(img_roi_head) self.train_cfg = train_cfg self.test_cfg = test_cfg self.init_weights(pretrained=pretrained)
def __init__(self, model_cfg, num_point_features, voxel_size, point_cloud_range, mode='max', norm_cfg=dict(type='BN1d', eps=1e-3, momentum=0.01)): super().__init__(model_cfg=model_cfg) self.point_cloud_range = point_cloud_range self.vx = voxel_size[0] self.vy = voxel_size[1] self.vz = voxel_size[2] self.x_offset = self.vx / 2 + point_cloud_range[0] self.y_offset = self.vy / 2 + point_cloud_range[1] self.z_offset = self.vz / 2 + point_cloud_range[2] # self.use_norm = self.model_cfg.USE_NORM self.with_distance = self.model_cfg.WITH_DISTANCE self.use_absolute_xyz = self.model_cfg.USE_ABSLOTE_XYZ num_point_features += 5 if self.use_absolute_xyz else 3 if self.with_distance: num_point_features += 1 self.num_filters = self.model_cfg.NUM_FILTERS assert len(self.num_filters) > 0 self.num_filters = [num_point_features] + list(self.num_filters) pfn_layers = [] # TODO: currently only support one PFNLayer for i in range(len(self.num_filters) - 1): in_filters = self.num_filters[i] out_filters = self.num_filters[i + 1] if i > 0: in_filters *= 2 _, norm_layer = build_norm_layer(norm_cfg, out_filters) pfn_layers.append( nn.Sequential(nn.Linear(in_filters, out_filters, bias=False), norm_layer, nn.ReLU(inplace=True))) self.num_pfn = len(pfn_layers) self.pfn_layers = nn.ModuleList(pfn_layers) self.pfn_scatter = DynamicScatter(voxel_size, point_cloud_range, (mode != 'max')) self.cluster_scatter = DynamicScatter(voxel_size, point_cloud_range, average_points=True) voxel_layer = dict(max_num_points=-1, point_cloud_range=point_cloud_range, voxel_size=voxel_size, max_voxels=(-1, -1)) self.voxel_layer = Voxelization(**voxel_layer)
def __init__(self, pts_voxel_layer=None, pts_voxel_encoder=None, pts_middle_encoder=None, img_backbone=None, img_seg_head=None, pts_backbone=None, pts_neck=None, pts_bbox_head=None, train_cfg=None, test_cfg=None, pretrained=None, pts_fc=[]): super(FusionBaseline4, self).__init__() if img_backbone: self.img_backbone = builder.build_backbone(img_backbone) if img_seg_head: self.img_seg_head = builder.build_head(img_seg_head) if pts_voxel_layer: self.pts_voxel_layer = Voxelization(**pts_voxel_layer) if pts_voxel_encoder: self.pts_voxel_encoder = builder.build_voxel_encoder( pts_voxel_encoder) if pts_middle_encoder: self.pts_middle_encoder = builder.build_middle_encoder( pts_middle_encoder) if pts_backbone: self.pts_backbone = builder.build_backbone(pts_backbone) if pts_neck is not None: self.pts_neck = builder.build_neck(pts_neck) if pts_bbox_head: pts_train_cfg = train_cfg.pts if train_cfg else None pts_bbox_head.update(train_cfg=pts_train_cfg) pts_test_cfg = test_cfg.pts if test_cfg else None pts_bbox_head.update(test_cfg=pts_test_cfg) self.pts_bbox_head = builder.build_head(pts_bbox_head) fc_layers = [] for i, (in_c, out_c) in enumerate(zip(pts_fc[:-1], pts_fc[1:])): fc_layers.append(nn.Linear(in_c, out_c)) if i == len(pts_fc) - 2: break fc_layers.append(nn.ReLU(inplace=True)) self.fc_layers = nn.Sequential(*fc_layers) self.train_cfg = train_cfg self.test_cfg = test_cfg self.init_weights(pretrained=pretrained)
def __init__(self, pts_voxel_layer=None, pts_voxel_encoder=None, pts_middle_encoder=None, img_backbone=None, img_seg_head=None, pts_backbone=None, pts_neck=None, pts_bbox_head=None, train_cfg=None, test_cfg=None, pretrained=None, vfes=[]): super(FusionBaseline, self).__init__() if img_backbone: self.img_backbone = builder.build_backbone(img_backbone) if img_seg_head: self.img_seg_head = builder.build_head(img_seg_head) if pts_voxel_layer: self.pts_voxel_layer = Voxelization(**pts_voxel_layer) if pts_voxel_encoder: self.pts_voxel_encoder = builder.build_voxel_encoder( pts_voxel_encoder) if pts_middle_encoder: self.pts_middle_encoder = builder.build_middle_encoder( pts_middle_encoder) if pts_backbone: self.pts_backbone = builder.build_backbone(pts_backbone) if pts_neck is not None: self.pts_neck = builder.build_neck(pts_neck) if pts_bbox_head: pts_train_cfg = train_cfg.pts if train_cfg else None pts_bbox_head.update(train_cfg=pts_train_cfg) pts_test_cfg = test_cfg.pts if test_cfg else None pts_bbox_head.update(test_cfg=pts_test_cfg) self.pts_bbox_head = builder.build_head(pts_bbox_head) vfe_layers = [] for in_c, out_c in zip(vfes[:-1], vfes[1:]): vfe_layers.append(VFELayer(in_c, out_c, max_out=False)) self.vfe_layers = nn.Sequential(*vfe_layers) self.train_cfg = train_cfg self.test_cfg = test_cfg self.init_weights(pretrained=pretrained)
def __init__(self, pts_voxel_layer=None, pts_voxel_encoder=None, pts_middle_encoder=None, pts_fusion_layer=None, img_backbone=None, pts_backbone=None, pts_neck=None, pts_bbox_head=None, img_seg_head=None, train_cfg=None, test_cfg=None, pretrained=None): super(MMDA, self).__init__() if pts_voxel_layer: self.pts_voxel_layer = Voxelization(**pts_voxel_layer) if pts_voxel_encoder: self.pts_voxel_encoder = builder.build_voxel_encoder( pts_voxel_encoder) if pts_middle_encoder: self.pts_middle_encoder = builder.build_middle_encoder( pts_middle_encoder) if pts_backbone: self.pts_backbone = builder.build_backbone(pts_backbone) if pts_fusion_layer: self.pts_fusion_layer = builder.build_fusion_layer( pts_fusion_layer) if pts_neck is not None: self.pts_neck = builder.build_neck(pts_neck) if pts_bbox_head: pts_train_cfg = train_cfg.pts if train_cfg else None pts_bbox_head.update(train_cfg=pts_train_cfg) pts_test_cfg = test_cfg.pts if test_cfg else None pts_bbox_head.update(test_cfg=pts_test_cfg) self.pts_bbox_head = builder.build_head(pts_bbox_head) if img_backbone: self.img_backbone = builder.build_backbone(img_backbone) if img_seg_head: self.img_seg_head = builder.build_head(img_seg_head) self.train_cfg = train_cfg self.test_cfg = test_cfg self.init_weights(pretrained=pretrained)
def __init__(self, voxel_layer, voxel_encoder, middle_encoder, backbone, neck=None, rpn_head=None, roi_head=None, train_cfg=None, test_cfg=None, pretrained=None): super(PartA2, self).__init__( backbone=backbone, neck=neck, rpn_head=rpn_head, roi_head=roi_head, train_cfg=train_cfg, test_cfg=test_cfg, pretrained=pretrained, ) self.voxel_layer = Voxelization(**voxel_layer) self.voxel_encoder = builder.build_voxel_encoder(voxel_encoder) self.middle_encoder = builder.build_middle_encoder(middle_encoder) # 转换RangeImage部分相关代码 self.H = 48 self.W = 512 self.fov_up = 3 self.fov_down = -15.0 self.pi = torch.tensor(np.pi) fov_up = self.fov_up * self.pi / 180.0 fov_down = self.fov_down * self.pi / 180.0 fov = abs(fov_up) + abs(fov_down) self.uv = torch.zeros((2, self.H, self.W)) self.uv[1] = torch.arange(0, self.W) self.uv.permute((0, 2, 1))[0] = torch.arange(0, self.H) self.uv[0] = ( (self.H - self.uv[0]) * fov - abs(fov_down) * self.H) / self.H self.uv[1] = (self.uv[1] * 2.0 - self.W) * self.pi / ( self.W * 4) # 最后一个 4 用来控制水平范围 # self.range_encoder = RangeEncoder(5, 64, use_img=True) self.fusion = Fusion(5, 3)
def __init__(self, voxel_layer, voxel_encoder, middle_encoder, backbone, neck=None, bbox_head=None, train_cfg=None, test_cfg=None, pretrained=None): super(VoxelNet, self).__init__( backbone=backbone, neck=neck, bbox_head=bbox_head, train_cfg=train_cfg, test_cfg=test_cfg, pretrained=pretrained, ) self.voxel_layer = Voxelization(**voxel_layer) self.voxel_encoder = builder.build_voxel_encoder(voxel_encoder) self.middle_encoder = builder.build_middle_encoder(middle_encoder)
def __init__(self, voxel_layer, voxel_encoder, middle_encoder, backbone, neck=None, rpn_head=None, roi_head=None, train_cfg=None, test_cfg=None, pretrained=None, init_cfg=None): super(PartA2, self).__init__(backbone=backbone, neck=neck, rpn_head=rpn_head, roi_head=roi_head, train_cfg=train_cfg, test_cfg=test_cfg, pretrained=pretrained, init_cfg=init_cfg) self.voxel_layer = Voxelization(**voxel_layer) self.voxel_encoder = builder.build_voxel_encoder(voxel_encoder) self.middle_encoder = builder.build_middle_encoder(middle_encoder)
def __init__(self, voxel_layer, voxel_encoder, middle_encoder, backbone, neck=None, bbox_head=None, train_cfg=None, test_cfg=None, pretrained=None): super(VoxelNet_RAN, self).__init__( backbone=backbone, neck=neck, bbox_head=bbox_head, train_cfg=train_cfg, test_cfg=test_cfg, pretrained=pretrained, ) self.voxel_layer = Voxelization(**voxel_layer) # self.backbone_second = build_backbone(backbone) # if neck is not None: # self.neck_secondfpn = build_neck(neck) self.voxel_encoder = builder.build_voxel_encoder(voxel_encoder) self.middle_encoder = builder.build_middle_encoder(middle_encoder)
def __init__(self, pts_voxel_layer=None, pts_voxel_encoder=None, pts_middle_encoder=None, pts_fusion_layer=None, img_backbone=None, pts_backbone=None, img_neck=None, pts_neck=None, pts_bbox_head=None, img_roi_head=None, img_rpn_head=None, train_cfg=None, test_cfg=None, pretrained=None, init_cfg=None): super(MVXTwoStageDetector, self).__init__(init_cfg=init_cfg) if pts_voxel_layer: self.pts_voxel_layer = Voxelization(**pts_voxel_layer) if pts_voxel_encoder: self.pts_voxel_encoder = builder.build_voxel_encoder( pts_voxel_encoder) if pts_middle_encoder: self.pts_middle_encoder = builder.build_middle_encoder( pts_middle_encoder) if pts_backbone: self.pts_backbone = builder.build_backbone(pts_backbone) if pts_fusion_layer: self.pts_fusion_layer = builder.build_fusion_layer( pts_fusion_layer) if pts_neck is not None: self.pts_neck = builder.build_neck(pts_neck) if pts_bbox_head: pts_train_cfg = train_cfg.pts if train_cfg else None pts_bbox_head.update(train_cfg=pts_train_cfg) pts_test_cfg = test_cfg.pts if test_cfg else None pts_bbox_head.update(test_cfg=pts_test_cfg) self.pts_bbox_head = builder.build_head(pts_bbox_head) if img_backbone: self.img_backbone = builder.build_backbone(img_backbone) if img_neck is not None: self.img_neck = builder.build_neck(img_neck) if img_rpn_head is not None: self.img_rpn_head = builder.build_head(img_rpn_head) if img_roi_head is not None: self.img_roi_head = builder.build_head(img_roi_head) self.train_cfg = train_cfg self.test_cfg = test_cfg if pretrained is None: img_pretrained = None pts_pretrained = None elif isinstance(pretrained, dict): img_pretrained = pretrained.get('img', None) pts_pretrained = pretrained.get('pts', None) else: raise ValueError( f'pretrained should be a dict, got {type(pretrained)}') if self.with_img_backbone: if img_pretrained is not None: warnings.warn('DeprecationWarning: pretrained is a deprecated \ key, please consider using init_cfg') self.img_backbone.init_cfg = dict(type='Pretrained', checkpoint=img_pretrained) if self.with_img_roi_head: if img_pretrained is not None: warnings.warn('DeprecationWarning: pretrained is a deprecated \ key, please consider using init_cfg') self.img_roi_head.init_cfg = dict(type='Pretrained', checkpoint=img_pretrained) if self.with_pts_backbone: if img_pretrained is not None: warnings.warn('DeprecationWarning: pretrained is a deprecated \ key, please consider using init_cfg') self.pts_backbone.init_cfg = dict(type='Pretrained', checkpoint=pts_pretrained)