diff --git a/codes/data/__init__.py b/codes/data/__init__.py index 9d4ba52b..4feca367 100644 --- a/codes/data/__init__.py +++ b/codes/data/__init__.py @@ -75,6 +75,8 @@ def create_dataset(dataset_opt, return_collate=False): collate = C(dataset_opt) elif mode == 'unsupervised_audio': from data.audio.unsupervised_audio_dataset import UnsupervisedAudioDataset as D + elif mode == 'unsupervised_audio_with_noise': + from data.audio.audio_with_noise_dataset import AudioWithNoiseDataset as D else: raise NotImplementedError('Dataset [{:s}] is not recognized.'.format(mode)) dataset = D(dataset_opt) diff --git a/codes/data/audio/audio_with_noise_dataset.py b/codes/data/audio/audio_with_noise_dataset.py index 834c5d95..011d8e69 100644 --- a/codes/data/audio/audio_with_noise_dataset.py +++ b/codes/data/audio/audio_with_noise_dataset.py @@ -109,7 +109,7 @@ class AudioWithNoiseDataset(Dataset): clip = clip + aug clip.clip_(-1, 1) except: - print("Exception encountered processing {item}, re-trying because this is often just a failed aug.") + print(f"Exception encountered processing {item}, re-trying because this is often just a failed aug.") return self[item] out['clip'] = clip diff --git a/codes/data/audio/unsupervised_audio_dataset.py b/codes/data/audio/unsupervised_audio_dataset.py index c3465964..b98ae2f3 100644 --- a/codes/data/audio/unsupervised_audio_dataset.py +++ b/codes/data/audio/unsupervised_audio_dataset.py @@ -2,6 +2,7 @@ import os import pathlib import random import sys +from warnings import warn import torch import torch.utils.data @@ -32,8 +33,8 @@ def load_audio(audiopath, sampling_rate): audio = audio[:, 0] if lsr != sampling_rate: - if lsr < sampling_rate: - print(f'{audiopath} has a sample rate of {sampling_rate} which is lower than the requested sample rate of {sampling_rate}. This is not a good idea.') + #if lsr < sampling_rate: + # warn(f'{audiopath} has a sample rate of {sampling_rate} which is lower than the requested sample rate of {sampling_rate}. This is not a good idea.') audio = torch.nn.functional.interpolate(audio.unsqueeze(0).unsqueeze(1), scale_factor=sampling_rate/lsr, mode='nearest', recompute_scale_factor=False).squeeze() # Check some assumptions about audio range. This should be automatically fixed in load_wav_to_torch, but might not be in some edge cases, where we should squawk. diff --git a/codes/data/util.py b/codes/data/util.py index 7c4c9e11..6c370b96 100644 --- a/codes/data/util.py +++ b/codes/data/util.py @@ -578,6 +578,20 @@ def imresize_np(img, scale, antialiasing=True): return out_2.numpy() +def load_paths_from_cache(paths, cache_path): + if not isinstance(paths, list): + paths = [paths] + if os.path.exists(cache_path): + output = torch.load(cache_path) + else: + print(f"Building cache for contents of {paths}..") + output = [] + for p in paths: + output.extend(find_files_of_type('img', p, qualifier=is_audio_file)[0]) + torch.save(output, cache_path) + return output + + if __name__ == '__main__': # test imresize function # read images diff --git a/codes/train.py b/codes/train.py index 26be2cff..2447843d 100644 --- a/codes/train.py +++ b/codes/train.py @@ -284,7 +284,7 @@ class Trainer: if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('-opt', type=str, help='Path to option YAML file.', default='../options/train_dvae_audio_clips_with_quantizer_compression.yml') + parser.add_argument('-opt', type=str, help='Path to option YAML file.', default='../options/train_noisy_audio_clips_classifier.yml') parser.add_argument('--launcher', choices=['none', 'pytorch'], default='none', help='job launcher') parser.add_argument('--local_rank', type=int, default=0) args = parser.parse_args() diff --git a/codes/trainer/injectors/base_injectors.py b/codes/trainer/injectors/base_injectors.py index 02d20b7d..20a4ae8e 100644 --- a/codes/trainer/injectors/base_injectors.py +++ b/codes/trainer/injectors/base_injectors.py @@ -539,8 +539,7 @@ class MelSpectrogramInjector(Injector): from munch import munchify from models.tacotron2 import hparams hp = munchify(hparams.create_hparams()) # Just use the default tacotron values for the MEL spectrogram. Noone uses anything else anyway. - self.stft = TacotronSTFT(hp.filter_length, hp.hop_length, hp.win_length, - hp.n_mel_channels, hp.sampling_rate, hp.mel_fmin, hp.mel_fmax) + self.stft = TacotronSTFT(hp.filter_length, hp.hop_length, hp.win_length, hp.n_mel_channels, hp.sampling_rate, hp.mel_fmin, hp.mel_fmax) def forward(self, state): inp = state[self.input]