-
Notifications
You must be signed in to change notification settings - Fork 1
/
PhonoDataset.py
34 lines (26 loc) · 994 Bytes
/
PhonoDataset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from torch.utils.data import Dataset
import numpy as np
import torch
class TrainDataset(Dataset):
def __init__(self, recordings, features, labels):
self.recordings = recordings
self.features = features
self.labels = labels
def __len__(self):
return len(self.recordings)
def __getitem__(self, index):
recording = self.recordings[index].reshape(1,-1)
label = self.labels[index]
label = torch.as_tensor(label).float()
features = torch.from_numpy(self.features[index]).float()
return recording, features, label
class TestDataset(Dataset):
def __init__(self, recordings, features):
self.recordings = recordings
self.features = features
def __len__(self):
return len(self.recordings)
def __getitem__(self, index):
recording = self.recordings[index].reshape(1,-1)
features = torch.from_numpy(self.features[index]).float()
return recording, features