albumentations.core.pydantic


Module containing Pydantic validation utilities for Albumentations. This module provides a collection of validators and utility functions used for validating parameters in the Pydantic models throughout the Albumentations library. It includes functions for ensuring numeric ranges are valid, handling type conversions, and creating standardized validation patterns that are reused across the codebase.

check_range_boundsfunction

check_range_bounds(
    min_val: Number,
    max_val: Number | None = None,
    min_inclusive: bool = True,
    max_inclusive: bool = True
)

Validates that all values in a tuple are within specified bounds.

Parameters

NameTypeDefaultDescription
min_valNumber-Minimum allowed value.
max_val
One of:
  • Number
  • None
NoneMaximum allowed value. If None, only lower bound is checked.
min_inclusiveboolTrueIf True, min_val is inclusive (>=). If False, exclusive (>).
max_inclusiveboolTrueIf True, max_val is inclusive (<=). If False, exclusive (<).

Returns

  • Callable[[tuple[T, ...] | None], tuple[T, ...] | None]: Validator function that

convert_to_0plus_rangefunction

convert_to_0plus_range(
    value: tuple[float, float] | float
)

Convert value to a range with lower bound of 0.

Parameters

NameTypeDefaultDescription
value
One of:
  • tuple[float, float]
  • float
-Input value.

Returns

  • tuple[float, float]: Range with minimum value of at least 0.

convert_to_1plus_rangefunction

convert_to_1plus_range(
    value: tuple[float, float] | float
)

Convert value to a range with lower bound of 1.

Parameters

NameTypeDefaultDescription
value
One of:
  • tuple[float, float]
  • float
-Input value.

Returns

  • tuple[float, float]: Range with minimum value of at least 1.

create_symmetric_rangefunction

create_symmetric_range(
    value: tuple[float, float] | float
)

Create a symmetric range around zero or use provided range.

Parameters

NameTypeDefaultDescription
value
One of:
  • tuple[float, float]
  • float
-Input value, either: - A tuple of two floats (used directly) - A single float (converted to (-value, value))

Returns

  • tuple[float, float]: Symmetric range.

float2intfunction

float2int(
    value: tuple[float, float]
)

Convert a tuple of floats to a tuple of integers.

Parameters

NameTypeDefaultDescription
valuetuple[float, float]-Tuple of two float values.

Returns

  • tuple[int, int]: Tuple of two integer values.

nondecreasingfunction

nondecreasing(
    value: tuple[Number, Number]
)

Ensure a tuple of two numbers is in non-decreasing order.

Parameters

NameTypeDefaultDescription
valuetuple[Number, Number]-Tuple of two numeric values to validate.

Returns

  • tuple[Number, Number]: The original tuple if valid.

process_non_negative_rangefunction

process_non_negative_range(
    value: tuple[float, float] | float | None
)

Process and validate a non-negative range.

Parameters

NameTypeDefaultDescription
value
One of:
  • tuple[float, float]
  • float
  • None
-Value to process. Can be: - A tuple of two floats - A single float (converted to symmetric range) - None (defaults to 0)

Returns

  • tuple[float, float]: Validated non-negative range.

repeat_if_scalarfunction

repeat_if_scalar(
    value: tuple[float, float] | float
)

Convert a scalar value to a tuple by repeating it, or return the tuple as is.

Parameters

NameTypeDefaultDescription
value
One of:
  • tuple[float, float]
  • float
-Input value, either a scalar or tuple.

Returns

  • tuple[float, float]: If input is scalar, returns (value, value), otherwise returns input unchanged.