package documentation

Augmentation engines and custom transforms for LDF samples.

This package provides the augmentation interface used by LuxonisLoader. The default implementation is AlbumentationsEngine, which adapts LDF labels to Albumentations targets before transformation and converts them back after transformation.

Augmentation configuration is a list of records. Each record contains a name identifying an Albumentations transform or a transform registered in TRANSFORMATIONS, optional params, optional use_for_resizing, and optional stage filtering through apply_on_stages. When apply_on_stages is omitted, the transform applies to "train".

[
    {"name": "HorizontalFlip", "params": {"p": 0.5}},
    {
        "name": "Mosaic4",
        "params": {"height": 640, "width": 640, "p": 1.0},
    },
]

The engine groups transforms by behavior rather than preserving the exact input order:

  1. Batch transforms, such as MixUp and Mosaic4.
  2. Spatial transforms, such as Albumentations dual transforms.
  3. Custom basic transforms.
  4. Pixel-only transforms.

Resize handling is part of the engine. A transform marked with use_for_resizing is used as the resize stage; otherwise the engine falls back to a regular resize or LetterboxResize, depending on the loader's aspect-ratio setting. If the selected resize transform has probability p < 1, it stays in the resize stage and the remaining probability mass is filled by the default resize in an always-on OneOf. The resize stage is applied before pixel-only transforms when downscaling saves work, and after pixel-only transforms when upscaling or preserving size.

Standard Albumentations flip transforms such as HorizontalFlip, VerticalFlip, and Transpose flip keypoint coordinates but do not swap semantic left/right keypoint labels. For symmetric keypoint structures, use the Luxonis custom transforms HorizontalSymmetricKeypointsFlip, VerticalSymmetricKeypointsFlip, and TransposeSymmetricKeypoints.

Batch transforms multiply the number of source samples required by the loader. For example, a pipeline that contains MixUp and Mosaic4 requires 8 = 2β‹…4 samples for each augmented output.

Custom augmentation engines can be added by subclassing AugmentationEngine. Subclasses are automatically registered in AUGMENTATION_ENGINES.

Custom Transforms

Custom transforms follow Albumentations conventions. Subclass an appropriate base class such as DualTransform or ImageOnlyTransform, implement the target methods needed by your labels, register the class in luxonis_ml.data.augmentations.custom.TRANSFORMATIONS, and reference the class name in loader configuration.

from albumentations import DualTransform
from luxonis_ml.data.augmentations.custom import TRANSFORMATIONS

class CustomTransform(DualTransform):
    def apply(self, image, **kwargs):
        return image

    def apply_to_mask(self, mask, **kwargs):
        return mask

    def apply_to_bboxes(self, bboxes, **kwargs):
        return bboxes

    def apply_to_keypoints(self, keypoints, **kwargs):
        return keypoints

TRANSFORMATIONS.register(module=CustomTransform)

augmentation_config = [
    {"name": "CustomTransform", "params": {"p": 1.0}},
]

Engine Interface

A custom engine should subclass AugmentationEngine and implement:

  • __init__ to consume output size, class count, configuration, aspect-ratio behavior, pipeline stage, and target metadata;
  • apply to transform a batch of images and labels and return the transformed values;
  • batch_size to tell LuxonisLoader how many source samples are needed per augmented output.
Module albumentations_engine No module docstring; 0/2 type alias, 1/1 class documented
Module base_engine Undocumented
Module batch_compose Undocumented
Module batch_transform Undocumented
Package custom Built-in custom Albumentations transforms.
Module utils Utilities for adapting LDF annotations to Albumentations.

From __init__.py:

Class AlbumentationsEngine Augmentation engine backed by Albumentations.
Class AugmentationEngine No class docstring; 1/1 property, 2/2 methods documented
Class BatchCompose Compose batch-aware Albumentations transforms.
Class BatchTransform Base class for transforms that combine multiple samples.
Constant AUGMENTATION_ENGINES Registry for augmentation engines.
AUGMENTATION_ENGINES: Registry[type[AugmentationEngine]] = ΒΆ

Registry for augmentation engines.

Value
Registry(name='augmentation_engines')