py123d_detection.torch.models.bevformer.utils

Geometry for BEVFormer’s bird’s-eye grid.

Three pure functions: lay out the grid, lift each cell into a vertical pillar of 3D points, and project those points into every camera. No parameters, no modules, which is why they are tested directly and reused by the camera renderer rather than reimplemented there.

Functions

create_3d_reference_points(bev_grid, ...)

Lift each BEV cell into a vertical pillar of 3D points, for spatial cross-attention.

create_bev_grid(bev_h, bev_w)

Cell centres of the BEV grid, normalised to [0, 1].

project_3d_to_cameras(points_3d, imu2img, ...)

Project world-frame points into every camera.

py123d_detection.torch.models.bevformer.utils.create_bev_grid(bev_h, bev_w)[source]

Cell centres of the BEV grid, normalised to [0, 1].

Parameters:
  • bev_h (int) – Cells along y.

  • bev_w (int) – Cells along x.

Return type:

Tensor

Returns:

(bev_h * bev_w, 2) of (x, y), row-major in y.

py123d_detection.torch.models.bevformer.utils.create_3d_reference_points(bev_grid, num_heights, pc_range)[source]

Lift each BEV cell into a vertical pillar of 3D points, for spatial cross-attention.

A cell has no height, but the cameras that see it do. Sampling a few evenly spaced heights inside the detection range is how a cell finds the pixels that look at it.

Parameters:
  • bev_grid (Tensor) – (Q, 2), from create_bev_grid().

  • num_heights (int) – Points per pillar.

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

Return type:

Tensor

Returns:

(Q, num_heights, 3) in world coordinates.

py123d_detection.torch.models.bevformer.utils.project_3d_to_cameras(points_3d, imu2img, pad_h, pad_w)[source]

Project world-frame points into every camera.

The projections come from the dataset as imu2img, which is already intrinsics @ extrinsics, so nothing here has to know how a rig is calibrated.

Parameters:
  • points_3d (Tensor) – (B, Q, P, 3) in the world (IMU) frame; P is the pillar height count.

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

  • pad_h (int) – Padded image height, as img_metas['pad_shape'] reports it.

  • pad_w (int) – Padded image width.

Return type:

Tuple[Tensor, Tensor]

Returns:

(coords_2d, valid_mask). Coordinates are (B, N, Q, P, 2) normalised to [0, 1]; the mask is (B, N, Q, P) and True where the point is in front of the camera and inside the image.