Core API (albumentations.core)

Composition

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

Compose transforms and handle all transformations regrading bounding boxes

Parameters:
  • 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)[source]

Select one of transforms to apply

Parameters:
  • transforms (list) – list of transformations to compose.
  • p (float) – probability of applying selected transform. Default: 0.5.
class albumentations.core.composition.BboxParams(format, label_fields=None, min_area=0.0, min_visibility=0.0)[source]

Parameters of bounding boxes

Parameters:
  • format (str) –

    format of bounding boxes. Should be ‘coco’, ‘pascal_voc’, ‘albumentations’ or ‘yolo’.

    The coco format
    [x_min, y_min, width, height], e.g. [97, 12, 150, 200].
    The pascal_voc format
    [x_min, y_min, x_max, y_max], e.g. [97, 12, 247, 212].
    The albumentations format
    is like pascal_voc, but normalized, in other words: [x_min, y_min, x_max, y_max]`, e.g. [0.2, 0.3, 0.4, 0.5].
    The yolo format
    [x, y, width, height], e.g. [0.1, 0.2, 0.3, 0.4]; x, y - normalized bbox center; width, height - normalized bbox width and height.
  • label_fields (list) – list of fields that are joined with boxes, e.g labels. Should be same type as boxes.
  • min_area (float) – minimum area of a bounding box. All bounding boxes whose visible area in pixels is less than this value will be removed. Default: 0.0.
  • min_visibility (float) – minimum fraction of area for a bounding box to remain this box in list. Default: 0.0.
class albumentations.core.composition.KeypointParams(format, label_fields=None, remove_invisible=True, angle_in_degrees=True)[source]

Parameters of keypoints

Parameters:
  • format (str) –

    format of keypoints. Should be ‘xy’, ‘yx’, ‘xya’, ‘xys’, ‘xyas’, ‘xysa’.

    x - X coordinate,

    y - Y coordinate

    s - Keypoint scale

    a - Keypoint orientation in radians or degrees (depending on KeypointParams.angle_in_degrees)

  • label_fields (list) – list of fields that are joined with keypoints, e.g labels. Should be same type as keypoints.
  • remove_invisible (bool) – to remove invisible points after transform or not
  • angle_in_degrees (bool) – angle in degrees or radians in ‘xya’, ‘xyas’, ‘xysa’ keypoints
class albumentations.core.composition.ReplayCompose(transforms, bbox_params=None, keypoint_params=None, additional_targets=None, p=1.0, save_key='replay')[source]

Transforms interface

albumentations.core.transforms_interface.to_tuple(param, low=None, bias=None)[source]

Convert input argument to min-max tuple :param param: Input value.

If value is scalar, return value would be (offset - value, offset + value). If value is tuple, return value would be value + offset (broadcasted).
Parameters:
  • low – Second element of tuple can be passed as optional argument
  • bias – An offset factor added to each element
class albumentations.core.transforms_interface.DualTransform(always_apply=False, p=0.5)[source]

Transform for segmentation task.

class albumentations.core.transforms_interface.ImageOnlyTransform(always_apply=False, p=0.5)[source]

Transform applied to image only.

class albumentations.core.transforms_interface.NoOp(always_apply=False, p=0.5)[source]

Does nothing

Serialization

albumentations.core.serialization.to_dict(transform, on_not_implemented_error='raise')[source]

Take a transform pipeline and convert it to a serializable representation that uses only standard python data types: dictionaries, lists, strings, integers, and floats.

Parameters:transform (object) – A transform that should be serialized. If the transform doesn’t implement the to_dict method and on_not_implemented_error equals to ‘raise’ then NotImplementedError is raised. If on_not_implemented_error equals to ‘warn’ then NotImplementedError will be ignored but no transform parameters will be serialized.
albumentations.core.serialization.from_dict(transform_dict, lambda_transforms=None)[source]
Parameters:
  • transform (dict) – A dictionary with serialized transform pipeline.
  • lambda_transforms (dict) – A dictionary that contains lambda transforms, that is instances of the Lambda class. This dictionary is required when you are restoring a pipeline that contains lambda transforms. Keys in that dictionary should be named same as name arguments in respective lambda transforms from a serialized pipeline.
albumentations.core.serialization.save(transform, filepath, data_format='json', on_not_implemented_error='raise')[source]

Take a transform pipeline, serialize it and save a serialized version to a file using either json or yaml format.

Parameters:
  • transform (obj) – Transform to serialize.
  • filepath (str) – Filepath to write to.
  • data_format (str) – Serialization format. Should be either json or ‘yaml’.
  • on_not_implemented_error (str) – Parameter that describes what to do if a transform doesn’t implement the to_dict method. If ‘raise’ then NotImplementedError is raised, if warn then the exception will be ignored and no transform arguments will be saved.
albumentations.core.serialization.load(filepath, data_format='json', lambda_transforms=None)[source]

Load a serialized pipeline from a json or yaml file and construct a transform pipeline.

Parameters:
  • transform (obj) – Transform to serialize.
  • filepath (str) – Filepath to read from.
  • data_format (str) – Serialization format. Should be either json or ‘yaml’.
  • lambda_transforms (dict) – A dictionary that contains lambda transforms, that is instances of the Lambda class. This dictionary is required when you are restoring a pipeline that contains lambda transforms. Keys in that dictionary should be named same as name arguments in respective lambda transforms from a serialized pipeline.