vak.common.labels.to_map¶
- vak.common.labels.to_map(labelset: set, map_background: bool = True, background_label: str = 'background') dict [source]¶
Convert set of labels to dict mapping those labels to a series of consecutive integers from 0 to n inclusive, where n is the number of labels in the set.
This ‘labelmap’ is used when mapping labels from annotations of a vocalization into a label for every time bin in a spectrogram of that vocalization.
If
map_background
is True, then a label will be added to labelset representing a background class (any segment that is not labeled). The default for this label isvak.common.constants.DEFAULT_BACKGROUND_LABEL
. This string label will map to class index 0, so the total number of classes is n + 1.- Parameters:
labelset (set) – Set of labels used to annotate a dataset.
map_background (bool) – If True, include key specified by
background_label
in mapping. Any time bins in a spectrogram that do not have a label associated with them, e.g. a silent gap between vocalizations, will be assigned the integer that the background key maps to.background_label (str, optional) – The string label applied to segments belonging to the background class. Default is
vak.common.constants.DEFAULT_BACKGROUND_LABEL
.
- Returns:
labelmap – Maps labels to integers.
- Return type: