audiblelight.class_mappings.ClassMapping#
- class audiblelight.class_mappings.ClassMapping(mapping=None)#
Bases:
objectParent class for all class mapping objects
- Parameters:
mapping (dict[str, int] | None)
- __init__(mapping=None)#
- Parameters:
mapping (dict[str, int] | None)
Methods
__init__([mapping])from_dict(input_dict)Compute a class mapping from a dictionary
infer_label_idx_from_filepath(filepath)Given a filepath, infer the class label and index from this.
infer_missing_values(class_id, class_label)Infers missing class ID or label if only one is provided.
to_dict()Returns the class mapping as a dictionary
Validates mapping after class initialization
Attributes
"class_index"
"class_name
- TASK = None#
- YEAR = None#
- __getitem__(item)#
Convert a class name into class index, and vice-versa
- Parameters:
item (Any)
- Return type:
Any
- __len__()#
Returns the number of classes for this mapping
- Return type:
int
- classmethod from_dict(input_dict)#
Compute a class mapping from a dictionary
- Parameters:
input_dict (dict[str, int])
- infer_label_idx_from_filepath(filepath)#
Given a filepath, infer the class label and index from this.
Returns a tuple of None, None if the class label cannot be inferred.
- Parameters:
filepath (Path | str) – the path to infer the class label from
- Return type:
tuple[int, str] | tuple[None, None]
Examples
>>> fpath = "/AudibleLight/resources/soundevents/maleSpeech/train/Male_speech_and_man_speaking/67669.wav" >>> mapping = ClassMapping() >>> c, i = mapping.infer_label_idx_from_filepath(fpath) >>> print(c, i) tuple("maleSpeech", 1)
- infer_missing_values(class_id, class_label)#
Infers missing class ID or label if only one is provided.
If only class_label is provided, class_id is inferred.
If only class_id is provided, class_label is inferred.
If both are provided or both are None, returns them as-is.
- Parameters:
class_id (int | None)
class_label (str | None)
- Return type:
tuple[int | None, str | None]
- property mapping: dict[str, int]#
“class_index”
- Type:
Returns a mapping of “class_name”
- property mapping_inverted: dict[int, str]#
“class_name
- Type:
Returns an inverted mapping, from “class_index”
- to_dict()#
Returns the class mapping as a dictionary
- Return type:
dict[str, int]
- validate_mapping()#
Validates mapping after class initialization
- Return type:
None