Dataset work for audio quality processor
This commit is contained in:
parent
0ee1c67ce5
commit
c3421b7f6d
|
@ -75,6 +75,8 @@ def create_dataset(dataset_opt, return_collate=False):
|
||||||
collate = C(dataset_opt)
|
collate = C(dataset_opt)
|
||||||
elif mode == 'unsupervised_audio':
|
elif mode == 'unsupervised_audio':
|
||||||
from data.audio.unsupervised_audio_dataset import UnsupervisedAudioDataset as D
|
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:
|
else:
|
||||||
raise NotImplementedError('Dataset [{:s}] is not recognized.'.format(mode))
|
raise NotImplementedError('Dataset [{:s}] is not recognized.'.format(mode))
|
||||||
dataset = D(dataset_opt)
|
dataset = D(dataset_opt)
|
||||||
|
|
|
@ -109,7 +109,7 @@ class AudioWithNoiseDataset(Dataset):
|
||||||
clip = clip + aug
|
clip = clip + aug
|
||||||
clip.clip_(-1, 1)
|
clip.clip_(-1, 1)
|
||||||
except:
|
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]
|
return self[item]
|
||||||
|
|
||||||
out['clip'] = clip
|
out['clip'] = clip
|
||||||
|
|
|
@ -2,6 +2,7 @@ import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
|
from warnings import warn
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
import torch.utils.data
|
import torch.utils.data
|
||||||
|
@ -32,8 +33,8 @@ def load_audio(audiopath, sampling_rate):
|
||||||
audio = audio[:, 0]
|
audio = audio[:, 0]
|
||||||
|
|
||||||
if lsr != sampling_rate:
|
if lsr != sampling_rate:
|
||||||
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.')
|
# 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()
|
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.
|
# 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.
|
||||||
|
|
|
@ -578,6 +578,20 @@ def imresize_np(img, scale, antialiasing=True):
|
||||||
return out_2.numpy()
|
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__':
|
if __name__ == '__main__':
|
||||||
# test imresize function
|
# test imresize function
|
||||||
# read images
|
# read images
|
||||||
|
|
|
@ -284,7 +284,7 @@ class Trainer:
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
parser = argparse.ArgumentParser()
|
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('--launcher', choices=['none', 'pytorch'], default='none', help='job launcher')
|
||||||
parser.add_argument('--local_rank', type=int, default=0)
|
parser.add_argument('--local_rank', type=int, default=0)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
|
@ -539,8 +539,7 @@ class MelSpectrogramInjector(Injector):
|
||||||
from munch import munchify
|
from munch import munchify
|
||||||
from models.tacotron2 import hparams
|
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.
|
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,
|
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)
|
||||||
hp.n_mel_channels, hp.sampling_rate, hp.mel_fmin, hp.mel_fmax)
|
|
||||||
|
|
||||||
def forward(self, state):
|
def forward(self, state):
|
||||||
inp = state[self.input]
|
inp = state[self.input]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user