OpenPCDet シリーズ | 7.1 KITTI データセット テスト プロセス予測ボックス予測

AnchorHeadTemplate.generate_predicted_boxes 部分

テストプロセスの構造図は次のとおりです。
ここに画像の説明を挿入

generate_predicted_boxes 関数の初期データ入力は次のとおりです。
ここに画像の説明を挿入

まず、さまざまなタイプの予測の特徴マップを再形成し、アンカー ディメンションをステッチします (例: (16, 248, 216, 42) -> (16, 321408, 7))。ただし、ここで注意点があります。特徴予測のボックス情報はアンカーのオフセット、つまり符号化されたオフセット係数に基づいているため、実際のボックス情報を取得するには独自の方法で復号化する必要があります。

# 各种维度的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)

方向予測機能がある場合は、それも再形成されます。ここでの予測特徴量 (16, 321408, 2) は、各アンカーの 2 方向の予測確率を表すため、ここでは確率の高いインデックスを選択する必要があります。torch.max 関数の最初の戻り結果はより高い値であり、2 番目の戻り結果はより高い値のインデックスですしたがって、ここでは予測特徴マップを確率に従って01の予測結果に変換する。

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)

最後に、角度を 0 ~ π に制限して、正確な GT ヨー角を構築します。最後に、実際の予測ボックス情報とラベル情報が返されます。フィーチャーの寸法は (16, 321408, 7) および (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

最後に特徴を辞書に保存します。

ここに画像の説明を挿入


おすすめ

転載: blog.csdn.net/weixin_44751294/article/details/130597828