forked from mrq/DL-Art-School
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)
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue
Block a user