callcut.io.CallDataset🔗
- class callcut.io.CallDataset(recordings, extractor, window_s=2.0, window_hop_s=0.5)[source]🔗
PyTorch Dataset for frame-level call detection.
Provides windowed samples of features with per-frame binary labels for training call detection models.
- Parameters:
- recordings
listofRecordingInfo Recording metadata from
scan_recordings().- extractor
BaseExtractor Feature extractor instance.
- window_s
float Window length in seconds for each sample.
- window_hop_s
float Hop between consecutive windows in seconds.
- recordings
Attributes
Number of recordings in the dataset.
Total number of windows (samples).
Window length in frames.
Window hop in frames.
Methods
Compute positive class weight for imbalanced data.
Notes
Lazy loading: Features are computed on-demand in
__getitem__rather than pre-loaded into memory. Results are cached via LRU cache.Examples
>>> from pathlib import Path >>> from callcut.extractors import SNRExtractor >>> from callcut.io import CallDataset, scan_recordings >>> from torch.utils.data import DataLoader >>> >>> extractor = SNRExtractor(sample_rate=32000, hop_ms=8.0, n_bands=8) >>> recordings = scan_recordings(list(Path("data/").glob("*.wav"))) >>> dataset = CallDataset( ... recordings=recordings, ... extractor=extractor, ... window_s=2.0, ... window_hop_s=0.5, ... ) >>> len(dataset) 1250 >>> X, y = dataset[0] >>> X.shape # (n_bands, window_frames) torch.Size([8, 250])
- compute_pos_weight()[source]🔗
Compute positive class weight for imbalanced data.
Useful for
torch.nn.BCEWithLogitsLoss(pos_weight=...).- Returns:
- pos_weight
Tensorof shape(1,) Weight for positive class:
n_negative / n_positive.
- pos_weight
Notes
This method loads all recordings to compute exact label statistics. For large datasets, this may take some time.
- property extractor🔗
Feature extractor used by this dataset.
- Type:
- property recordings🔗
Recordings in this dataset.
- Type:
list of
RecordingInfo