Lint bert gen & remove unused vars

This commit is contained in:
Lengyue
2023-09-05 01:59:36 -04:00
parent d4d0082b05
commit 042fb96fd9

View File

@@ -1,23 +1,21 @@
import torch import torch
from torch.utils.data import DataLoader
from multiprocessing import Pool from multiprocessing import Pool
import commons import commons
import utils import utils
from data_utils import TextAudioSpeakerLoader, TextAudioSpeakerCollate
from tqdm import tqdm from tqdm import tqdm
import warnings
from text import cleaned_text_to_sequence, get_bert from text import cleaned_text_to_sequence, get_bert
config_path = 'configs/config.json' config_path = "configs/config.json"
hps = utils.get_hparams_from_file(config_path) hps = utils.get_hparams_from_file(config_path)
total_gpus = torch.cuda.device_count()
def process_line(line): def process_line(line):
_id, spk, language_str, text, phones, tone, word2ph = line.strip().split("|") wav_path, _, language_str, text, phones, tone, word2ph = line.strip().split("|")
phone = phones.split(" ") phone = phones.split(" ")
tone = [int(i) for i in tone.split(" ")] tone = [int(i) for i in tone.split(" ")]
word2ph = [int(i) for i in word2ph.split(" ")] word2ph = [int(i) for i in word2ph.split(" ")]
w2pho = [i for i in word2ph]
word2ph = [i for i in word2ph] word2ph = [i for i in word2ph]
phone, tone, language = cleaned_text_to_sequence(phone, tone, language_str) phone, tone, language = cleaned_text_to_sequence(phone, tone, language_str)
@@ -28,26 +26,27 @@ def process_line(line):
for i in range(len(word2ph)): for i in range(len(word2ph)):
word2ph[i] = word2ph[i] * 2 word2ph[i] = word2ph[i] * 2
word2ph[0] += 1 word2ph[0] += 1
wav_path = f'{_id}'
bert_path = wav_path.replace(".wav", ".bert.pt") bert_path = wav_path.replace(".wav", ".bert.pt")
try: try:
bert = torch.load(bert_path) bert = torch.load(bert_path)
assert bert.shape[-1] == len(phone) assert bert.shape[-1] == len(phone)
except: except Exception:
bert = get_bert(text, word2ph, language_str) bert = get_bert(text, word2ph, language_str)
assert bert.shape[-1] == len(phone) assert bert.shape[-1] == len(phone)
torch.save(bert, bert_path) torch.save(bert, bert_path)
if __name__ == '__main__': if __name__ == "__main__":
lines = [] lines = []
with open(hps.data.training_files, encoding='utf-8' ) as f: with open(hps.data.training_files, encoding="utf-8") as f:
lines.extend(f.readlines()) lines.extend(f.readlines())
with open(hps.data.validation_files, encoding='utf-8' ) as f: with open(hps.data.validation_files, encoding="utf-8") as f:
lines.extend(f.readlines()) lines.extend(f.readlines())
with Pool(processes=12) as pool: #A100 40GB suitable config,if coom,please decrease the processess number. # A100 40GB suitable config, if coom, please decrease the processes number.
for _ in tqdm(pool.imap_unordered(process_line, lines)): with Pool(processes=6) as pool:
for _ in tqdm(pool.imap_unordered(process_line, lines), total=len(lines)):
pass pass