Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clamp audio samples to valid range to prevent NaN loss during training #108

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions data/ft_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def __init__(
spect_params,
sr=22050,
batch_size=1,
max_audio_sample: float = 1,
min_audio_sample: float = -1,
):
self.data_path = data_path
self.data = []
Expand All @@ -45,6 +47,11 @@ def __init__(
assert len(self.data) != 0
while len(self.data) < batch_size:
self.data += self.data
assert max_audio_sample is not None
assert min_audio_sample is not None
assert min_audio_sample < max_audio_sample
self.max_audio_sample = max_audio_sample
self.min_audio_sample = min_audio_sample

def __len__(self):
return len(self.data)
Expand All @@ -64,6 +71,7 @@ def __getitem__(self, idx):
speech = librosa.resample(speech, orig_sr, self.sr)

wave = torch.from_numpy(speech).float().unsqueeze(0)
wave = torch.clamp(wave, self.min_audio_sample, self.max_audio_sample)
mel = to_mel_fn(wave, self.mel_fn_args).squeeze(0)

return wave.squeeze(0), mel
Expand Down