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
|
- 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- 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,intrinsicsandextrinsicsare accepted but unused; seeforward().
- 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),Truefor a real camera andFalsefor a padded slot.Nonetreats every camera as real.imu2img –
(B, N, 4, 4), which is what the 3D position embedding is built from.
depth,ray,intrinsics,extrinsicsandcoverage_maskbelong 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.