-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataloader.py
executable file
·49 lines (43 loc) · 1.97 KB
/
dataloader.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: winston lin
"""
import numpy as np
from torch.utils.data import Dataset
from scipy.io import loadmat
from utils import getPaths
class MspPodcastDataset(Dataset):
"""MSP-Podcast Emotion dataset."""
def __init__(self, root_dir, label_dir, split_set, emo_attr):
# Parameters
self.root_dir = root_dir
# Loading Label Distribution
self._paths, self._labels = getPaths(label_dir, split_set=split_set, emo_attr=emo_attr)
# Loading Norm-Feature
self.Feat_mean_All = loadmat('./NormTerm/feat_norm_means.mat')['normal_para']
self.Feat_std_All = loadmat('./NormTerm/feat_norm_stds.mat')['normal_para']
# Loading Norm-Label
if emo_attr == 'Act':
self.Label_mean = loadmat('./NormTerm/act_norm_means.mat')['normal_para'][0][0]
self.Label_std = loadmat('./NormTerm/act_norm_stds.mat')['normal_para'][0][0]
elif emo_attr == 'Dom':
self.Label_mean = loadmat('./NormTerm/dom_norm_means.mat')['normal_para'][0][0]
self.Label_std = loadmat('./NormTerm/dom_norm_stds.mat')['normal_para'][0][0]
elif emo_attr == 'Val':
self.Label_mean = loadmat('./NormTerm/val_norm_means.mat')['normal_para'][0][0]
self.Label_std = loadmat('./NormTerm/val_norm_stds.mat')['normal_para'][0][0]
def __len__(self):
return len(self._paths)
def __getitem__(self, idx):
# Loading Data & Normalization
data = loadmat(self.root_dir + self._paths[idx].replace('.wav','.mat'))['Audio_data']
data = data[:,1:] # remove time-info
# z-norm and bounded in -3~3 range (i.e., 99.5% values coverage)
data = (data-self.Feat_mean_All)/self.Feat_std_All
data[np.isnan(data)]=0
data[data>3]=3
data[data<-3]=-3
# Label Normalization
label = (self._labels[idx]-self.Label_mean)/self.Label_std
return data, label