callcut.io.intervals_to_frame_labels๐Ÿ”—

callcut.io.intervals_to_frame_labels(intervals, times)[source]๐Ÿ”—

Convert annotation intervals to per-frame binary labels.

For each frame, the label is 1.0 if the frameโ€™s time falls within any annotation interval, and 0.0 otherwise.

Parameters:
intervalsarray of shape (n_intervals, 2)

Annotation intervals as (start, stop) times in seconds. Can be empty (shape (0, 2)).

timesTensor of shape (n_frames,)

Time axis in seconds, typically from a feature extractor.

Returns:
labelsTensor of shape (n_frames,)

Binary labels (0.0 or 1.0) for each frame.

Examples

>>> import numpy as np
>>> import torch
>>> intervals = np.array([[1.0, 2.0], [3.5, 4.0]])
>>> times = torch.linspace(0, 5, 100)
>>> labels = intervals_to_frame_labels(intervals, times)
>>> labels.shape
torch.Size([100])
>>> labels.sum()  # frames within [1,2] and [3.5,4]
tensor(30.)