-
Notifications
You must be signed in to change notification settings - Fork 3
/
data_utils.py
41 lines (39 loc) · 1.38 KB
/
data_utils.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
import numpy as np
from torch import Tensor
import librosa
from torch.utils.data import Dataset
from RawBoost import process_Rawboost_feature
from utils import pad
class Dataset_train(Dataset):
def __init__(self, args, list_IDs, labels, base_dir, algo):
self.list_IDs = list_IDs
self.labels = labels
self.base_dir = base_dir
self.algo=algo
self.args=args
self.cut=66800
def __len__(self):
return len(self.list_IDs)
def __getitem__(self, index):
utt_id = self.list_IDs[index]
X, fs = librosa.load(self.base_dir+'flac/'+utt_id+'.flac', sr=16000)
Y=process_Rawboost_feature(X, fs, self.args, self.algo)
X_pad= pad(Y, self.cut)
x_inp= Tensor(X_pad)
target = self.labels[utt_id]
return x_inp, target
class Dataset_eval(Dataset):
def __init__(self, list_IDs, base_dir, track):
'''self.list_IDs : list of strings (each string: utt key),'''
self.list_IDs = list_IDs
self.base_dir = base_dir
self.cut = 66800 # take ~4 sec audio
self.track = track
def __len__(self):
return len(self.list_IDs)
def __getitem__(self, index):
utt_id = self.list_IDs[index]
X, fs = librosa.load(self.base_dir+'flac/'+utt_id+'.flac', sr=16000)
X_pad = pad(X,self.cut)
x_inp = Tensor(X_pad)
return x_inp, utt_id