py123d_detection.torch.data.augment

The random part of a training sample, in one place.

A sample is augmented twice over, and both halves are drawn together, once per sample:

  • in the image: a zoom, a crop position and a horizontal flip (ImageDraw), shared by every camera of the frame and folded into each camera’s intrinsics;

  • in bird’s-eye view: a rotation and a scale of the world about the ego vehicle (BevTransform), applied to the boxes and folded, inverted, into every matrix that reads from the ego frame, so the images need no change.

Validation is the default Draw: no zoom, a centred crop, no flip, no rotation.

Randomness. A dataset draws from its own generator, which the data module reseeds in every worker from the worker’s seed and the trainer’s rank. So each epoch sees a fresh augmentation of every frame, the same run repeated gives the same augmentations, and two ranks never draw the same stream. (The first version seeded each sample from its index, which is reproducible but gave every frame the same augmentation in every epoch.) To reproduce one sample exactly, pass its Draw to the dataset.

Zoom is relative. PETR’s resize_lim is an absolute scale, meaningful only for one source resolution and one output size: (0.8, 1.0) suits 1600x900 images cropped to 704x1280 and is wrong by a factor of two at 320x800. Here the zoom multiplies the scale at which the image just covers the network input, so one range works for every rig and every size. (1.0, 1.25) is exactly what the thesis trained with on Argoverse 2 and Waymo (on nuScenes it was (1.025, 1.28)), and PETR’s own configs, rewritten this way, come to (0.94, 1.25) at both 320x800 and 640x1600.

Classes

Augmentation([zoom_range, flip, ...])

The distribution a training sample's Draw comes from.

BevTransform([angle, scale])

The rotation and scale chosen for one sample.

Draw([image, bev])

Everything random about one sample.

class py123d_detection.torch.data.augment.BevTransform(angle=0.0, scale=1.0)[source]

Bases: object

The rotation and scale chosen for one sample. The identity when not augmenting.

angle: float = 0.0
scale: float = 1.0
property is_identity: bool
rotation_matrix()[source]
Return type:

ndarray

inverse_matrix()[source]

Augmented ego frame back to the original one, i.e. R(-angle) / scale.

A matrix mapping from the ego frame (imu2img, imu2cam, imu2global) is right-multiplied by this, because its input now arrives already rotated and scaled.

Return type:

ndarray

forward_matrix()[source]

Original ego frame to the augmented one, for matrices that map into it.

Return type:

ndarray

apply_to_boxes(boxes)[source]

Rotate and scale [x, y, z, w, l, h, yaw, vx, vy] rows.

Centres, sizes, velocities and yaw all turn the same way. The legacy implementation turned the centres by +angle and the yaw by -angle, which left every augmented box facing the wrong way by twice the angle; a symmetric range hid it on average.

Return type:

ndarray

class py123d_detection.torch.data.augment.Draw(image=<factory>, bev=<factory>)[source]

Bases: object

Everything random about one sample. The default is the unaugmented, validation sample.

image: ImageDraw
bev: BevTransform
metadata()[source]

What was drawn, for img_metas.

Return type:

Dict[str, object]

class py123d_detection.torch.data.augment.Augmentation(zoom_range=(1.0, 1.25), flip=True, rotation_range=(-0.3925, 0.3925), scale_range=(0.95, 1.05))[source]

Bases: object

The distribution a training sample’s Draw comes from.

A dataset without one is not augmented, which is the whole difference between training and validation data.

zoom_range: Tuple[float, float] = (1.0, 1.25)

Image scale relative to the covering one; see the module notes. Ignored in stretch mode.

flip: bool = True

Mirror the images of half the samples.

rotation_range: Tuple[float, float] = (-0.3925, 0.3925)

Bird’s-eye yaw in radians, about +/- 22.5 degrees by default.

scale_range: Tuple[float, float] = (0.95, 1.05)

Bird’s-eye scale of the world about the ego vehicle.

draw(rng)[source]
Return type:

Draw