Skip to content

Composition API (core.composition)

class albumentations.core.composition.Compose (transforms, bbox_params=None, keypoint_params=None, additional_targets=None, p=1.0) [view source on GitHub]

Compose transforms and handle all transformations regarding bounding boxes

Parameters:

Name Type Description
transforms list

list of transformations to compose.

bbox_params BboxParams

Parameters for bounding boxes transforms

keypoint_params KeypointParams

Parameters for keypoints transforms

additional_targets dict

Dict with keys - new target name, values - old target name. ex: {'image2': 'image'}

p float

probability of applying all list of transforms. Default: 1.0.

class albumentations.core.composition.OneOf (transforms, p=0.5) [view source on GitHub]

Select one of transforms to apply. Selected transform will be called with force_apply=True. Transforms probabilities will be normalized to one 1, so in this case transforms probabilities works as weights.

Parameters:

Name Type Description
transforms list

list of transformations to compose.

p float

probability of applying selected transform. Default: 0.5.

class albumentations.core.composition.OneOrOther (first=None, second=None, transforms=None, p=0.5) [view source on GitHub]

Select one or another transform to apply. Selected transform will be called with force_apply=True.

class albumentations.core.composition.PerChannel (transforms, channels=None, p=0.5) [view source on GitHub]

Apply transformations per-channel

Parameters:

Name Type Description
transforms list

list of transformations to compose.

channels sequence

channels to apply the transform to. Pass None to apply to all. Default: None (apply to all)

p float

probability of applying the transform. Default: 0.5.

class albumentations.core.composition.Sequential (transforms, p=0.5) [view source on GitHub]

Sequentially applies all transforms to targets.

Note: This transform is not intended to be a replacement for Compose. Instead, it should be used inside Compose the same way OneOf or OneOrOther are used. For instance, you can combine OneOf with Sequential to create an augmentation pipeline that contains multiple sequences of augmentations and applies one randomly chose sequence to input data (see the Example section for an example definition of such pipeline).

Examples:

>>> import albumentations as A
>>> transform = A.Compose([
>>>    A.OneOf([
>>>        A.Sequential([
>>>            A.HorizontalFlip(p=0.5),
>>>            A.ShiftScaleRotate(p=0.5),
>>>        ]),
>>>        A.Sequential([
>>>            A.VerticalFlip(p=0.5),
>>>            A.RandomBrightnessContrast(p=0.5),
>>>        ]),
>>>    ], p=1)
>>> ])

class albumentations.core.composition.SomeOf (transforms, n, replace=True, p=1) [view source on GitHub]

Select N transforms to apply. Selected transforms will be called with force_apply=True. Transforms probabilities will be normalized to one 1, so in this case transforms probabilities works as weights.

Parameters:

Name Type Description
transforms list

list of transformations to compose.

n int

number of transforms to apply.

replace bool

Whether the sampled transforms are with or without replacement. Default: True.

p float

probability of applying selected transform. Default: 1.