py123d_detection.torch.models.bevformer.head

Stage 1 (BEV Encoder): Builds a dense BEV feature map from multi-view images

via Spatial Cross-Attention

Stage 2 (Detection Decoder): Object queries cross-attend to the BEV feature

map using deformable attention to produce 3D detection predictions

Classes

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

BEVFormer's head: build a bird's-eye feature map, then detect in it.

DeformableDETRDecoder([num_layers, ...])

Deformable DETR decoder that cross-attends to BEV features.

DeformableDETRDecoderLayer([embed_dims, ...])

Single Deformable DETR decoder layer.

class py123d_detection.torch.models.bevformer.head.DeformableDETRDecoderLayer(embed_dims=256, num_heads=8, feedforward_channels=2048, dropout=0.1, num_points=4, with_cp=True)[source]

Bases: Module

Single Deformable DETR decoder layer.

Order: self-attn -> norm -> deformable cross-attn (on BEV) -> norm ->

FFN -> norm.

forward(*args, **kwargs)[source]
Return type:

Tensor

class py123d_detection.torch.models.bevformer.head.DeformableDETRDecoder(num_layers=6, embed_dims=256, num_heads=8, feedforward_channels=2048, dropout=0.1, num_points=4, with_cp=True)[source]

Bases: Module

Deformable DETR decoder that cross-attends to BEV features.

Returns intermediate outputs from each layer for auxiliary loss.

forward(query, query_pos, reference_points, bev_features, spatial_shapes, level_start_index)[source]
Return type:

Tensor

Returns:

intermediate: (num_layers, B, num_query, C) intermediate outputs.

class py123d_detection.torch.models.bevformer.head.BEVFormerHead(num_classes, in_channels=256, embed_dims=256, bev_h=50, bev_w=50, num_query=900, num_encoder_layers=3, num_decoder_layers=6, num_heads=8, num_heights=4, num_points=4, pc_range=None, code_weights=None, feedforward_channels_encoder=512, feedforward_channels_decoder=2048, dropout=0.1, with_box_refine=True, with_cp=True, debug_nan_checks=False, cam_embed_type='none', num_cameras=6, **kwargs)[source]

Bases: Module

BEVFormer’s head: build a bird’s-eye feature map, then detect in it.

The encoder turns multi-view image features into a dense BEV map. The decoder then works only in that map, so detection never touches a pixel again. The output is laid out exactly as PETRHead’s, which is what lets both detectors share one loss and one metric.

Parameters:
  • num_classes (int) – Object classes.

  • in_channels (int) – Channels arriving from the FPN.

  • embed_dims (int) – Internal feature dimension.

  • bev_h (int) – BEV grid height.

  • bev_w (int) – BEV grid width.

  • num_query (int) – Detection queries.

  • num_encoder_layers (int) – Layers in the BEV encoder.

  • num_decoder_layers (int) – Layers in the detection decoder.

  • num_heads (int) – Attention heads.

  • num_heights (int) – Height samples per pillar.

  • num_points (int) – Deformable sampling points.

  • pc_range (List[float]) – Detection range, [x_min, y_min, z_min, x_max, y_max, z_max].

  • code_weights (List[float]) – Per-column weights for the box regression loss.

  • feedforward_channels_encoder (int) – Hidden width of the encoder’s feed-forward networks.

  • feedforward_channels_decoder (int) – Hidden width of the decoder’s.

  • dropout (float) – Dropout rate.

  • with_box_refine (bool) – Refine the 2D BEV reference points between decoder layers and give each layer its own prediction branches, as Deformable DETR does.

  • with_cp (bool) – Gradient-checkpoint the encoder and decoder layers.

init_weights()[source]

Initialize weights following Deformable DETR conventions.

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

  • img_metas – One metadata dict per sample, carrying pad_shape.

  • cam_mask – (B, N), True for a real camera.

  • imu2img – (B, N, 4, 4).

Returns:

all_cls_scores (L, B, num_query, num_classes) and all_bbox_preds (L, B, num_query, 10), one entry per decoder layer.

loss(gt_bboxes_list, gt_labels_list, preds_dicts, sync=True, num_boxes_synced=None)[source]

Compute loss. Same interface as PETRHead.

get_bboxes(preds_dicts, img_metas=None, rescale=False)[source]

Convert predictions to bboxes in world coordinates. Same interface as PETRHead.

reset_classification_head(num_classes)[source]

Reinitialize classification head for a new class taxonomy.