py123d_detection.torch.models.multiview¶
What every camera-based detector in this package does before its head.
Flatten the rig’s images into a batch, run one shared backbone over them, fold them back into per-camera features, and make sure the projection matrices are there. What happens next is where PETR and BEVFormer part company, queries attending to image features against an explicit bird’s-eye grid, so that is the only thing a subclass supplies.
Keeping this separate from Detector3D keeps the
Lightning loop free of anything camera-specific, and keeps the two detectors siblings. In the
thesis BEVFormer subclassed PETR, so every change to PETR’s forward was a silent change
to BEVFormer’s.
Module Attributes
Stride of the shared ResNet backbone: an image becomes a grid this many pixels per cell. |
|
Detection range in the ego (IMU) frame. |
|
ImageNet statistics in RGB order, which the pretrained backbones expect. |
Classes
|
A shared backbone over a rig of cameras, plus a head a subclass chooses. |
- py123d_detection.torch.models.multiview.BACKBONE_STRIDE = 16¶
Stride of the shared ResNet backbone: an image becomes a grid this many pixels per cell.
- py123d_detection.torch.models.multiview.DEFAULT_PC_RANGE = (-51.2, -51.2, -3.0, 51.2, 51.2, 5.0)¶
Detection range in the ego (IMU) frame. The z bounds are mmdet3d’s lidar-frame
[-5, 3]shifted up by two metres, because the IMU sits over the rear axle, well below a roof lidar.
- py123d_detection.torch.models.multiview.IMAGENET_MEAN = (123.675, 116.28, 103.53)¶
ImageNet statistics in RGB order, which the pretrained backbones expect.
- class py123d_detection.torch.models.multiview.MultiViewDetector(num_classes=10, num_query=900, num_decoder_layers=6, hidden_dim=256, backbone_name='resnet50', pc_range=None, image_size=(320, 800), use_grid_mask=True, grid_mask_ratio=0.5, grid_mask_prob=0.7, grid_mask_annealing=False, backbone_checkpointing=False, head_checkpointing=False, pretrained_weights=None, pixel_mean=(123.675, 116.28, 103.53), pixel_std=(58.395, 57.12, 57.375), **trainer_kwargs)[source]¶
Bases:
Detector3DA shared backbone over a rig of cameras, plus a head a subclass chooses.
- Parameters:
num_classes (
int) – Size of the classification head; must match the taxonomy’s class count.num_query (
int) – Object queries. Each may become one detection, so this caps how many objects a frame can hold.pc_range (
Optional[List[float]]) –(x_min, y_min, z_min, x_max, y_max, z_max)the box regression is normalised against. A prediction outside it cannot be expressed.image_size (
tuple) –(height, width)of the padded network input.use_grid_mask (
bool) – Blank a random grid of squares in each image during training. Cheap and effective here, where a model otherwise learns to lean on whichever view is easiest.grid_mask_annealing (
bool) – Ramp the masking probability from nothing at the first epoch togrid_mask_probat the last, which is what official PETR does. Off by default, as it was in the thesis, so every number this branch has published stays reproducible.pixel_mean (
Sequence[float]) – Per-channel RGB mean subtracted fromuint8input, on the device. The statistics belong to the backbone’s pretraining, so they live here and not in the dataset.pixel_std (
Sequence[float]) – Per-channel RGB standard deviation, seepixel_mean.
- on_train_epoch_start()[source]¶
Move the grid mask along its ramp, when one was asked for.
Official PETR raises the masking probability linearly from 0 at the first epoch to the configured value at the last, so a model learns on whole images before it has to cope with holes in them.
max_epochsis the figure the schedule is drawn against, the same one the cosine learning rate uses, rather than Lightning’s trainer, so a run that stops early sees the schedule it was configured with.- Return type:
- extract_features(images)[source]¶
Backbone features per camera, as
(B, N, C, H, W)per level.Features come back in fp32 even under mixed precision: the heads run attention over them and a trained backbone’s magnitudes overflow fp16 there.
- Return type:
List[Tensor]
- normalize_images(batch)[source]¶
batch["img"]as the backbone’s input.The dataset delivers raw
uint8pixels, a quarter of the bytes of normalised floats through the worker queues and the host-to-device copy, and cheaper to produce: on the CPU, normalising cost more than decoding the JPEG. Here it is one fused operation on the device.Everything that is not an image pixel is set to zero after normalisation, which is the mean colour, as the float pipeline always did. That covers the padding up to the stride divisor, a camera padded in to match a wider rig, and a camera with no image this frame.
A floating-point
imgis taken as already normalised and returned unchanged.- Return type:
Tensor