Transformer running

This commit is contained in:
Steffen Illium
2021-03-04 12:01:08 +01:00
parent b5e3e5aec1
commit f89f0f8528
14 changed files with 349 additions and 80 deletions

View File

@ -60,7 +60,8 @@ class LibrosaAudioToMelDataset(Dataset):
self.mel_file_path.unlink(missing_ok=True)
if not self.mel_file_path.exists():
self.mel_file_path.parent.mkdir(parents=True, exist_ok=True)
raw_sample, _ = librosa.core.load(self.audio_path, sr=self.sampling_rate)
with self.audio_path.open(mode='rb') as audio_file:
raw_sample, _ = librosa.core.load(audio_file, sr=self.sampling_rate)
mel_sample = self._mel_transform(raw_sample)
with self.mel_file_path.open('wb') as mel_file:
pickle.dump(mel_sample, mel_file, protocol=pickle.HIGHEST_PROTOCOL)

View File

@ -22,10 +22,12 @@ class TorchMelDataset(Dataset):
self.mel_hop_len = int(mel_hop_len)
self.sub_segment_hop_len = int(sub_segment_hop_len)
self.n = int((self.sampling_rate / self.mel_hop_len) * self.audio_file_len + 1)
if self.sub_segment_len and self.sub_segment_hop_len:
if self.sub_segment_len and self.sub_segment_hop_len and (self.n - self.sub_segment_len) > 0:
self.offsets = list(range(0, self.n - self.sub_segment_len, self.sub_segment_hop_len))
else:
self.offsets = [0]
if len(self) == 0:
print('what happend here')
self.label = label
self.transform = transform