py123d_detection.torch.models.petr.head

PETR’s detection head: position-aware queries over multi-view image features.

The head does three things. It turns each feature-map pixel into a 3D ray of points through that camera’s own projection, with compute_frustum_coords3d(), then embeds those coordinates and adds them to the features, so a pixel carries where in space it could be looking. It then lets learned queries, themselves embedded from 3D reference points, attend across every camera at once with ordinary attention. Finally it reads class scores and box residuals off each decoder layer.

There is no view transformation, no depth prediction and no bird’s-eye grid. That is the whole point of the paper, and it is why a new camera rig needs nothing from this file.

eps is fixed at 1e-5 throughout. The frustum coordinates are cast back to float32 before inverse_sigmoid, which is what the official implementation does with out_fp32=True, because at fp16 an eps of 1e-5 is lost in the rounding.

Classes

PETRHead(num_classes, in_channels[, ...])

class py123d_detection.torch.models.petr.head.PETRHead(num_classes, in_channels, num_query=900, num_decoder_layers=6, pc_range=None, code_weights=[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.2, 0.2], position_range=[-61.2, -61.2, -10.0, 61.2, 61.2, 10.0], with_cp=True, mask_strict=True, debug_nan_checks=False, patches_x=None, patches_y=None, image_width=None, image_height=None, **kwargs)[source]

Bases: Module

init_weights()[source]
reset_classification_head(num_classes)[source]

Reinitialize class-dependent modules for a new class taxonomy.

position_embeding(img_feats, img_metas, masks=None, imu2img=None, depth=None, ray=None, intrinsics=None, extrinsics=None)[source]

PETR’s 3D positional encoding.

Every pixel is lifted to a column of points at increasing depth, transformed into the ego frame, and the column embedded. That is what gives a 2D feature a 3D position without any depth prediction.

depth, ray, intrinsics and extrinsics are accepted but unused; see forward().

forward(x, img_metas, cam_mask=None, imu2img=None, extrinsics=None, intrinsics=None, depth=None, ray=None, coverage_mask=None)[source]
Parameters:
  • x – FPN features; only the first level is used, (B, N, C, H, W).

  • img_metas – One metadata dict per sample.

  • cam_mask – (B, N), True for a real camera and False for a padded slot. None treats every camera as real.

  • imu2img – (B, N, 4, 4), which is what the 3D position embedding is built from.

depth, ray, intrinsics, extrinsics and coverage_mask belong to variants of the head that were not ported (a predicted-depth lift, PRoPE attention, a cylindrical canvas). They are still in the signature so that a checkpoint or a caller from the thesis loads, but the frustum path ignores them.

loss(gt_bboxes_list, gt_labels_list, preds_dicts, sync=True, num_boxes_synced=None)[source]
get_bboxes(preds_dicts, img_metas=None, rescale=False)[source]

Convert predictions to bboxes in world coordinates.