class AlbumentationsEngine(AugmentationEngine):
Constructor: AlbumentationsEngine(height, width, targets, n_classes, ...)
Augmentation engine backed by Albumentations.
Table of Contents
Configuration Format
The configuration contains a list of transformations,
each specified by its name and optional parameters as
described in the AlbumentationConfigItem schema.
The name must be either a valid name of an Albumentations
transformation, or a name of a custom transformation registered in the
TRANSFORMATIONS registry.
For example:
[
{
"name": "Affine",
"params": {
"rotate": 30,
"scale": 0.5,
"p": 0.3,
},
},
{
"name": "MixUp",
"params": {
"alpha": [0.3, 0.7],
"p": 0.5,
},
},
{
"name": "CustomResize",
"use_for_resizing": True,
},
]Transformation Order
The order of transformations provided in the configuration is not guaranteed to be preserved. The transformations are divided into the following groups and are applied in this order:
- Batch transformations: Subclasses of
BatchTransform.- Spatial transformations: Subclasses of A.DualTransform.
- Custom transformations: Subclasses of A.BasicTransform, but not subclasses of more specific base classes above.
- Pixel transformations: Subclasses of A.ImageOnlyTransform. These transformations act only on the image.
Supported Augmentations
Albumentations Augmentations
All augmentations provided by the Albumentations library are supported.
Batch Augmentations
Augmenting Unsupported Types
Albumentations does not natively support all label types supported by Luxonis Data Format. This section describes how unsupported types are handled.
Note that the following applies only to officially supported augmentations. Custom augmentations can be implemented to handle arbitrary types.
Classification
Classification can be properly augmented only for multi-label tasks, where each class is tied to a bounding box. In such cases, the classes belonging to bboxes falling outside the image are removed. In other cases, the classification annotation is kept as is.
Metadata
Metadata labels can contain arbitrary data and their semantics are unknown to the augmentation engine. Therefore, the only transformation applied to metadata is discarding metadata associated with boxes falling outside the image.
Arrays
Arrays are dealt with in the same way as metadata. The only transformation applied to arrays is discarding arrays associated with bboxes falling outside the image.
Oriented Bounding Boxes
(Not yet implemented)
Oriented bounding boxes are of shape (N, 5) where the last element of each row contains the angle of the bbox. This format is not supported by Albumentations, however, Albumentations support angle to be a part of the keypoints. So, the oriented bounding boxes are split into regular bounding boxes and a set of keypoints that represent the center of the bbox and contain the angle as the third coordinate.
Both the keypoints and the bboxes are augmented separately. At the end, the angle is extracted from the keypoints and added back to the bounding boxes. The keypoints are discarded.
Custom Augmentations
Custom augmentations can be implemented by creating a subclass of
A.BasicTransform and registering it in the TRANSFORMATIONS
registry.
Possible target types that the augmentation can receive are:
"image":
The image. All augmentations should usually support this target. For subclasses of A.ImageOnlyTransform or A.DualTransform this means overriding apply.
"bboxes":
Bounding boxes. For subclasses of A.DualTransform, this means overriding apply_to_bboxes.
"keypoints":
Keypoints. For subclasses of A.DualTransform, this means overriding apply_to_keypoints.
"mask":
Segmentation masks. For subclasses of A.DualTransform, this means overriding apply_to_mask.
"instance_mask":
Instance segmentation masks. For subclasses of
BatchTransform, this means overriding apply_to_instance_mask.Subclasses of A.DualTransform do not support this target; instance masks are treated as regular masks instead.
Custom augmentations can support instance masks by implementing their own logic for handling them and overriding the targets property to include the "instance_mask" target.
"array":
Arbitrary arrays. Can only be supported by custom augmentations by implementing their own logic and adding the "array" target to the targets property.
"metadata":
Metadata labels. Same situation as with the "array" type.
"classification":
One-hot encoded multi-task classification labels. Same situation as with the "array" type.
For example:
class CustomArrayAugmentation(A.BasicTransform): @property @override def targets(self): return { "image": self.apply, "array": self.apply_to_array, } @override def apply(self, image, **kwargs): ... def apply_to_array( self, array: np.ndarray, **kwargs ) -> np.ndarray: ...
| Method | __init__ |
Create an Albumentations-backed augmentation pipeline. |
| Method | apply |
Apply the augmentation pipeline to the data. |
| Property | batch |
The batch size required by the augmentation pipeline. |
| Static Method | _create |
Undocumented |
| Static Method | _create |
Undocumented |
| Static Method | _mark |
Mark keypoints outside the image bounds as invisible. |
| Static Method | _resolve |
Undocumented |
| Static Method | _task |
Undocumented |
| Static Method | _wrap |
Wrap an Albumentations composition for loader data dictionaries. |
| Method | _check |
Undocumented |
| Method | _postprocess |
Postprocess the augmented data back to LDF format. |
| Method | _preprocess |
Preprocess a batch of labels. |
| Instance Variable | _batch |
Undocumented |
| Instance Variable | _bbox |
Undocumented |
| Instance Variable | _custom |
Undocumented |
| Instance Variable | _image |
Undocumented |
| Instance Variable | _n |
Undocumented |
| Instance Variable | _pixel |
Undocumented |
| Instance Variable | _resize |
Undocumented |
| Instance Variable | _source |
Undocumented |
| Instance Variable | _spatial |
Undocumented |
| Instance Variable | _target |
Undocumented |
| Instance Variable | _targets |
Undocumented |
@override
int, width: int, targets: dict[ str, str], n_classes: dict[ str, int], source_names: list[ str], config: Iterable[ Params], keep_aspect_ratio: bool = True, is_validation_pipeline: bool | None = None, pipeline_stage: Literal[ 'train', 'val', 'test'] | None = None, min_bbox_visibility: float = 0.0, seed: int | None = None, bbox_area_threshold: float = 0.0004):
¶
Create an Albumentations-backed augmentation pipeline.
| Parameters | |
height:int | Target output image height. |
width:int | Target output image width. |
targets:dict[ | Task names mapped to task types. Supported task types are "array", "classification", "segmentation", "instance_segmentation", "boundingbox", "keypoints", and metadata tasks. |
ndict[ | Number of classes per task. |
sourcelist[ | Source names that should be treated as image targets. |
config:Iterable[ | Iterable of augmentation configuration dictionaries. |
keepbool | Whether the default resize transform should preserve image aspect ratio. |
isbool | None | Optional legacy flag selecting evaluation behavior.
Deprecated since version 0.5.0: use pipeline_stage instead.
|
pipelineLiteral[ | Optional explicit pipeline stage. Valid values are "train", "val", and "test". |
minfloat | Minimum visible fraction of a bounding box after augmentation. |
seed:int | None | Optional random seed. |
bboxfloat | Minimum normalized bounding-box area kept after augmentation. |
| Raises | |
ValueError | If a target task type is unsupported, more than one transform is marked for resizing, or a configured transform is not an Albumentations transform. |
TypeError | If a resizing transform has a non-numeric probability p. |
Apply the augmentation pipeline to the data.
| Parameters | |
inputlist[ | Loader outputs to augment. The number of items must match the engine's batch size. |
| Returns | |
LoaderMultiOutput | Augmented loader output. |
The batch size required by the augmentation pipeline.
The batch size is the number of images requested by the augmentation pipeline in case of batch-based augmentations.
For example, if the augmentation pipeline contains the MixUp augmentation, the batch size should be 2.
If the pipeline requires MixUp and also Mosaic4 augmentations, the batch size should be 8 = (2⋅4).
bool, height: int, width: int, p: float = 1.0) -> A.DualTransform:
¶
Undocumented
np.ndarray, shape: tuple[ int, int], **_) -> np.ndarray:
¶
Mark keypoints outside the image bounds as invisible.
| Parameters | |
keypoints:np.ndarray | Keypoints with visibility stored in the last column. |
shape:tuple[ | Image shape used for bounds checking. |
| **_ | Undocumented |
| Returns | |
np.ndarray | Copy of keypoints with out-of-bounds visibility set to zero. |
Literal[ 'train', 'val', 'test'] | None, is_validation_pipeline: bool | None) -> Literal[ 'train', 'val', 'test']:
¶
Undocumented
A.BaseCompose, is_pixel: bool = False, source_names: list[ str] | None = None) -> Callable[ ..., Data]:
¶
Wrap an Albumentations composition for loader data dictionaries.
| Parameters | |
transform:A.BaseCompose | Albumentations composition to wrap. |
isbool | Whether the composition contains pixel-only transforms that should be replayed across image sources. |
sourcelist[ | Image source names replayed for pixel-only transforms. |
| Returns | |
Callable[ | Callable that applies the composition to a data dictionary. |
| Raises | |
ValueError | If is_pixel is true and source_names is not provided. |
AlbumentationConfigItem, available_target_types: set):
¶
Undocumented
Postprocess the augmented data back to LDF format.
Discards labels associated with bounding boxes that are outside the image.
| Parameters | |
data:Data | Augmented data keyed by target name. |
ndict[ | Mapping from task names to keypoint counts. |
| Returns | |
LoaderMultiOutput | Augmented images and labels. |
list[ LoaderMultiOutput]) -> tuple[ list[ Data], dict[ str, int]]:
¶
Preprocess a batch of labels.
| Parameters | |
labelslist[ | Loader outputs to preprocess. |
| Returns | |
tuple[ | Preprocessed data and keypoint counts for each task. |