albumentations.core.label_manager


Module for managing and transforming label data during augmentation. This module provides utilities for encoding, decoding, and tracking metadata for labels during the augmentation process. It includes classes for managing label transformations, preserving data types, and ensuring consistent handling of categorical, numerical, and mixed label types. The module supports automatic encoding of string labels to numerical values and restoration of original data types after processing.

custom_sortfunction

custom_sort(
    item: Any
)

Sort items by type then value for consistent label ordering. This function is used to sort labels in a consistent order, prioritizing numerical values before string values. All numerical values are given priority 0, while string values are given priority 1, ensuring numerical values are sorted first. Args: item (Any): Item to be sorted, can be either a numeric value or any other type. Returns: tuple[int, Real | str]: A tuple with sort priority (0 for numbers, 1 for others) and the value itself (or string representation for non-numeric values).

Parameters

NameTypeDefaultDescription
itemAny--

LabelEncoderclass

LabelEncoder()

Encodes labels into integer indices. This class handles the conversion between original label values and their numerical representations. It supports both numerical and categorical labels. Args: classes_ (dict[str | Real, int]): Mapping from original labels to encoded indices. inverse_classes_ (dict[int, str | Real]): Mapping from encoded indices to original labels. num_classes (int): Number of unique classes. is_numerical (bool): Whether the original labels are numerical.

LabelMetadataclass

LabelMetadata()

Stores metadata about a label field.

LabelManagerclass

LabelManager()

Manages label encoding and decoding across multiple data fields. This class handles the encoding, decoding, and type management for label fields. It maintains metadata about each field to ensure proper conversion between original and encoded representations. Args: metadata (dict[str, dict[str, LabelMetadata]]): Dictionary mapping data types and label fields to their metadata.