py123d_detection.torch.data.collate

Batching samples whose rigs differ.

Mixing datasets means mixing camera counts: nuScenes has six, Argoverse seven, Waymo five. A batch pads every sample up to the largest and carries cam_mask so a model can ignore what was added. Ground truth stays a list, because the number of objects varies per frame and padding it would invent boxes.

Padded projection matrices are the identity, never zeros. A zero 4x4 is singular, and a model that inverts or chains it gets NaN out of a camera that does not exist.

Module Attributes

PER_SAMPLE_KEYS

Kept as lists: their length varies per sample, so stacking would need padding that means something.

PER_CAMERA_KEYS

Stacked along a camera dimension that is padded up to the batch's widest rig.

PER_CAMERA_METADATA

Entries of img_metas holding one value per camera, extended alongside the tensors.

Functions

collate_rigs(batch)

Collate samples from rigs of different sizes.

py123d_detection.torch.data.collate.PER_SAMPLE_KEYS = ('gt_bboxes_3d', 'gt_labels_3d', 'img_metas')

Kept as lists: their length varies per sample, so stacking would need padding that means something. A padded box is a false object.

py123d_detection.torch.data.collate.PER_CAMERA_KEYS = ('img', 'intrinsics', 'extrinsics', 'imu2img', 'cam_valid_mask')

Stacked along a camera dimension that is padded up to the batch’s widest rig.

py123d_detection.torch.data.collate.PER_CAMERA_METADATA = ('ori_shape', 'img_shape', 'pad_shape')

Entries of img_metas holding one value per camera, extended alongside the tensors.

py123d_detection.torch.data.collate.collate_rigs(batch)[source]

Collate samples from rigs of different sizes.

Adds two keys the samples do not have:

Return type:

Dict[str, Any]

cam_mask (B, N)

True where a camera is both present in that sample’s rig and had an image. This is the one a model should mask attention with.

num_cams (B,)

How many cameras each sample’s own rig has, before padding.