Your ad could be here - Reach CV/ML engineers
Contact for advertisingContactalbumentations.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.
Members
- functioncheck_range_bounds
- functionconvert_to_0plus_range
- functionconvert_to_1plus_range
- functioncreate_symmetric_range
- functionfloat2int
- functionnondecreasing
- functionprocess_non_negative_range
- functionrepeat_if_scalar
check_range_boundsfunction
Validates that all values in a tuple are within specified bounds.
Parameters
Name | Type | Default | Description |
---|---|---|---|
min_val | Number | - | Minimum allowed value. |
max_val | One of:
| None | Maximum allowed value. If None, only lower bound is checked. |
min_inclusive | bool | True | If True, min_val is inclusive (>=). If False, exclusive (>). |
max_inclusive | bool | True | If True, max_val is inclusive (<=). If False, exclusive (<). |
Returns
- Callable[[tuple[T, ...] | None], tuple[T, ...] | None]: Validator function that
Examples
>>> validator = check_range_bounds(0, 1) # For [0, 1] range
>>> validator((0.1, 0.5)) # Valid 2D
(0.1, 0.5)
>>> validator((0.1, 0.5, 0.7)) # Valid 3D
(0.1, 0.5, 0.7)
>>> validator((1.1, 0.5)) # Raises ValueError - outside range
>>> validator = check_range_bounds(0, 1, max_inclusive=False) # For [0, 1) range
>>> validator((0, 1)) # Raises ValueError - 1 not included
convert_to_0plus_rangefunction
Convert value to a range with lower bound of 0.
Parameters
Name | Type | Default | Description |
---|---|---|---|
value | One of:
| - | Input value. |
Returns
- tuple[float, float]: Range with minimum value of at least 0.
convert_to_1plus_rangefunction
Convert value to a range with lower bound of 1.
Parameters
Name | Type | Default | Description |
---|---|---|---|
value | One of:
| - | Input value. |
Returns
- tuple[float, float]: Range with minimum value of at least 1.
create_symmetric_rangefunction
Create a symmetric range around zero or use provided range.
Parameters
Name | Type | Default | Description |
---|---|---|---|
value | One of:
| - | Input value, either: - A tuple of two floats (used directly) - A single float (converted to (-value, value)) |
Returns
- tuple[float, float]: Symmetric range.
float2intfunction
Convert a tuple of floats to a tuple of integers.
Parameters
Name | Type | Default | Description |
---|---|---|---|
value | tuple[float, float] | - | Tuple of two float values. |
Returns
- tuple[int, int]: Tuple of two integer values.
nondecreasingfunction
Ensure a tuple of two numbers is in non-decreasing order.
Parameters
Name | Type | Default | Description |
---|---|---|---|
value | tuple[Number, Number] | - | Tuple of two numeric values to validate. |
Returns
- tuple[Number, Number]: The original tuple if valid.
process_non_negative_rangefunction
Process and validate a non-negative range.
Parameters
Name | Type | Default | Description |
---|---|---|---|
value | One of:
| - | 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
Convert a scalar value to a tuple by repeating it, or return the tuple as is.
Parameters
Name | Type | Default | Description |
---|---|---|---|
value | One of:
| - | Input value, either a scalar or tuple. |
Returns
- tuple[float, float]: If input is scalar, returns (value, value), otherwise returns input unchanged.