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
|
The distribution a training sample's |
|
The rotation and scale chosen for one sample. |
|
Everything random about one sample. |
- class py123d_detection.torch.data.augment.BevTransform(angle=0.0, scale=1.0)[source]¶
Bases:
objectThe rotation and scale chosen for one sample. The identity when not augmenting.
- 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:
- forward_matrix()[source]¶
Original ego frame to the augmented one, for matrices that map into it.
- Return type:
- 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
+angleand 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:
- class py123d_detection.torch.data.augment.Draw(image=<factory>, bev=<factory>)[source]¶
Bases:
objectEverything random about one sample. The default is the unaugmented, validation sample.
- bev: BevTransform¶
- 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:
objectThe distribution a training sample’s
Drawcomes 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
stretchmode.
- rotation_range: Tuple[float, float] = (-0.3925, 0.3925)¶
Bird’s-eye yaw in radians, about +/- 22.5 degrees by default.