-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheval_dataloader.py
66 lines (51 loc) · 1.59 KB
/
eval_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
Class of dataloader for evaluation
"""
import os
import torch
import pandas as pd
from torch.utils.data import Dataset
import torchaudio
import numpy as np
from utils.masking_thresholds import MaskingThresholds
class MusicNoiseDataset(Dataset):
def __init__(
self,
root_dir,
csv_file,
nfft,
sr,
set,
hpss_music,
hpss_noise):
self.root_dir = root_dir
# set_metadata, files_id = load_set(set, csv_file)
self.metadata = pd.read_csv(csv_file)
self.metadata = self.metadata[self.metadata['set'] == set]
self.nfft = nfft
self.sr = sr
# global amplitude maximum in the dataset.
self.global_maximum_amplitude = 43048712.0
self.masking_thresholds = MaskingThresholds(
nfft=self.nfft,
sr=self.sr
)
def __len__(self):
return len(self.metadata)
def __getitem__(self, idx):
if torch.is_tensor(idx):
idx = idx.tolist()
music_path = os.path.join(
self.root_dir,
self.metadata['music_path'].iloc[idx]
)
noise_path = os.path.join(
self.root_dir,
self.metadata['noise_path'].iloc[idx]
)
music_waveform, _ = torchaudio.load(uri=music_path)
noise_waveform, _ = torchaudio.load(uri=noise_path)
max_amplitude_couple = self.metadata['max_amplitude_couple'].iloc[idx]
music_waveform = max_amplitude_couple * music_waveform / self.global_maximum_amplitude
noise_waveform = max_amplitude_couple * noise_waveform / self.global_maximum_amplitude
return music_waveform.squeeze(0), noise_waveform.squeeze(0), idx