forked from mrq/DL-Art-School
Revert paired back
This commit is contained in:
parent
ad3e7df086
commit
2b36ca5f8e
codes
|
@ -15,39 +15,49 @@ from models.tacotron2.text import text_to_sequence, sequence_to_text
|
||||||
from utils.util import opt_get
|
from utils.util import opt_get
|
||||||
|
|
||||||
|
|
||||||
def parse_libri(line, base_path, split="|"):
|
def load_tsv(filename):
|
||||||
fpt = line.strip().split(split)
|
with open(filename, encoding='utf-8') as f:
|
||||||
fpt[0] = os.path.join(base_path, fpt[0])
|
components = [line.strip().split('\t') for line in f]
|
||||||
return fpt
|
base = os.path.dirname(filename)
|
||||||
|
filepaths_and_text = [[os.path.join(base, f'{component[1]}'), component[0]] for component in components]
|
||||||
|
return filepaths_and_text
|
||||||
|
|
||||||
|
|
||||||
def parse_tsv(line, base_path):
|
def load_tsv_aligned_codes(filename):
|
||||||
fpt = line.strip().split('\t')
|
with open(filename, encoding='utf-8') as f:
|
||||||
return os.path.join(base_path, f'{fpt[1]}'), fpt[0]
|
components = [line.strip().split('\t') for line in f]
|
||||||
|
base = os.path.dirname(filename)
|
||||||
|
def convert_string_list_to_tensor(strlist):
|
||||||
|
if strlist.startswith('['):
|
||||||
|
strlist = strlist[1:]
|
||||||
|
if strlist.endswith(']'):
|
||||||
|
strlist = strlist[:-1]
|
||||||
|
as_ints = [int(s) for s in strlist.split(', ')]
|
||||||
|
return torch.tensor(as_ints)
|
||||||
|
filepaths_and_text = [[os.path.join(base, f'{component[1]}'), component[0], convert_string_list_to_tensor(component[2])] for component in components]
|
||||||
|
return filepaths_and_text
|
||||||
|
|
||||||
|
|
||||||
def parse_tsv_aligned_codes(line, base_path):
|
def load_mozilla_cv(filename):
|
||||||
fpt = line.strip().split('\t')
|
with open(filename, encoding='utf-8') as f:
|
||||||
def convert_string_list_to_tensor(strlist):
|
components = [line.strip().split('\t') for line in f][1:] # First line is the header
|
||||||
if strlist.startswith('['):
|
base = os.path.dirname(filename)
|
||||||
strlist = strlist[1:]
|
filepaths_and_text = [[os.path.join(base, f'clips/{component[1]}'), component[2]] for component in components]
|
||||||
if strlist.endswith(']'):
|
return filepaths_and_text
|
||||||
strlist = strlist[:-1]
|
|
||||||
as_ints = [int(s) for s in strlist.split(', ')]
|
|
||||||
return torch.tensor(as_ints)
|
|
||||||
return os.path.join(base_path, f'{fpt[1]}'), fpt[0], convert_string_list_to_tensor(fpt[2])
|
|
||||||
|
|
||||||
|
|
||||||
def parse_mozilla_cv(line, base_path):
|
def load_voxpopuli(filename):
|
||||||
components = line.strip().split('\t')
|
with open(filename, encoding='utf-8') as f:
|
||||||
return os.path.join(base_path, f'clips/{components[1]}'), components[2]
|
lines = [line.strip().split('\t') for line in f][1:] # First line is the header
|
||||||
|
base = os.path.dirname(filename)
|
||||||
|
filepaths_and_text = []
|
||||||
def parse_voxpopuli(line, base_path):
|
for line in lines:
|
||||||
line = line.strip().split('\t')
|
if len(line) == 0:
|
||||||
file, raw_text, norm_text, speaker_id, split, gender = line
|
continue
|
||||||
year = file[:4]
|
file, raw_text, norm_text, speaker_id, split, gender = line
|
||||||
return os.path.join(base_path, year, f'{file}.ogg.wav'), raw_text
|
year = file[:4]
|
||||||
|
filepaths_and_text.append([os.path.join(base, year, f'{file}.ogg.wav'), raw_text])
|
||||||
|
return filepaths_and_text
|
||||||
|
|
||||||
|
|
||||||
class CharacterTokenizer:
|
class CharacterTokenizer:
|
||||||
|
@ -60,16 +70,14 @@ class CharacterTokenizer:
|
||||||
|
|
||||||
class TextWavLoader(torch.utils.data.Dataset):
|
class TextWavLoader(torch.utils.data.Dataset):
|
||||||
def __init__(self, hparams):
|
def __init__(self, hparams):
|
||||||
self.paths = hparams['path']
|
self.path = hparams['path']
|
||||||
if not isinstance(self.paths, list):
|
if not isinstance(self.path, list):
|
||||||
self.paths = [self.paths]
|
self.path = [self.path]
|
||||||
self.paths_size_bytes = [os.path.getsize(p) for p in self.paths]
|
|
||||||
self.total_size_bytes = sum(self.paths_size_bytes)
|
|
||||||
|
|
||||||
self.fetcher_mode = opt_get(hparams, ['fetcher_mode'], 'lj')
|
fetcher_mode = opt_get(hparams, ['fetcher_mode'], 'lj')
|
||||||
if not isinstance(self.fetcher_mode, list):
|
if not isinstance(fetcher_mode, list):
|
||||||
self.fetcher_mode = [self.fetcher_mode]
|
fetcher_mode = [fetcher_mode]
|
||||||
assert len(self.paths) == len(self.fetcher_mode)
|
assert len(self.path) == len(fetcher_mode)
|
||||||
|
|
||||||
self.load_conditioning = opt_get(hparams, ['load_conditioning'], False)
|
self.load_conditioning = opt_get(hparams, ['load_conditioning'], False)
|
||||||
self.conditioning_candidates = opt_get(hparams, ['num_conditioning_candidates'], 1)
|
self.conditioning_candidates = opt_get(hparams, ['num_conditioning_candidates'], 1)
|
||||||
|
@ -77,8 +85,25 @@ class TextWavLoader(torch.utils.data.Dataset):
|
||||||
self.debug_failures = opt_get(hparams, ['debug_loading_failures'], False)
|
self.debug_failures = opt_get(hparams, ['debug_loading_failures'], False)
|
||||||
self.load_aligned_codes = opt_get(hparams, ['load_aligned_codes'], False)
|
self.load_aligned_codes = opt_get(hparams, ['load_aligned_codes'], False)
|
||||||
self.aligned_codes_to_audio_ratio = opt_get(hparams, ['aligned_codes_ratio'], 443)
|
self.aligned_codes_to_audio_ratio = opt_get(hparams, ['aligned_codes_ratio'], 443)
|
||||||
|
self.audiopaths_and_text = []
|
||||||
|
for p, fm in zip(self.path, fetcher_mode):
|
||||||
|
if fm == 'lj' or fm == 'libritts':
|
||||||
|
fetcher_fn = load_filepaths_and_text
|
||||||
|
elif fm == 'tsv':
|
||||||
|
fetcher_fn = load_tsv_aligned_codes if self.load_aligned_codes else load_tsv
|
||||||
|
elif fm == 'mozilla_cv':
|
||||||
|
assert not self.load_conditioning # Conditioning inputs are incompatible with mozilla_cv
|
||||||
|
fetcher_fn = load_mozilla_cv
|
||||||
|
elif fm == 'voxpopuli':
|
||||||
|
assert not self.load_conditioning # Conditioning inputs are incompatible with voxpopuli
|
||||||
|
fetcher_fn = load_voxpopuli
|
||||||
|
else:
|
||||||
|
raise NotImplementedError()
|
||||||
|
self.audiopaths_and_text.extend(fetcher_fn(p))
|
||||||
self.text_cleaners = hparams.text_cleaners
|
self.text_cleaners = hparams.text_cleaners
|
||||||
self.sample_rate = hparams.sample_rate
|
self.sample_rate = hparams.sample_rate
|
||||||
|
random.seed(hparams.seed)
|
||||||
|
random.shuffle(self.audiopaths_and_text)
|
||||||
self.max_wav_len = opt_get(hparams, ['max_wav_length'], None)
|
self.max_wav_len = opt_get(hparams, ['max_wav_length'], None)
|
||||||
if self.max_wav_len is not None:
|
if self.max_wav_len is not None:
|
||||||
self.max_aligned_codes = self.max_wav_len // self.aligned_codes_to_audio_ratio
|
self.max_aligned_codes = self.max_wav_len // self.aligned_codes_to_audio_ratio
|
||||||
|
@ -109,64 +134,23 @@ class TextWavLoader(torch.utils.data.Dataset):
|
||||||
assert not torch.any(tokens == 0)
|
assert not torch.any(tokens == 0)
|
||||||
return tokens
|
return tokens
|
||||||
|
|
||||||
def load_random_line(self, depth=0):
|
|
||||||
assert depth < 10
|
|
||||||
|
|
||||||
rand_offset = random.randint(0, self.total_size_bytes)
|
|
||||||
for i in range(len(self.paths)):
|
|
||||||
if rand_offset < self.paths_size_bytes[i]:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
rand_offset -= self.paths_size_bytes[i]
|
|
||||||
path = self.paths[i]
|
|
||||||
fm = self.fetcher_mode[i]
|
|
||||||
with open(path, 'r', encoding='utf-8') as f:
|
|
||||||
f.seek(rand_offset)
|
|
||||||
# Read the rest of the line we seeked to, then the line after that.
|
|
||||||
try: # This can fail when seeking to a UTF-8 escape byte.
|
|
||||||
f.readline()
|
|
||||||
except:
|
|
||||||
return self.load_random_line(depth=depth + 1) # On failure, just recurse and try again.
|
|
||||||
l2 = f.readline()
|
|
||||||
|
|
||||||
if l2:
|
|
||||||
try:
|
|
||||||
base_path = os.path.dirname(path)
|
|
||||||
if fm == 'lj' or fm == 'libritts':
|
|
||||||
return parse_libri(l2, base_path)
|
|
||||||
elif fm == 'tsv':
|
|
||||||
return parse_tsv_aligned_codes(l2, base_path) if self.load_aligned_codes else parse_tsv(l2, base_path)
|
|
||||||
elif fm == 'mozilla_cv':
|
|
||||||
assert not self.load_conditioning # Conditioning inputs are incompatible with mozilla_cv
|
|
||||||
return parse_mozilla_cv(l2, base_path)
|
|
||||||
elif fm == 'voxpopuli':
|
|
||||||
assert not self.load_conditioning # Conditioning inputs are incompatible with voxpopuli
|
|
||||||
return parse_voxpopuli(l2, base_path)
|
|
||||||
else:
|
|
||||||
raise NotImplementedError()
|
|
||||||
except:
|
|
||||||
print(f"error parsing random offset: {sys.exc_info()}")
|
|
||||||
return self.load_random_line(depth=depth+1) # On failure, just recurse and try again.
|
|
||||||
|
|
||||||
|
|
||||||
def __getitem__(self, index):
|
def __getitem__(self, index):
|
||||||
self.skipped_items += 1
|
self.skipped_items += 1
|
||||||
apt = self.load_random_line()
|
|
||||||
try:
|
try:
|
||||||
tseq, wav, text, path = self.get_wav_text_pair(apt)
|
tseq, wav, text, path = self.get_wav_text_pair(self.audiopaths_and_text[index])
|
||||||
if text is None or len(text.strip()) == 0:
|
if text is None or len(text.strip()) == 0:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
cond, cond_is_self = load_similar_clips(apt[0], self.conditioning_length, self.sample_rate,
|
cond, cond_is_self = load_similar_clips(self.audiopaths_and_text[index][0], self.conditioning_length, self.sample_rate,
|
||||||
n=self.conditioning_candidates) if self.load_conditioning else (None, False)
|
n=self.conditioning_candidates) if self.load_conditioning else (None, False)
|
||||||
except:
|
except:
|
||||||
if self.skipped_items > 100:
|
if self.skipped_items > 100:
|
||||||
raise # Rethrow if we have nested too far.
|
raise # Rethrow if we have nested too far.
|
||||||
if self.debug_failures:
|
if self.debug_failures:
|
||||||
print(f"error loading {apt[0]} {sys.exc_info()}")
|
print(f"error loading {self.audiopaths_and_text[index][0]} {sys.exc_info()}")
|
||||||
return self[(index+1) % len(self)]
|
return self[(index+1) % len(self)]
|
||||||
|
|
||||||
if self.load_aligned_codes:
|
if self.load_aligned_codes:
|
||||||
aligned_codes = apt[2]
|
aligned_codes = self.audiopaths_and_text[index][2]
|
||||||
|
|
||||||
actually_skipped_items = self.skipped_items
|
actually_skipped_items = self.skipped_items
|
||||||
self.skipped_items = 0
|
self.skipped_items = 0
|
||||||
|
@ -205,7 +189,7 @@ class TextWavLoader(torch.utils.data.Dataset):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return self.total_size_bytes // 1000 # 1000 cuts down a TSV file to the actual length pretty well, but doesn't work with the other formats.
|
return len(self.audiopaths_and_text)
|
||||||
|
|
||||||
|
|
||||||
class PairedVoiceDebugger:
|
class PairedVoiceDebugger:
|
||||||
|
@ -240,23 +224,22 @@ class PairedVoiceDebugger:
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
batch_sz = 16
|
batch_sz = 8
|
||||||
params = {
|
params = {
|
||||||
'mode': 'paired_voice_audio',
|
'mode': 'paired_voice_audio',
|
||||||
#'path': ['Y:\\clips\\books1\\transcribed-w2v.tsv'],
|
'path': ['Y:\\clips\\books1\\transcribed-w2v.tsv'],
|
||||||
'path': ['Y:\\bigasr_dataset\\mozcv\\en\\train.tsv'],
|
'fetcher_mode': ['tsv'],
|
||||||
'fetcher_mode': ['mozilla_cv'],
|
|
||||||
'phase': 'train',
|
'phase': 'train',
|
||||||
'n_workers': 0,
|
'n_workers': 0,
|
||||||
'batch_size': batch_sz,
|
'batch_size': batch_sz,
|
||||||
'max_wav_length': 255995,
|
'max_wav_length': 255995,
|
||||||
'max_text_length': 200,
|
'max_text_length': 200,
|
||||||
'sample_rate': 22050,
|
'sample_rate': 22050,
|
||||||
'load_conditioning': False,
|
'load_conditioning': True,
|
||||||
'num_conditioning_candidates': 2,
|
'num_conditioning_candidates': 2,
|
||||||
'conditioning_length': 44000,
|
'conditioning_length': 44000,
|
||||||
'use_bpe_tokenizer': True,
|
'use_bpe_tokenizer': True,
|
||||||
'load_aligned_codes': False,
|
'load_aligned_codes': True,
|
||||||
}
|
}
|
||||||
from data import create_dataset, create_dataloader
|
from data import create_dataset, create_dataloader
|
||||||
|
|
||||||
|
@ -273,7 +256,7 @@ if __name__ == '__main__':
|
||||||
for i, b in tqdm(enumerate(dl)):
|
for i, b in tqdm(enumerate(dl)):
|
||||||
for ib in range(batch_sz):
|
for ib in range(batch_sz):
|
||||||
print(f'{i} {ib} {b["real_text"][ib]}')
|
print(f'{i} {ib} {b["real_text"][ib]}')
|
||||||
#save(b, i, ib, 'wav')
|
save(b, i, ib, 'wav')
|
||||||
#if i > 5:
|
if i > 5:
|
||||||
# break
|
break
|
||||||
|
|
||||||
|
|
|
@ -300,7 +300,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='../experiments/train_gpt_asr_mass_hf2_audio_only_fp32/train_gpt_asr_mass_hf2.yml')
|
parser.add_argument('-opt', type=str, help='Path to option YAML file.', default='../options/train_diffusion_tts.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()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user