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.
Members
- functioncustom_sort
- classLabelEncoder
- classLabelMetadata
- classLabelManager
custom_sortfunction
custom_sort(
item: Any
)Return a sort key (priority, value) so labels sort consistently: numbers first (priority 0), then strings (priority 1). Used for 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
| Name | Type | Default | Description |
|---|---|---|---|
| item | Any | - | - |
LabelEncoderclass
LabelEncoder()Encode original label values (numeric or categorical) to integer indices and back. Keeps classes_ and inverse_classes_ mapping. 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 for a label field: input_type, is_numerical, dtype, and optional LabelEncoder for encoding and decoding.
LabelManagerclass
LabelManager()Manages encoding, decoding, and type handling for label fields across data types. Maintains per-field metadata and encoders. 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.