py123d_detection.torch.models.bevformer.spatial_cross_attention

Core “backward projection” mechanism: BEV queries reach into multi-view image features by projecting 3D pillar reference points to each camera view and applying deformable attention at the projected locations.

Classes

SpatialCrossAttention([embed_dims, ...])

How a BEV cell reads from the cameras that can see it.

class py123d_detection.torch.models.bevformer.spatial_cross_attention.SpatialCrossAttention(embed_dims=256, num_heads=8, num_points=8, num_heights=4, dropout=0.1)[source]

Bases: Module

How a BEV cell reads from the cameras that can see it.

Each query’s pillar of 3D points is projected into every camera. A query takes part in a camera’s attention only where at least one of its points lands in that camera’s image, so a cell behind the vehicle does not attend to the front camera’s pixels at all. All cameras go into one deformable attention call, the per-camera results are scattered back onto the grid, and each query is divided by the number of cameras it was seen by, so a cell in an overlap is not weighted higher than one seen once.

Parameters:
  • embed_dims (int) – Feature dimension.

  • num_heads (int) – Attention heads.

  • num_points (int) – Deformable sampling points per head.

  • num_heights (int) – Height samples per pillar, the num_Z_anchors of the attention below.

  • dropout (float) – Dropout rate.

forward(bev_queries, image_features, reference_points_3d, imu2img, cam_mask, pad_h, pad_w)[source]
Parameters:
  • bev_queries (Tensor) – (B, Q, C), with the positional encoding already added.

  • image_features (Tensor) – (B, N, C, H, W).

  • reference_points_3d (Tensor) – (Q, num_heights, 3) in world coordinates, shared across the batch.

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

  • cam_mask (Tensor) – (B, N), True for a real camera and False for a padded slot.

  • pad_h (int) – Padded image height.

  • pad_w (int) – Padded image width.

Return type:

Tensor

Returns:

(B, Q, C).