py123d_detection.torch.models.bevformer.encoder

Stacks encoder layers that apply: 1. Deformable self-attention among BEV queries 2. Spatial cross-attention from BEV queries to multi-view image features 3. Feed-forward network

Classes

BEVFormerEncoder([num_layers, embed_dims, ...])

A stack of BEVFormerEncoderLayer.

BEVFormerEncoderLayer([embed_dims, ...])

One layer of the BEV encoder.

class py123d_detection.torch.models.bevformer.encoder.BEVFormerEncoderLayer(embed_dims=256, num_heads=8, feedforward_channels=512, dropout=0.1, num_points_self=4, num_points_cross=8, num_heights=4, with_cp=True)[source]

Bases: Module

One layer of the BEV encoder.

Pre-norm, three blocks, each with a residual: deformable self-attention over the BEV grid, so a cell can read its neighbours; spatial cross-attention into the camera features, so it can read the images; then a feed-forward network.

Parameters:
  • embed_dims (int) – Feature dimension.

  • num_heads (int) – Attention heads.

  • feedforward_channels (int) – Hidden width of the feed-forward network.

  • dropout (float) – Dropout rate.

  • num_points_self (int) – Sampling points for the self-attention.

  • num_points_cross (int) – Sampling points for the cross-attention.

  • num_heights (int) – Pillar height count, which has to match the num_Z_anchors dimension of the 3D reference points.

  • with_cp (bool) – Gradient-checkpoint the layer.

forward(*args, **kwargs)[source]

Forward with optional gradient checkpointing.

Return type:

Tensor

class py123d_detection.torch.models.bevformer.encoder.BEVFormerEncoder(num_layers=3, embed_dims=256, num_heads=8, feedforward_channels=512, dropout=0.1, num_points_self=4, num_points_cross=8, num_heights=4, with_cp=True)[source]

Bases: Module

A stack of BEVFormerEncoderLayer.

Parameters:
  • num_layers (int) – How many layers; 3 is BEVFormer-S.

  • embed_dims (int) – Feature dimension.

  • num_heads (int) – Attention heads.

  • feedforward_channels (int) – Hidden width of each layer’s feed-forward network.

  • dropout (float) – Dropout rate.

  • num_points_self (int) – Sampling points for the self-attention.

  • num_points_cross (int) – Sampling points for the cross-attention.

  • num_heights (int) – Pillar height count for the spatial cross-attention.

  • with_cp (bool) – Gradient-checkpoint each layer.

forward(bev_queries, bev_pos, image_features, reference_points_3d, bev_ref_2d, spatial_shapes_bev, level_start_index_bev, imu2img, cam_mask, pad_h, pad_w)[source]

Run BEV queries through all encoder layers.

Return type:

Tensor

Returns:

bev_queries: (B, Q_bev, C) final BEV features.