Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ jobs:
libhdf5-dev \
libfftw3-dev \
libgsl-dev \
libframel-dev \
libmetaio-dev \
pkg-config

- name: Install package and dev dependencies
Expand Down
3 changes: 3 additions & 0 deletions src/deepextractor/data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from deepextractor.data.datasets import SpectrogramDataset, TimeSeriesDataset

__all__ = ["SpectrogramDataset", "TimeSeriesDataset"]
52 changes: 52 additions & 0 deletions src/deepextractor/data/datasets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import numpy as np
import torch
from torch.utils.data import Dataset


class TimeSeriesDataset(Dataset):
"""Dataset for 1-D time-series arrays stored as .npy files.

Each array is expected to have shape ``(N, L)`` where *N* is the number
of samples and *L* is the signal length. Items are returned as
``(1, L)`` float32 tensors (channel dimension added).
"""

def __init__(self, input_npy, target_npy, transform=None):
self.inputs = np.load(input_npy)
self.targets = np.load(target_npy)
self.transform = transform

def __len__(self):
return len(self.inputs)

def __getitem__(self, idx):
x = torch.from_numpy(self.inputs[idx]).float().unsqueeze(0)
y = torch.from_numpy(self.targets[idx]).float().unsqueeze(0)
if self.transform:
x = self.transform(x)
y = self.transform(y)
return x, y


class SpectrogramDataset(Dataset):
"""Dataset for 2-D spectrogram arrays stored as .npy files.

Each array is expected to have shape ``(N, H, W)``. Items are returned
as ``(1, H, W)`` float32 tensors (channel dimension added).
"""

def __init__(self, input_npy, target_npy, transform=None):
self.inputs = np.load(input_npy)
self.targets = np.load(target_npy)
self.transform = transform

def __len__(self):
return len(self.inputs)

def __getitem__(self, idx):
x = torch.from_numpy(self.inputs[idx]).float().unsqueeze(0)
y = torch.from_numpy(self.targets[idx]).float().unsqueeze(0)
if self.transform:
x = self.transform(x)
y = self.transform(y)
return x, y
Loading