vak.transforms.frame_labels.transforms.PostProcess#

class vak.transforms.frame_labels.transforms.PostProcess(timebin_dur: float, unlabeled_label: int = 0, min_segment_dur: float | None = None, majority_vote: bool = False)[source]#

Bases: object

Apply post-processing transformations to a vector of frame labels.

Optional post-processing consist of two transforms, that both rely on there being a label that corresponds to the ā€œunlabeledā€ (or ā€œbackgroundā€) class. The first removes any segments that are shorter than a specified duration, by converting labels in those segments to the ā€œbackgroundā€ / ā€œunlabeledā€ class label. The second performs a ā€œmajority voteā€ transform within run of labels that is bordered on both sides by the ā€œbackgroundā€ label. I.e., it counts the number of times any label occurs in that segment, and then assigns all bins the most common label.

The function performs those steps in this order (pseudo-code):

if min_segment_dur:
    frame_labels = remove_short_segments(frame_labels, labelmap, min_segment_dur)
if majority_vote:
    frame_labels = majority_vote(frame_labels, labelmap)
return frame_labels
timebin_dur#

Duration of a time bin in a spectrogram, e.g., as estimated from vector of times using vak.timebins.timebin_dur_from_vec.

Type:

float

unlabeled_label#

Label that was given to segments that were not labeled in annotation, e.g. silent periods between annotated segments. Default is 0.

Type:

int

min_segment_dur#

Minimum duration of segment, in seconds. If specified, then any segment with a duration less than min_segment_dur is removed from frame_labels. Default is None, in which case no segments are removed.

Type:

float

majority_vote#

If True, transform segments containing multiple labels into segments with a single label by taking a ā€œmajority voteā€, i.e. assign all time bins in the segment the most frequently occurring label in the segment. This transform can only be applied if the labelmap contains an ā€˜unlabeledā€™ label, because unlabeled segments makes it possible to identify the labeled segments. Default is False.

Type:

bool

__init__(timebin_dur: float, unlabeled_label: int = 0, min_segment_dur: float | None = None, majority_vote: bool = False)[source]#

Methods

__init__(timebin_dur[, unlabeled_label, ...])