• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Paper Reading- Center-based 3D Object Detection and Tracking (Based: KITTI)

武飞扬头像
Creator_Wei
帮助1

Background

随着2D目标检测的逐渐成熟,3D目标检测在近几年的研究领域受到了广泛的关注。但是3D目标的特性2D不同,面临着很多的挑战。

  • 点云的稀疏性;2D图像当前分辨率较高,但是点云相对于2D图像显得很稀疏,而且他举越远,点云越稀疏;
  • 点云目标大小不一致;3D目标有很多种类,没有固定的大小。导致很容易发生误检。它不同于2D有色彩信息,只可以通过空间关系判断当前目标属性;
  • 3D的bounding-box不好和全局的数据对齐;因为3D的bounding-box不同于传统2D,而且在一般的3D点云检测网络中会存在2D和3D特征提取网络,所以3D的bounding-box很难和全局数据做到对齐;

3D目标检测延续了2D目标检测的一些方法。3D的对象为了表示BBox(Bounding box),一般都是立体的。这种方法是模仿了2D中检测的方法。在传统的方法中,一般使用anchor。本文讲2D检测中的一篇十分经典的文章CenterNet在3D检测方面得到的实现,并且取得了不错的成绩。相比传统的ancher-based的方法,Center-Based point的方法有以下一些优点;

  1. 可以使用较少的计算量;Anchor-based的方法一般都是需要在map-viewer上铺设许多的anchor,之后再筛选符合要求的anchor作为最终的检测结果。Point-based的方法使用heatmap的方法,先筛选出需要的检测点以后再回归出对应的box;
  2. 有更好的目标方向判断;Anchor-based的方法是不仅需要预测目标分类和位置,还需要预测目标的角度。但是center-based的方法没有固定的方向,目标的方向是根据3D backbone提取的特征回归出来的,有更好的目标方向检测属性;
  3. 可以减少负样本的引入;Anchor-based的方法在得出目标角度的时候会得到很多的目标检测anchor,用于计算目标角度,这样的话会引入大量的false-postive的样本。Center-based的方法不会存在这样的问题;

Progress

  • PointCenter使用了点的方式表示了目标的位置,简化了三维目标检测的任务。也同时避免了因为点云中三维目标很难判断方向的问题。同时保证了点云的旋转不变性;
  • 使用点的方法,简化了下游任务。比如说是Tracking任务,如果track的对象是点的话,那么只需要预测对象在连续帧之间的相对偏移就可以了;
  • 文中提到了一点:基于点的方法可以更好的设计出一种比之前方法快的多的有效的两阶段细化模块(第二阶段在KITTI数据集中没有使用,只有在Waymo数据集中使用了);

CenterPoint Pipline

学新通

学新通

CenterPoint Architecture

CenterPoint分为三个阶段,分别是特征提取Backbone,HeatMap(First stage)和生成额外点的特征(Second stage),接下来对着三个阶段分别介绍。在说明CenterPoint之前,先普及一下CenterNet的知识;

CenterNet

在CenterNet中,网络会输入一张宽为学新通,高位学新通的图片。CenterNet会根据输入的图片生成以一个HeatMap(也就是Label),大小为学新通。根据输出的结果,会选比较周围的峰值是否大于当前结果,如果都小于当前结果则选取当前峰值为正样本(这个是个大致的结果)。而且,因为热力图的大小为学新通。所以可能会对检测带来一些误差。因此加入Offset。

学新通

 但是,为什么要在3D检测中,不使用用Anchor,而要使用基于点的检测方法呢?

主要是有两个原因。第一个是因为如果使用Anchor的话,其实面领着需要有巨大的运算量。第二个原因是因为基于anchor的方法的BBox的和坐标轴平齐的,但是在显是情况下,当车辆转弯时候基于anchor的方法没有办法很好的检测对象。论文中的一个图示很好的解释了这个问题。

学新通

Backbone

在CenterPoint中的过程大致描述如下(因为用的是kitti的,所以没有second stage):

  1. 点云输入,将输入的点云经过预处理(flap,rotation,scaling)之后处理成我们需要使用的点云;
  2. Point Encoder
    1. Voxel_feature的提取,在数据处理阶段已经将点云转换成voxel(transform_points_to_voxels()),之后使用MeanVFE对每个Voxel中的点求均值,得到每个Voxel的特征‘voxel_features’,这里的作用有点像对Voxel特征进行pooling操作;
    2. 对3D特征的提取。使用VoxelBackBone8x()对非空的Voxel_features进行3D特征提取,输出为经过稀疏卷积特征提取的特征向量,使得特征变为体素形式的特征。(在这里的稀疏卷积有点类似于Resnet);
    3. 将3D特征转化为2D特征。使用HeightCompression()将提取出的点云稀疏特征拍扁,变为BEV视角下的稀疏特征,在这一步中也就是将Channel和Dense相乘,增大了Z轴的感受野;
    4. 对转化后的2D特征继续进行2D特征提取。在这里包括了不同尺度的下采样和上采样,提取到了更多尺度的特征,在这里输出了一个大小为学新通的feature_map, 其中W表示宽,L表示长,F表示通道数;
  3. Center-Head,在Center-Head这里会生成3个Head,分别是Center heatmap head,Regression head, 和Velocity head & Track
    1. 根据标注数据生成基于高斯分布的heatmap的ground_truth, 在这里根据iou_threshold生成了计算出gaussian_radius。之后根据radius计算出学新通,使用学新通和标注数据生成groundtruth
    2. 根据之前在point encoder中生成的feature map,推理出中心点的位置(Decoder)。中心点的判断依据是当一个score大于周围8个score的时候,这个点就被认定为中心点。使用这个中心点个之前得到的gt,优化loss。
    3. 除了heatmap之外,还有一个Regression heads,主要用于回归出除中心点以外的其他属性(Decoder)。在Regression heads中需要使用3Dbackbone的输出在proposal中生成reg(x,y的位置偏移),height(高度),dim(box大小,包括w,h,l)和rot(偏航角正余弦,以yaw的sin和cos)。回归的目标是根据选取的中心点找到的真值。根据这个计算loss。

对于Centerpoint有两个Backbone(3D encoder)可以供选择,分别是PointPollars和VoxelNet这两种。对于PointPollars需要要相对较大的运算量,VoxelNet相对来说小一点。 在这里我只针对的是VoxelNet展开,以下是对于两种Backbone的测试结果 ;

学新通

在数据处理阶段,首先将点云划分成了不同的Voxel,根据如下方式。

  1.  
    def transform_points_to_voxels(self, data_dict=None, config=None, voxel_generator=None):
  2.  
    if data_dict is None:
  3.  
    try:
  4.  
    from spconv.utils import VoxelGeneratorV2 as VoxelGenerator
  5.  
    except:
  6.  
    from spconv.utils import VoxelGenerator
  7.  
     
  8.  
    voxel_generator = VoxelGenerator(
  9.  
    voxel_size=config.VOXEL_SIZE,
  10.  
    point_cloud_range=self.point_cloud_range,
  11.  
    max_num_points=config.MAX_POINTS_PER_VOXEL,
  12.  
    max_voxels=config.MAX_NUMBER_OF_VOXELS[self.mode]
  13.  
    )
  14.  
    grid_size = (self.point_cloud_range[3:6] - self.point_cloud_range[0:3]) / np.array(config.VOXEL_SIZE)
  15.  
    self.grid_size = np.round(grid_size).astype(np.int64)
  16.  
    self.voxel_size = config.VOXEL_SIZE
  17.  
    return partial(self.transform_points_to_voxels, voxel_generator=voxel_generator)
  18.  
     
  19.  
    points = data_dict['points']
  20.  
    voxel_output = voxel_generator.generate(points)
  21.  
    if isinstance(voxel_output, dict):
  22.  
    voxels, coordinates, num_points = \
  23.  
    voxel_output['voxels'], voxel_output['coordinates'], voxel_output['num_points_per_voxel']
  24.  
    else:
  25.  
    voxels, coordinates, num_points = voxel_output
  26.  
     
  27.  
    if not data_dict['use_lead_xyz']:
  28.  
    voxels = voxels[..., 3:] # remove xyz in voxels(N, 3)
  29.  
     
  30.  
    data_dict['voxels'] = voxels
  31.  
    data_dict['voxel_coords'] = coordinates
  32.  
    data_dict['voxel_num_points'] = num_points
  33.  
    return data_dict
学新通

在VoxleNet的Backbone中,对Voxle采用的均值的方法,对每个Voxel内的10个点的特征求了平平均。在代码中对应的是MeanVFE(Mean voxel feature encoding)部分。这里求平均值的作用是简化特征,用平均值代替本Voxel中的所有特征,这样可以加快计算速度

  1.  
    class MeanVFE(VFETemplate):
  2.  
    def __init__(self, model_cfg, num_point_features, **kwargs):
  3.  
    super().__init__(model_cfg=model_cfg)
  4.  
    self.num_point_features = num_point_features
  5.  
     
  6.  
    def get_output_feature_dim(self):
  7.  
    return self.num_point_features
  8.  
     
  9.  
    def forward(self, batch_dict, **kwargs):
  10.  
    """
  11.  
    Args:
  12.  
    batch_dict:
  13.  
    voxels: (num_voxels, max_points_per_voxel, C) voxel feature -> (12000,10,5)
  14.  
    voxel_num_points: optional (num_voxels) Voxle number of points -> (12000)
  15.  
    **kwargs:
  16.  
     
  17.  
    Returns:
  18.  
    vfe_features: (num_voxels, C)
  19.  
    """
  20.  
     
  21.  
    voxel_features, voxel_num_points = batch_dict['voxels'], batch_dict['voxel_num_points']
  22.  
    points_mean = voxel_features[:, :, :].sum(dim=1, keepdim=False) #对输入的10个点求和
  23.  
    normalizer = torch.clamp_min(voxel_num_points.view(-1, 1), min=1.0).type_as(voxel_features) #正则化,防止除0错误
  24.  
    points_mean = points_mean / normalizer #求均值
  25.  
    batch_dict['voxel_features'] = points_mean.contiguous() #返回均值 -> (12000,5)
  26.  
     
  27.  
    return batch_dict
学新通

在经过均值操作之后,输入到特征提取网络进行稀疏卷积的特征提取(因为点云在空间中的分布是离散的,即使分配到各个Voxel中也是有的Voxel有,有的没有。所以使用稀疏卷积可以有效地减少模型的运算量,帮助模型加速。具体稀疏卷积可以看一下这篇文章)。

  1.  
    '''
  2.  
    对3D特征进行提取,输入是MeanVFE的输出,输出为经过稀疏卷积的特征向量(有点类似PointNet ,把输入从原始点云换成了体素)
  3.  
    将Voxel_feature根据coors进行稀疏卷积,变成了体素特征,维度为(batch_size, channels, grid_nums_z, grid_nums_y,grid_nuns_x)
  4.  
    '''
  5.  
    class VoxelBackBone8x(nn.Module):
  6.  
    def __init__(self, model_cfg, input_channels, grid_size, **kwargs):
  7.  
    super().__init__()
  8.  
    self.model_cfg = model_cfg
  9.  
    norm_fn = partial(nn.BatchNorm1d, eps=1e-3, momentum=0.01)
  10.  
     
  11.  
    self.sparse_shape = grid_size[::-1] [1, 0, 0]
  12.  
    #稀疏卷积(因为点云是稀疏的,无法使用标准的卷积操作,稀疏卷积有助于模型加速)
  13.  
    #还有一个原因是如果使用普通卷积,会导致点云的稀疏性被损坏(也就是便稠密了,影响了几何轮廓的表示),会导致出现回归不准确的问题
  14.  
    self.conv_input = spconv.SparseSequential(
  15.  
    spconv.SubMConv3d(input_channels, 16, 3, padding=1, bias=False, indice_key='subm1'),
  16.  
    norm_fn(16),
  17.  
    nn.ReLU(),
  18.  
    )
  19.  
     
  20.  
    #这里的block代表选择什么卷积方式:
  21.  
    #subm: ubMConv3d
  22.  
    #spconv: SparseConv3d
  23.  
    #inverseconv: SparseInverseConv3d
  24.  
    block = post_act_block
  25.  
     
  26.  
    self.conv1 = spconv.SparseSequential(
  27.  
    block(16, 16, 3, norm_fn=norm_fn, padding=1, indice_key='subm1'),
  28.  
    )
  29.  
     
  30.  
    self.conv2 = spconv.SparseSequential(
  31.  
    # [1600, 1408, 41] <- [800, 704, 21]
  32.  
    block(16, 32, 3, norm_fn=norm_fn, stride=2, padding=1, indice_key='spconv2', conv_type='spconv'),
  33.  
    block(32, 32, 3, norm_fn=norm_fn, padding=1, indice_key='subm2'),
  34.  
    block(32, 32, 3, norm_fn=norm_fn, padding=1, indice_key='subm2'),
  35.  
    )
  36.  
     
  37.  
    self.conv3 = spconv.SparseSequential(
  38.  
    # [800, 704, 21] <- [400, 352, 11]
  39.  
    block(32, 64, 3, norm_fn=norm_fn, stride=2, padding=1, indice_key='spconv3', conv_type='spconv'),
  40.  
    block(64, 64, 3, norm_fn=norm_fn, padding=1, indice_key='subm3'),
  41.  
    block(64, 64, 3, norm_fn=norm_fn, padding=1, indice_key='subm3'),
  42.  
    )
  43.  
     
  44.  
    self.conv4 = spconv.SparseSequential(
  45.  
    # [400, 352, 11] <- [200, 176, 5]
  46.  
    block(64, 64, 3, norm_fn=norm_fn, stride=2, padding=(0, 1, 1), indice_key='spconv4', conv_type='spconv'),
  47.  
    block(64, 64, 3, norm_fn=norm_fn, padding=1, indice_key='subm4'),
  48.  
    block(64, 64, 3, norm_fn=norm_fn, padding=1, indice_key='subm4'),
  49.  
    )
  50.  
     
  51.  
    last_pad = 0
  52.  
    last_pad = self.model_cfg.get('last_pad', last_pad)
  53.  
    self.conv_out = spconv.SparseSequential(
  54.  
    # [200, 150, 5] -> [200, 150, 2]
  55.  
    spconv.SparseConv3d(64, 128, (3, 1, 1), stride=(2, 1, 1), padding=last_pad,
  56.  
    bias=False, indice_key='spconv_down2'),
  57.  
    norm_fn(128),
  58.  
    nn.ReLU(),
  59.  
    )
  60.  
    self.num_point_features = 128
  61.  
     
  62.  
    def forward(self, batch_dict):
  63.  
    """
  64.  
    Args:
  65.  
    batch_dict:
  66.  
    batch_size: int
  67.  
    vfe_features: (num_voxels, C)
  68.  
    voxel_coords: (num_voxels, 4), [batch_idx, z_idx, y_idx, x_idx]
  69.  
    Returns:
  70.  
    batch_dict:
  71.  
    encoded_spconv_tensor: sparse tensor
  72.  
    """
  73.  
     
  74.  
    '''
  75.  
    Voxel_feature(12000,5):Voxel的特征均值。Voxel_coords(12000,4):Voxel的坐标
  76.  
    '''
  77.  
    voxel_features, voxel_coords = batch_dict['voxel_features'], batch_dict['voxel_coords']
  78.  
    batch_size = batch_dict['batch_size']
  79.  
     
  80.  
    #变成了体素
  81.  
    #对Voxel_features按照coors进行索引,coors之前加入了一个维度(batch_indx),变成了4维[batch_idx, z_idx, y_idx, x_idx]
  82.  
    #输出为[batch_size, channels, sparse_shap],也就是[batch_size,channels,z_idx,y_idx,x_idx]
  83.  
    #将coors加入了排列,变成了体素空间的索引,也就是[batch_size,channels,z_idx,y_idx,x_idx]
  84.  
    input_sp_tensor = spconv.SparseConvTensor(
  85.  
    features=voxel_features,
  86.  
    indices=voxel_coords.int(),
  87.  
    spatial_shape=self.sparse_shape,
  88.  
    batch_size=batch_size
  89.  
    )
  90.  
    #经过一个稀疏卷积(SubMConv3d),feature.shape从[12000,5]变成[12000,16]
  91.  
    x = self.conv_input(input_sp_tensor)
  92.  
     
  93.  
    x_conv1 = self.conv1(x) #[12000,16]->[12000,16]
  94.  
    x_conv2 = self.conv2(x_conv1) #[12000,16]->[113293,32]
  95.  
    x_conv3 = self.conv3(x_conv2) #[113293,32]->[55250,64]
  96.  
    x_conv4 = self.conv4(x_conv3) #[55250,64]->[20650,64]
  97.  
     
  98.  
    # for detection head
  99.  
    # [200, 176, 5] -> [200, 176, 2]
  100.  
    out = self.conv_out(x_conv4)
  101.  
     
  102.  
     
  103.  
    batch_dict.update({
  104.  
    'encoded_spconv_tensor': out,
  105.  
    'encoded_spconv_tensor_stride': 8
  106.  
    })
  107.  
    batch_dict.update({
  108.  
    'multi_scale_3d_features': {
  109.  
    'x_conv1': x_conv1,
  110.  
    'x_conv2': x_conv2,
  111.  
    'x_conv3': x_conv3,
  112.  
    'x_conv4': x_conv4,
  113.  
    }
  114.  
    })
  115.  
     
  116.  
    return batch_dict
学新通

在上面的过程,也就是完成了对Backbone3D的过程,接下来需要完成Backbone2D的过程。 

经过稀疏卷积之后,提取出了当前点云的3D与特征。因为需要在BEV视角下做中心点检测。所以接下来需要将点云的稀疏特征转移到BEV视角上。在这里对Voxel特征在Z轴方向进行堆叠(也就是拍扁了)。这样的作用可以扩大在Z轴上的感受野婢妾简化了网络的计算难度。

  1.  
    class HeightCompression(nn.Module):
  2.  
    def __init__(self, model_cfg, **kwargs):
  3.  
    super().__init__()
  4.  
    self.model_cfg = model_cfg
  5.  
    self.num_bev_features = self.model_cfg.NUM_BEV_FEATURES #搞毒的特征数量
  6.  
     
  7.  
    def forward(self, batch_dict):
  8.  
    """
  9.  
    Args:
  10.  
    batch_dict:
  11.  
    encoded_spconv_tensor: sparse tensor
  12.  
    Returns:
  13.  
    batch_dict:
  14.  
    spatial_features:
  15.  
     
  16.  
    """
  17.  
    encoded_spconv_tensor = batch_dict['encoded_spconv_tensor'] #得到VoxelBackbone8x的输出
  18.  
    spatial_features = encoded_spconv_tensor.dense() #从Spocv的格式中取出体素格式的特征(这里将稀疏特征转化为了密集特征) dense()全连接层
  19.  
    N, C, D, H, W = spatial_features.shape #(Bacth_size,channel, Depth, Height, weight)
  20.  
    spatial_features = spatial_features.view(N, C * D, H, W) #将体素格式的特征转换为二维的BEV格式
  21.  
    batch_dict['spatial_features'] = spatial_features
  22.  
    batch_dict['spatial_features_stride'] = batch_dict['encoded_spconv_tensor_stride']
  23.  
    return batch_dict
学新通

3D特征被压扁之后,继续对2D的特征进行特征提取。目的是为了提取到更多特征。在这个过程中,对提取到的特征进行了上采样和下采样。目的是为了得到更多尺度的特征。

  1.  
    '''
  2.  
    对Spatial_feature提取的2D特征进行进一步的特征提取
  3.  
    得到2D的BEV下的特征
  4.  
    '''
  5.  
    class BaseBEVBackbone(nn.Module):
  6.  
    def __init__(self, model_cfg, input_channels):
  7.  
    super().__init__()
  8.  
    self.model_cfg = model_cfg
  9.  
     
  10.  
    if self.model_cfg.get('LAYER_NUMS', None) is not None:
  11.  
    assert len(self.model_cfg.LAYER_NUMS) == len(self.model_cfg.LAYER_STRIDES) == len(self.model_cfg.NUM_FILTERS)
  12.  
    layer_nums = self.model_cfg.LAYER_NUMS
  13.  
    layer_strides = self.model_cfg.LAYER_STRIDES
  14.  
    num_filters = self.model_cfg.NUM_FILTERS
  15.  
    else:
  16.  
    layer_nums = layer_strides = num_filters = []
  17.  
     
  18.  
    if self.model_cfg.get('UPSAMPLE_STRIDES', None) is not None:
  19.  
    assert len(self.model_cfg.UPSAMPLE_STRIDES) == len(self.model_cfg.NUM_UPSAMPLE_FILTERS)
  20.  
    num_upsample_filters = self.model_cfg.NUM_UPSAMPLE_FILTERS
  21.  
    upsample_strides = self.model_cfg.UPSAMPLE_STRIDES
  22.  
    else:
  23.  
    upsample_strides = num_upsample_filters = []
  24.  
     
  25.  
    num_levels = len(layer_nums)
  26.  
    c_in_list = [input_channels, *num_filters[:-1]]
  27.  
    self.blocks = nn.ModuleList()
  28.  
    self.deblocks = nn.ModuleList()
  29.  
    for idx in range(num_levels):
  30.  
    cur_layers = [
  31.  
    nn.ZeroPad2d(1),
  32.  
    nn.Conv2d(
  33.  
    c_in_list[idx], num_filters[idx], kernel_size=3,
  34.  
    stride=layer_strides[idx], padding=0, bias=False
  35.  
    ),
  36.  
    nn.BatchNorm2d(num_filters[idx], eps=1e-3, momentum=0.01),
  37.  
    nn.ReLU()
  38.  
    ]
  39.  
    for k in range(layer_nums[idx]):
  40.  
    cur_layers.extend([
  41.  
    nn.Conv2d(num_filters[idx], num_filters[idx], kernel_size=3, padding=1, bias=False),
  42.  
    nn.BatchNorm2d(num_filters[idx], eps=1e-3, momentum=0.01),
  43.  
    nn.ReLU()
  44.  
    ])
  45.  
    self.blocks.append(nn.Sequential(*cur_layers))
  46.  
    if len(upsample_strides) > 0:
  47.  
    stride = upsample_strides[idx]
  48.  
    if stride >= 1:
  49.  
    self.deblocks.append(nn.Sequential(
  50.  
    nn.ConvTranspose2d(
  51.  
    num_filters[idx], num_upsample_filters[idx],
  52.  
    upsample_strides[idx],
  53.  
    stride=upsample_strides[idx], bias=False
  54.  
    ),
  55.  
    nn.BatchNorm2d(num_upsample_filters[idx], eps=1e-3, momentum=0.01),
  56.  
    nn.ReLU()
  57.  
    ))
  58.  
    else:
  59.  
    stride = np.round(1 / stride).astype(np.int)
  60.  
    self.deblocks.append(nn.Sequential(
  61.  
    nn.Conv2d(
  62.  
    num_filters[idx], num_upsample_filters[idx],
  63.  
    stride,
  64.  
    stride=stride, bias=False
  65.  
    ),
  66.  
    nn.BatchNorm2d(num_upsample_filters[idx], eps=1e-3, momentum=0.01),
  67.  
    nn.ReLU()
  68.  
    ))
  69.  
     
  70.  
    c_in = sum(num_upsample_filters)
  71.  
    if len(upsample_strides) > num_levels:
  72.  
    self.deblocks.append(nn.Sequential(
  73.  
    nn.ConvTranspose2d(c_in, c_in, upsample_strides[-1], stride=upsample_strides[-1], bias=False),
  74.  
    nn.BatchNorm2d(c_in, eps=1e-3, momentum=0.01),
  75.  
    nn.ReLU(),
  76.  
    ))
  77.  
     
  78.  
    self.num_bev_features = c_in
  79.  
     
  80.  
    def forward(self, data_dict):
  81.  
    """
  82.  
    Args:
  83.  
    data_dict:
  84.  
    spatial_features
  85.  
    Returns:
  86.  
    """
  87.  
    spatial_features = data_dict['spatial_features']
  88.  
    ups = []
  89.  
    ret_dict = {}
  90.  
    x = spatial_features
  91.  
     
  92.  
    # 对不同分支进行卷积操作
  93.  
    '''
  94.  
    Centerpoint中有两个下采样层,一个是下采样到原图的大小,一个是下采样到BEV的大小
  95.  
    '''
  96.  
    for i in range(len(self.blocks)):
  97.  
    x = self.blocks[i](x)
  98.  
     
  99.  
    stride = int(spatial_features.shape[2] / x.shape[2])
  100.  
    ret_dict['spatial_features_%dx' % stride] = x
  101.  
    if len(self.deblocks) > 0:
  102.  
    ups.append(self.deblocks[i](x)) #反卷积,作用:上采样
  103.  
    else:
  104.  
    ups.append(x)
  105.  
     
  106.  
    if len(ups) > 1:
  107.  
    x = torch.cat(ups, dim=1) #(batch, c, 128, 128) -->> (batch, c*2, 128, 128)
  108.  
    elif len(ups) == 1:
  109.  
    x = ups[0]
  110.  
     
  111.  
    if len(self.deblocks) > len(self.blocks):
  112.  
    x = self.deblocks[-1](x)
  113.  
     
  114.  
    data_dict['spatial_features_2d'] = x
  115.  
    #输出
  116.  
    return data_dict
学新通

First stage: Centers & 3D boxs

在这里生成HeatMap的形式和CenterNet中的基本相似,其实就是一个3D Encoding的过程。在CenterNet中如果输入的图像大小是学新通。那么会对生成一个大小为学新通的HeatMap(其中学新通是检测的类别数)。在CenterPoint中,因为点云是离散的,并不是集中的。如果使用和CenterNet的办法的话则大部分都为背景,计算效率较低。CenterPoint中将目标对象放大实现高斯峰值。其中将高斯半径设置为学新通,其中学新通是最小的高斯半径,学新通为在CornerNet中定义的半径函数。 经过3D Encoding之后,输出的有:热力图,目标的尺寸,目标的朝向和目标的速度。;

在这里主要分为两步骤,首先会是生成ground_turth,第二是生成proposal

  1.  
    def forward(self, data_dict):
  2.  
    spatial_features_2d = data_dict['spatial_features_2d'] #获得BEV上的特征->(B, C, H, W)
  3.  
     
  4.  
    cls_preds = self.conv_cls(spatial_features_2d) #获得分类预测结果->(B, C, H, W)
  5.  
    box_preds = self.conv_box(spatial_features_2d) #获得回归预测结果->(B, C, H, W)
  6.  
     
  7.  
    cls_preds = cls_preds.permute(0, 2, 3, 1).contiguous() # [N, H, W, C]
  8.  
    box_preds = box_preds.permute(0, 2, 3, 1).contiguous() # [N, H, W, C]
  9.  
     
  10.  
    self.forward_ret_dict['cls_preds'] = cls_preds
  11.  
    self.forward_ret_dict['box_preds'] = box_preds
  12.  
     
  13.  
    if self.training:
  14.  
    targets_dict = self.assign_targets(
  15.  
    gt_boxes=data_dict['gt_boxes']
  16.  
    )
  17.  
    self.forward_ret_dict.update(targets_dict)
  18.  
     
  19.  
    if not self.training or self.predict_boxes_when_training:
  20.  
    batch_cls_preds, batch_box_preds = self.generate_predicted_boxes(
  21.  
    batch_size=data_dict['batch_size'],
  22.  
    cls_preds=cls_preds, box_preds=box_preds, dir_cls_preds=None
  23.  
    )
  24.  
    data_dict['batch_cls_preds'] = batch_cls_preds
  25.  
    data_dict['batch_box_preds'] = batch_box_preds
  26.  
    data_dict['cls_preds_normalized'] = False
  27.  
     
  28.  
    return data_dict
学新通

在这里计算loss的时候分为两种,一种是针对heatmap需要计算loss,另一个是需要针对box回归出的一些结果计算loss。最终针对Heatmap和回归值的loss相加,并且乘一定的比例,得出最终的loss,具体代码如下:

针对Heatmap的loss,需要首先生成Ground truth,然后根据预测值和Ground truth计算Heatmap的loss;

针对回归loss,在长宽高方面,根据坐标计算出长宽高,然后根据预测值和计算出的结果计算loss(只会再有中心点的位置计算)。因为输入和输出有一定的缩放,所以可能精度上会有损失,会对小物体的检测有一定的影响,所以在这里加入offset_loss;针对旋转角度,这里分成了两个,分别是sin_r_loss和cos_r_loss两个部分

  1.  
    def get_loss(self):
  2.  
    tb_dict = {}
  3.  
    pred_dicts = self.forward_ret_dict['multi_head_features']
  4.  
    center_loss = []
  5.  
    self.forward_ret_dict['pred_box_encoding'] = {}
  6.  
    for task_id, pred_dict in enumerate(pred_dicts):
  7.  
    pred_dict['hm'] = self._sigmoid(pred_dict['hm'])
  8.  
    hm_loss = self.crit(pred_dict['hm'], self.forward_ret_dict['heatmap'][task_id])
  9.  
     
  10.  
    target_box_encoding = self.forward_ret_dict['box_encoding'][task_id]
  11.  
    # nuscense encoding format [x, y, z, w, l, h, sinr, cosr, vx, vy]
  12.  
     
  13.  
    if self.dataset == 'nuscenes':
  14.  
    pred_box_encoding = torch.cat([
  15.  
    pred_dict['reg'],
  16.  
    pred_dict['height'],
  17.  
    pred_dict['dim'],
  18.  
    pred_dict['rot'],
  19.  
    pred_dict['vel']
  20.  
    ], dim = 1).contiguous() # (B, 10, H, W)
  21.  
    else:
  22.  
    pred_box_encoding = torch.cat([
  23.  
    pred_dict['reg'],
  24.  
    pred_dict['height'],
  25.  
    pred_dict['dim'],
  26.  
    pred_dict['rot']
  27.  
    ], dim = 1).contiguous() # (B, 8, H, W)
  28.  
     
  29.  
    self.forward_ret_dict['pred_box_encoding'][task_id] = pred_box_encoding
  30.  
    #Box_Loss
  31.  
    box_loss = self.crit_reg(
  32.  
    pred_box_encoding,
  33.  
    self.forward_ret_dict['mask'][task_id],
  34.  
    self.forward_ret_dict['ind'][task_id],
  35.  
    target_box_encoding
  36.  
    )
  37.  
     
  38.  
    loc_loss = (box_loss * box_loss.new_tensor(self.code_weights)).sum()
  39.  
    loss = hm_loss self.weight * loc_loss
  40.  
     
  41.  
    tb_key = 'task_' str(task_id) '/'
  42.  
     
  43.  
    if self.dataset == 'nuscenes':
  44.  
    tb_dict.update({
  45.  
    tb_key 'loss': loss.item(), tb_key 'hm_loss': hm_loss.item(), tb_key 'loc_loss': loc_loss.item(),
  46.  
    tb_key 'x_loss': box_loss[0].item(), tb_key 'y_loss': box_loss[1].item(), tb_key 'z_loss': box_loss[2].item(),
  47.  
    tb_key 'w_loss': box_loss[3].item(), tb_key 'l_loss': box_loss[4].item(), tb_key 'h_loss': box_loss[5].item(),
  48.  
    tb_key 'sin_r_loss': box_loss[6].item(), tb_key 'cos_r_loss': box_loss[7].item(),
  49.  
    tb_key 'vx_loss': box_loss[8].item(), tb_key 'vy_loss': box_loss[9].item(),
  50.  
    tb_key 'num_positive': self.forward_ret_dict['mask'][task_id].float().sum(),
  51.  
    })
  52.  
    else:
  53.  
    tb_dict.update({
  54.  
    tb_key 'loss': loss.item(), tb_key 'hm_loss': hm_loss.item(),
  55.  
    tb_key 'loc_loss': loc_loss.item(),
  56.  
    tb_key 'x_loss': box_loss[0].item(), tb_key 'y_loss': box_loss[1].item(),
  57.  
    tb_key 'z_loss': box_loss[2].item(),
  58.  
    tb_key 'w_loss': box_loss[3].item(), tb_key 'l_loss': box_loss[4].item(),
  59.  
    tb_key 'h_loss': box_loss[5].item(),
  60.  
    tb_key 'sin_r_loss': box_loss[6].item(), tb_key 'cos_r_loss': box_loss[7].item(),
  61.  
    tb_key 'num_positive': self.forward_ret_dict['mask'][task_id].float().sum(),
  62.  
    })
  63.  
    center_loss.append(loss)
  64.  
     
  65.  
    return sum(center_loss), tb_dict
学新通

Second stage: Score & 3D boxes

第二阶段只有在Waymo数据集和nuScenes数据集中有使用,在KITTI中并没有使用。总的来说,其实就是又进行了一次特征提取,也就是用了第一阶段检测对象的一些附加特征来细化了估计。在第二阶段中,使用了之前预测的边框的四个面(只考虑周围的4个面,顶部和底部的面中心都是中心点)的中心点提取特征。对于每个点,在文章中提到了使用线性插值的方法从主干Map中输出特征,最后将此特征传递给MLP,对第二阶段进行特征细化。

Loss

对于与类别无关的置信度预测使用预测结果与IoU计算Loss, 如图:

学新通

对于训练时使用交叉熵损失函数计算Loss,如图:

学新通

Experiments

作者这里主要在Waymo和nuScenes数据集上进行了测试,Waymo结果如下: 

学新通

 nuScenes数据集结果:

学新通

 对于KITTI数据集上的结果,我按照centerpoint.yaml跑的,也就是使用的VoxelNet的Backbone,没有第二阶段优化(作者说第二阶段在KITTI上并没有很好的效果,所以没有用)结果如下:

  1.  
    2022-08-19 00:19:20,746 INFO *************** EPOCH 80 EVALUATION *****************
  2.  
    eval: 100% 1257/1257 [02:45<00:00, 7.61it/s, recall_0.3=(0, 16574) / 17558]
  3.  
    2022-08-19 00:22:05,838 INFO *************** Performance of EPOCH 80 *****************
  4.  
    2022-08-19 00:22:05,838 INFO Generate label finished(sec_per_example: 0.0438 second).
  5.  
    2022-08-19 00:22:05,838 INFO recall_roi_0.3: 0.000000
  6.  
    2022-08-19 00:22:05,839 INFO recall_rcnn_0.3: 0.943957
  7.  
    2022-08-19 00:22:05,839 INFO recall_roi_0.5: 0.000000
  8.  
    2022-08-19 00:22:05,839 INFO recall_rcnn_0.5: 0.884326
  9.  
    2022-08-19 00:22:05,839 INFO recall_roi_0.7: 0.000000
  10.  
    2022-08-19 00:22:05,839 INFO recall_rcnn_0.7: 0.650871
  11.  
    2022-08-19 00:22:05,842 INFO Average predicted number of objects(3769 samples): 14.189
  12.  
    2022-08-19 00:22:25,293 INFO Car AP@0.70, 0.70, 0.70:
  13.  
    bbox AP:95.1977, 89.6228, 88.9443
  14.  
    bev AP:89.5762, 87.3362, 84.9389
  15.  
    3d AP:87.8885, 78.1958, 76.9271
  16.  
    aos AP:95.15, 89.50, 88.76
  17.  
    Car AP_R40@0.70, 0.70, 0.70:
  18.  
    bbox AP:97.6645, 93.8115, 91.6160
  19.  
    bev AP:92.1521, 88.1394, 87.0467
  20.  
    3d AP:89.8526, 80.9555, 76.7696
  21.  
    aos AP:97.62, 93.66, 91.41
  22.  
    Car AP@0.70, 0.50, 0.50:
  23.  
    bbox AP:95.1977, 89.6228, 88.9443
  24.  
    bev AP:95.2045, 89.6821, 89.1962
  25.  
    3d AP:95.1455, 89.6365, 89.1102
  26.  
    aos AP:95.15, 89.50, 88.76
  27.  
    Car AP_R40@0.70, 0.50, 0.50:
  28.  
    bbox AP:97.6645, 93.8115, 91.6160
  29.  
    bev AP:97.6538, 94.5334, 93.8886
  30.  
    3d AP:97.5949, 94.4241, 93.6071
  31.  
    aos AP:97.62, 93.66, 91.41
  32.  
    Pedestrian AP@0.50, 0.50, 0.50:
  33.  
    bbox AP:72.8755, 69.8601, 67.5803
  34.  
    bev AP:59.0602, 56.1858, 53.7814
  35.  
    3d AP:55.9983, 52.7308, 48.4896
  36.  
    aos AP:70.86, 67.22, 64.51
  37.  
    Pedestrian AP_R40@0.50, 0.50, 0.50:
  38.  
    bbox AP:72.8309, 70.8996, 67.8249
  39.  
    bev AP:58.7370, 56.0706, 52.6835
  40.  
    3d AP:54.1025, 51.4533, 47.5276
  41.  
    aos AP:70.72, 67.81, 64.29
  42.  
    Pedestrian AP@0.50, 0.25, 0.25:
  43.  
    bbox AP:72.8755, 69.8601, 67.5803
  44.  
    bev AP:76.5677, 76.0058, 73.3515
  45.  
    3d AP:76.2825, 75.5901, 72.9315
  46.  
    aos AP:70.86, 67.22, 64.51
  47.  
    Pedestrian AP_R40@0.50, 0.25, 0.25:
  48.  
    bbox AP:72.8309, 70.8996, 67.8249
  49.  
    bev AP:78.5230, 77.4655, 74.4151
  50.  
    3d AP:78.1941, 76.9804, 73.7875
  51.  
    aos AP:70.72, 67.81, 64.29
  52.  
    Cyclist AP@0.50, 0.50, 0.50:
  53.  
    bbox AP:88.2125, 79.4905, 76.0368
  54.  
    bev AP:86.1723, 70.7543, 67.7885
  55.  
    3d AP:77.0715, 64.8973, 60.6476
  56.  
    aos AP:88.06, 79.12, 75.66
  57.  
    Cyclist AP_R40@0.50, 0.50, 0.50:
  58.  
    bbox AP:92.1393, 80.4166, 77.3878
  59.  
    bev AP:86.9190, 71.4113, 67.6574
  60.  
    3d AP:80.4734, 64.4435, 60.6898
  61.  
    aos AP:91.93, 80.02, 76.99
  62.  
    Cyclist AP@0.50, 0.25, 0.25:
  63.  
    bbox AP:88.2125, 79.4905, 76.0368
  64.  
    bev AP:88.7953, 75.6457, 72.2460
  65.  
    3d AP:88.7953, 75.6457, 72.2460
  66.  
    aos AP:88.06, 79.12, 75.66
  67.  
    Cyclist AP_R40@0.50, 0.25, 0.25:
  68.  
    bbox AP:92.1393, 80.4166, 77.3878
  69.  
    bev AP:90.0662, 76.6310, 73.2075
  70.  
    3d AP:90.0662, 76.6310, 73.2075
  71.  
    aos AP:91.93, 80.02, 76.99
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgafgik
系列文章
更多 icon
同类精品
更多 icon
继续加载