-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdataset.py
54 lines (40 loc) · 1.43 KB
/
dataset.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import logging
import numpy as np
import torch as th
import random
from librosa.util import find_files
from torch.utils import data
from torch.utils.data import DataLoader
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
formatter = logging.Formatter(
"%(asctime)s [%(pathname)s:%(lineno)s - %(levelname)s ] %(message)s")
handler.setFormatter(formatter)
logger.addHandler(handler)
class TasDataset(object):
def __init__(self, file_path):
self.filelist = find_files(file_path, "npz")
def __getitem__(self, idx):
dat = np.load(self.filelist[idx])
mix_speech = dat["mix_speech"]
speech1 = dat["speech1"]
speech2 = dat["speech2"]
return th.from_numpy(mix_speech), th.from_numpy(speech1), th.from_numpy(speech2)
def __len__(self):
return len(self.filelist)
def test():
train_dataset = TasDataset('./data/train_input/')
train_loader = DataLoader(train_dataset, batch_size=128, shuffle=True,
num_workers=4, drop_last=True, pin_memory=True)
i = 0
for mix_speech, speech1, speech2 in train_loader:
while i<10:
print(mix_speech.shape)
print(speech1.shape)
print(speech2.shape)
print('\n')
i += 1
if __name__ == '__main__':
test()