OpenPCDet series | 7.1 KITTI dataset test process predicted_boxes prediction

AnchorHeadTemplate.generate_predicted_boxes部分

The structure diagram of the test process is as follows:
insert image description here

The initial data input of the generate_predicted_boxes function is:
insert image description here

First, reshape the feature maps of various types of predictions, and stitch the anchor dimension, for example: (16, 248, 216, 42) -> (16, 321408, 7). But there are caveats here. The box information of the feature prediction is based on an offset of the anchor, that is, the encoded offset coefficient, so it needs to be decoded in the original way to obtain the real box information.

# 各种维度的reshape处理
anchors = torch.cat(self.anchors, dim=-3)   # (1, 248, 216, 3, 2, 7)
num_anchors = anchors.view(-1, anchors.shape[-1]).shape[0]  # 3个类别+2个方向 在特征图上的总anchor数 321408
batch_anchors = anchors.view(1, -1, anchors.shape[-1]).repeat(batch_size, 1, 1)     # (16, 321408, 7)
batch_cls_preds = cls_preds.view(batch_size, num_anchors, -1).float() \
    if not isinstance(cls_preds, list) else cls_preds   # (16, 248, 216, 18) -> (16, 321408, 3)
batch_box_preds = box_preds.view(batch_size, num_anchors, -1) if not isinstance(box_preds, list) \
    else torch.cat(box_preds, dim=1).view(batch_size, num_anchors, -1)    # (16, 248, 216, 42) -> (16, 321408, 7)
# 解码回去
batch_box_preds = self.box_coder.decode_torch(batch_box_preds, batch_anchors)   # 根据pred和anchor解码为正常的尺寸 (16, 321408, 7)

If there is a direction prediction feature, it is also reshaped. The prediction feature here (16, 321408, 2) represents the prediction probability of each anchor for two directions, so the index with a higher probability needs to be selected here. The first return result of the torch.max function is the higher value, and the second return result is the index of the higher value . Therefore, here the predicted feature map is converted to the predicted result of 01 according to the probability.

if dir_cls_preds is not None:
    dir_offset = self.model_cfg.DIR_OFFSET      # 0.78539
    dir_limit_offset = self.model_cfg.DIR_LIMIT_OFFSET  # 0
    dir_cls_preds = dir_cls_preds.view(batch_size, num_anchors, -1) if not isinstance(dir_cls_preds, list) \
        else torch.cat(dir_cls_preds, dim=1).view(batch_size, num_anchors, -1)  # (16, 321408, 2)
    # 确定正向还是反向
    dir_labels = torch.max(dir_cls_preds, dim=-1)[1]     # (16, 321408)

Finally, limit the angle to 0-π to construct an accurate gt yaw angle. Finally, the real predicted box information and label information are returned. The feature dimensions are: (16, 321408, 7) and (16, 321408, 3)

period = (2 * np.pi / self.model_cfg.NUM_DIR_BINS)  # pi
dir_rot = common_utils.limit_period(    # 限制在0到pi之间
    batch_box_preds[..., 6] - dir_offset, dir_limit_offset, period
)
# period * dir_labels.to(batch_box_preds.dtype) 如果label为1,则为π;否则仍然保存0;
batch_box_preds[..., 6] = dir_rot + dir_offset + period * dir_labels.to(batch_box_preds.dtype)

return batch_cls_preds, batch_box_preds

Finally store the features in a dictionary:

insert image description here


Guess you like

Origin blog.csdn.net/weixin_44751294/article/details/130597828