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, 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 test_sparse_encoder(): if not torch.cuda.is_available(): pytest.skip('test requires GPU and torch+cuda') sparse_encoder_cfg = dict( type='SparseEncoder', in_channels=5, sparse_shape=[40, 1024, 1024], order=('conv', 'norm', 'act'), encoder_channels=((16, 16, 32), (32, 32, 64), (64, 64, 128), (128, 128)), encoder_paddings=((1, 1, 1), (1, 1, 1), (1, 1, 1), (1, 1, 1), (1, 1, 1)), block_type='basicblock') sparse_encoder = build_middle_encoder(sparse_encoder_cfg).cuda() voxel_features = torch.rand([207842, 5]).cuda() coors = torch.randint(0, 4, [207842, 4]).cuda() ret = sparse_encoder(voxel_features, coors, 4) assert ret.shape == torch.Size([4, 256, 128, 128])
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): super(MultiTaskSep, 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) self.train_cfg = train_cfg self.test_cfg = test_cfg self.init_weights(pretrained=pretrained)