vision3d.transforms#
3D data augmentation transforms.
Classes
|
Batch-level 3D copy-paste data augmentation. |
|
Add Gaussian noise to point xyz coordinates with probability |
|
Subsample (or oversample with replacement) to exactly |
|
Randomly permute point order with probability |
|
Flip inputs along a 3D axis with probability |
|
Rotate inputs around an axis by a random angle with probability |
|
Scale inputs by a random uniform factor with probability |
|
Translate inputs by a random 3D offset with probability |
|
Drop points and boxes outside an axis-aligned 3D region. |
Base class for vision3d transforms. |
- class vision3d.transforms.CopyPaste3D(target_counts, min_points=5, max_database_size=None, offset_range=(0.0, 0.0), offset_std=None, max_jitter_attempts=5, p=1.0)[source]#
Bases:
TransformBatch-level 3D copy-paste data augmentation.
Maintains a lazy object database that grows as batches pass through. For each sample, pastes additional objects from the database to reach a target count per class. Objects are pasted at their original scene position from the source frame.
Operates on collated batches
(tuple_of_inputs, tuple_of_targets), not individual samples. Each instance should be used with only one dataset to avoid cross-contamination.CopyPaste3Dmust be the first transform in any pipeline, before any 3D spatial transform (RandomFlip3D,RandomRotate3D,RandomScale3D,RandomTranslate3D). Pasted objects are extracted and re-inserted in the source-frame geometry of the scene they came from. If a scene transform has already mutated the frame, the pasted objects will disagree with the rest of the scene and the resulting boxes/points will be inconsistent.- Parameters:
target_counts (dict[int, int]) – Dict mapping integer class label to desired object count per sample. E.g.
{0: 15, 1: 10}.min_points (int) – Minimum number of points an extracted object must have to be stored in the database. Default:
5.max_database_size (int | None) – Maximum entries per class. None means unlimited. Default:
None.offset_range (tuple[float, float] | Sequence[tuple[float, float]]) – Random position offset applied per pasted object (to its box and points) before the overlap check, so placements stay collision-free at the jittered pose. Either a single
(min, max)interval, in scene units, applied independently to the x, y, and z axes, or a 3-tuple of per-axis intervals((x_min, x_max), (y_min, y_max), (z_min, z_max)).(0.0, 0.0)disables jittering. For each object up tomax_jitter_attemptsoffsets are drawn and the first collision-free one is used; if none is collision-free the object falls back to its original (un-jittered) pose. Default:(0.0, 0.0).offset_std (float | Sequence[float | None] | None) – Standard deviation, in scene units, of the offset distribution.
None(the default) draws offsets uniformly acrossoffset_range; a positive value draws from a normal distribution centred on each range’s midpoint and truncated to it. May be a single value shared across axes or a 3-tuple of per-axis values (each a float, orNoneto keep that axis uniform). Default:None.max_jitter_attempts (int) – Number of jittered positions to try per object before falling back to its original (un-jittered) pose. Larger values raise the chance of placing a genuinely jittered object in a crowded scene. Ignored when jittering is disabled. Default:
5.p (float) – Probability of applying the augmentation. Default:
1.0.
- forward(*inputs)[source]#
Apply copy-paste augmentation to a collated batch.
Accepts any pytree structure containing
PointCloud3D,BoundingBoxes3D, and optionally camera tensors and plain-tensor labels.
- class vision3d.transforms.PointJitter(sigma=0.01, p=0.5)[source]#
Bases:
_RandomApplyTransformAdd Gaussian noise to point xyz coordinates with probability
p.- Parameters:
- class vision3d.transforms.PointSample(n)[source]#
Bases:
TransformSubsample (or oversample with replacement) to exactly
npoints.If the point cloud has more than
npoints, a random subset is selected. If fewer, points are sampled with replacement to reachn.- Parameters:
n (int) – Target number of points.
- class vision3d.transforms.PointShuffle(p=0.5)[source]#
Bases:
_RandomApplyTransformRandomly permute point order with probability
p.- Parameters:
p (float) – Probability of applying. Default:
0.5.
- class vision3d.transforms.RandomFlip3D(axis='x', p=0.5)[source]#
Bases:
_RandomApplyTransformFlip inputs along a 3D axis with probability
p.Operates on
PointCloud3DandBoundingBoxes3D. Camera inputs (images, extrinsics, intrinsics) are rejected, since this transform flips only the 3D geometry and leaves the camera side untouched. To flip a scene that contains cameras, usetorchvision.transforms.v2.RandomHorizontalFlip(world Y) ortorchvision.transforms.v2.RandomVerticalFlip(world Z), which apply the matching image-space flip and update the camera tensors so projection stays consistent.The world X-axis flip has no image-space equivalent, so
RandomFlip3Dremains the way to apply it (on camera-free samples).- Parameters:
- class vision3d.transforms.RandomRotate3D(angle_range=math.pi / 4, axis=(0.0, 0.0, 1.0), p=0.5)[source]#
Bases:
_RandomApplyTransformRotate inputs around an axis by a random angle with probability
p.Operates on
PointCloud3D,BoundingBoxes3D, andCameraExtrinsics.- Parameters:
- class vision3d.transforms.RandomScale3D(scale_range=(0.95, 1.05), p=0.5)[source]#
Bases:
_RandomApplyTransformScale inputs by a random uniform factor with probability
p.Operates on
PointCloud3D,BoundingBoxes3D, andCameraExtrinsics.- Parameters:
- class vision3d.transforms.RandomTranslate3D(translation_range=0.5, p=0.5)[source]#
Bases:
_RandomApplyTransformTranslate inputs by a random 3D offset with probability
p.Operates on
PointCloud3D,BoundingBoxes3D, andCameraExtrinsics.- Parameters:
- class vision3d.transforms.RangeFilter3D(point_cloud_range, labels_getter='default')[source]#
Bases:
TransformDrop points and boxes outside an axis-aligned 3D region.
Points are filtered by their xyz coordinates; boxes are filtered by their center (format-agnostic), and any per-box
labelsare filtered in sync. The sample must hold at most oneBoundingBoxes3Dset (a single keep-mask cannot span box sets of differing length).Must be applied after spatial augmentations (rotate / scale / translate can push data out of the sensor range) and before the model sees the data.
- Parameters:
point_cloud_range (tuple[float, ...]) – Axis-aligned bounds
(x_min, y_min, z_min, x_max, y_max, z_max).labels_getter (str | Callable[[Any], Any] | None) – How to locate the per-box label tensor(s) that are filtered in sync with the boxes. Pass a callable that takes the sample and returns the label tensor stored in it, a tuple or list of such tensors (when several label tensors track the same boxes), or
None. The returned tensors must be the exact objects stored in the sample, not copies or views, since labels are matched to their leaf by identity. Alternatively, pass the string"default"(the default) to use the built-in heuristic, which finds the labels under a case-insensitive"labels"key and raises if the sample has boxes but no such tensor, or passNoneto filter the boxes without touching any labels.
- forward(*inputs)[source]#
Filter points and boxes outside the configured range.
Accepts both a single sample dict and an
(inputs, targets)pair.- Returns:
Filtered sample in the same structure as the input.
- Raises:
ValueError – If called with no inputs. If the sample holds more than one box set. If the sample has boxes but the default
labels_gettercannot find a labels tensor. Iflabels_getterreturns a tensor that is not a leaf of the sample (e.g. a copy, view, or nested tensor). If a returned label tensor’s length does not match the number of boxes.- Parameters:
inputs (Any)
- Return type:
- class vision3d.transforms.Transform[source]#
Bases:
ModuleBase class for vision3d transforms.
Mirrors
torchvision.transforms.v2.Transform. Subclasses overridetransform()and use_call_kernelto dispatch to the correct kernel for each input type.The class-level
_transformed_typestuple lists the input types the transform operates on; inputs whose type is not listed flow through unchanged. Subclasses can additionally overridecheck_inputs()to reject unsupported input combinations with aTypeError.- check_inputs(flat_inputs)[source]#
Validate inputs before transforming. Override to reject inputs.
The base implementation is a no-op. Subclasses raise
TypeErrorfor input combinations the transform cannot handle (e.g. a 3D-only transform that has no matching update for camera tensors).
- forward(*inputs)[source]#
Apply the transform to one or more inputs (dicts, tuples, etc.).
Do not override this; override
transform()instead.