py123d_detection.torch.data.rigs

Which cameras a dataset has, and which part of each image is worth keeping.

Rigs differ in ways a detector cannot absorb on its own. Waymo’s cameras are portrait and point forward; Argoverse 2’s front camera is 2048 px tall with most of the sky in it; nuScenes’ six cameras already ring the vehicle. Cutting the unusable rows away and bringing every camera to a common shape is what makes one model trainable on several of them at once.

The legacy code had one module per dataset for this, five of which were the same forty lines with a different table of row ranges and a different output size. Here there is one class and a table per dataset, so adding a dataset is one entry rather than one file.

A CameraPreprocessing does not touch pixels. It is the first factor of the affine map from sensor pixels to network input (see images), so the crop, the resize to the rig’s shape and the augmentation are resampled in one pass, and the intrinsics are left-multiplied by the same matrix rather than re-derived.

Module Attributes

PREPROCESSING

Cropping presets, keyed the way the 123D splits are named.

RIGS

Ready-made rigs, one per dataset the thesis trained on.

Functions

get_rig(name)

Classes

CameraPreprocessing(row_ranges, target_size)

Cut fixed rows out of each camera, then scale every camera to one shape.

CameraRig(cameras[, preprocessing])

The cameras to read, in the order the model expects them.

class py123d_detection.torch.data.rigs.CameraPreprocessing(row_ranges, target_size)[source]

Bases: object

Cut fixed rows out of each camera, then scale every camera to one shape.

Parameters:
  • row_ranges (Mapping[str, Tuple[int, int]]) – {camera: (first_row, last_row)} in original pixels. A camera with no entry is only scaled. Ranges are clamped to the image, so a dataset whose resolution changed does not crash, it just crops less.

  • target_size (Tuple[int, int]) – (width, height) every camera is brought to. The augmentation’s zoom is relative to the covering scale of this shape, so it also sets each dataset’s pixel scale.

row_ranges: Mapping[str, Tuple[int, int]]
target_size: Tuple[int, int]
matrix(camera, height, width)[source]

The 3x3 map from a height by width image’s pixels to the rig’s shape.

Return type:

ndarray

class py123d_detection.torch.data.rigs.CameraRig(cameras, preprocessing=None)[source]

Bases: object

The cameras to read, in the order the model expects them.

Order matters and is not alphabetical: a model with per-camera parameters learns position by index, so the same dataset has to present its cameras the same way every time.

Parameters:

preprocessing (Optional[CameraPreprocessing]) – The fixed crop and shape in front of the per-sample transform. None leaves each camera at its own size, which is right when the rig needs no cropping; cameras of different sizes are then each transformed against their own.

cameras: Tuple[str, ...]
preprocessing: CameraPreprocessing | None = None
camera_matrix(camera, height, width)[source]

The rig’s part of the affine map for one camera, and the (height, width) it yields.

Return type:

Tuple[ndarray, Tuple[int, int]]

py123d_detection.torch.data.rigs.PREPROCESSING: Dict[str, CameraPreprocessing] = {'av2': CameraPreprocessing(row_ranges={'PCAM_F0': (750, 1750), 'PCAM_L0': (250, 1500), 'PCAM_R0': (250, 1500), 'PCAM_L1': (250, 1500), 'PCAM_R1': (250, 1500), 'PCAM_L2': (60, 1310), 'PCAM_R2': (60, 1310)}, target_size=(1600, 960)), 'carla': CameraPreprocessing(row_ranges={'PCAM_F0': (0, 450), 'PCAM_L0': (0, 450), 'PCAM_R0': (0, 450), 'PCAM_L1': (0, 450), 'PCAM_R1': (0, 450), 'PCAM_B0': (0, 420)}, target_size=(1640, 920)), 'nuplan': CameraPreprocessing(row_ranges={'PCAM_F0': (0, 1015), 'PCAM_R0': (0, 983), 'PCAM_R1': (0, 1080), 'PCAM_R2': (0, 1010), 'PCAM_L0': (0, 1010), 'PCAM_L1': (0, 1080), 'PCAM_L2': (0, 1025), 'PCAM_B0': (0, 1080)}, target_size=(1600, 900)), 'nuscenes': CameraPreprocessing(row_ranges={}, target_size=(1640, 920)), 'pandaset': CameraPreprocessing(row_ranges={'PCAM_F0': (0, 1080), 'PCAM_B0': (0, 825), 'PCAM_L0': (0, 1080), 'PCAM_R0': (0, 1080), 'PCAM_L1': (0, 1080), 'PCAM_R1': (0, 1080)}, target_size=(1800, 880)), 'wod': CameraPreprocessing(row_ranges={'PCAM_F0': (0, 1100), 'PCAM_L0': (0, 1100), 'PCAM_R0': (0, 1100), 'PCAM_L1': (0, 886), 'PCAM_R1': (0, 886)}, target_size=(1720, 880))}

Cropping presets, keyed the way the 123D splits are named.

The row ranges come from the master thesis, where they were tuned per dataset by looking at what the cameras actually see: sky and bonnet on Argoverse, the bottom band of the Waymo portrait frames, a different dead strip per nuPlan camera.

py123d_detection.torch.data.rigs.RIGS: Dict[str, CameraRig] = {'av2': CameraRig(cameras=('PCAM_F0', 'PCAM_L0', 'PCAM_R0', 'PCAM_L1', 'PCAM_R1', 'PCAM_L2', 'PCAM_R2'), preprocessing=CameraPreprocessing(row_ranges={'PCAM_F0': (750, 1750), 'PCAM_L0': (250, 1500), 'PCAM_R0': (250, 1500), 'PCAM_L1': (250, 1500), 'PCAM_R1': (250, 1500), 'PCAM_L2': (60, 1310), 'PCAM_R2': (60, 1310)}, target_size=(1600, 960))), 'carla': CameraRig(cameras=('PCAM_F0', 'PCAM_L0', 'PCAM_R0', 'PCAM_L1', 'PCAM_R1', 'PCAM_B0'), preprocessing=CameraPreprocessing(row_ranges={'PCAM_F0': (0, 450), 'PCAM_L0': (0, 450), 'PCAM_R0': (0, 450), 'PCAM_L1': (0, 450), 'PCAM_R1': (0, 450), 'PCAM_B0': (0, 420)}, target_size=(1640, 920))), 'nuplan': CameraRig(cameras=('PCAM_F0', 'PCAM_L0', 'PCAM_R0', 'PCAM_L1', 'PCAM_R1', 'PCAM_L2', 'PCAM_R2', 'PCAM_B0'), preprocessing=CameraPreprocessing(row_ranges={'PCAM_F0': (0, 1015), 'PCAM_R0': (0, 983), 'PCAM_R1': (0, 1080), 'PCAM_R2': (0, 1010), 'PCAM_L0': (0, 1010), 'PCAM_L1': (0, 1080), 'PCAM_L2': (0, 1025), 'PCAM_B0': (0, 1080)}, target_size=(1600, 900))), 'nuscenes': CameraRig(cameras=('PCAM_F0', 'PCAM_L0', 'PCAM_R0', 'PCAM_L1', 'PCAM_R1', 'PCAM_B0'), preprocessing=CameraPreprocessing(row_ranges={}, target_size=(1640, 920))), 'pandaset': CameraRig(cameras=('PCAM_F0', 'PCAM_L0', 'PCAM_R0', 'PCAM_L1', 'PCAM_R1', 'PCAM_B0'), preprocessing=CameraPreprocessing(row_ranges={'PCAM_F0': (0, 1080), 'PCAM_B0': (0, 825), 'PCAM_L0': (0, 1080), 'PCAM_R0': (0, 1080), 'PCAM_L1': (0, 1080), 'PCAM_R1': (0, 1080)}, target_size=(1800, 880))), 'wod': CameraRig(cameras=('PCAM_F0', 'PCAM_L0', 'PCAM_R0', 'PCAM_L1', 'PCAM_R1'), preprocessing=CameraPreprocessing(row_ranges={'PCAM_F0': (0, 1100), 'PCAM_L0': (0, 1100), 'PCAM_R0': (0, 1100), 'PCAM_L1': (0, 886), 'PCAM_R1': (0, 886)}, target_size=(1720, 880)))}

Ready-made rigs, one per dataset the thesis trained on.

py123d_detection.torch.data.rigs.get_rig(name)[source]
Return type:

CameraRig