albumentations.core.utils


Module containing utility functions and classes for the core Albumentations framework. This module provides a collection of helper functions and base classes used throughout the Albumentations library. It includes utilities for shape handling, parameter processing, data conversion, and serialization. The module defines abstract base classes for data processors that implement the conversion logic between different data formats used in the transformation pipeline.

Members

get_shapefunction

get_shape(
    data: dict[str, Any]
)

Extract (height, width) from data dict. Keys: image, images, volume. Raises if no image/volume present. Call for spatial checks during pipeline. After grayscale preprocessing, all data has channel dimension at the end. Args: data (dict[str, Any]): Dictionary containing image or volume data with one of: - 'volume': 3D array of shape (D, H, W, C) - 'image': 2D array of shape (H, W, C) - 'images': Batch of arrays of shape (N, H, W, C) Returns: tuple[int, int]: (height, width) dimensions

Parameters

NameTypeDefaultDescription
datadict[str, Any]--

get_image_datafunction

get_image_data(
    data: dict[str, Any]
)

Extract dtype, spatial dimensions, and channel count from the first canonical image, image batch, or volume in core pipelines. NumPy inputs use HWC, NHWC, or DHWC layout. Tensor inputs use CHW, NCHW, or CDHW layout. Args: data (dict[str, Any]): Dictionary potentially containing image/volume arrays. Returns: dict[str, Any]: Dictionary with 'dtype', 'height', 'width', 'num_channels' keys. Raises: ValueError: If no valid image/volume data keys are found in the dictionary.

Parameters

NameTypeDefaultDescription
datadict[str, Any]--

get_volume_shapefunction

get_volume_shape(
    volume: np.ndarray | torch.Tensor
)

Return `(D, H, W)` from a volume in its canonical container layout. NumPy volumes are `(D, H, W, C)` and Tensor volumes are `(C, D, H, W)` inside Compose. Channel-less `(D, H, W)` arrays are retained for direct functional calls.

Parameters

NameTypeDefaultDescription
volume
One of:
  • np.ndarray
  • torch.Tensor
--

format_argsfunction

format_args(
    args_dict: dict[str, Any]
)

Format a dict of argument names and values as "key1='val1', key2=val2" for repr. Strings are quoted; other values passed through str(). For transform __repr__. Args: args_dict (dict[str, Any]): Dictionary of argument names and values. Returns: str: Formatted string of arguments in the form "key1='value1', key2=value2".

Parameters

NameTypeDefaultDescription
args_dictdict[str, Any]--

Paramsclass

Params(
    coord_format: Any,
    label_fields: Sequence[str] | None
)

Base class for transform data params: coord_format and label_fields. BboxParams and KeypointParams subclass this. Serializable. Args: coord_format (Any): The coordinate format of the data this parameter object will process. label_fields (Sequence[str] | None): List of fields that are joined with the data, such as labels.

Parameters

NameTypeDefaultDescription
coord_formatAny--
label_fields
One of:
  • Sequence[str]
  • None
--

DataProcessorclass

DataProcessor(
    params: ParamsT,
    additional_targets: dict[str, str] | None
)

Abstract base for data processors: convert, validate, filter. Subclasses: BboxProcessor, KeypointsProcessor. Uses Params. Data processors handle the conversion, validation, and filtering of data during transformations. Args: params (Params): Parameters for data processing. additional_targets (dict[str, str] | None): Dictionary mapping additional target names to their types.

Parameters

NameTypeDefaultDescription
paramsParamsT--
additional_targets
One of:
  • dict[str, str]
  • None
--