File size: 1,173 Bytes
df07554 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import torch
import numpy as np
import string
import shutil
import os
def kwargify(**kwargs):
return kwargs
def show_lr(optimizer):
lr = []
for param_group in optimizer.param_groups:
lr += [param_group['lr']]
return np.array(lr).mean()
def contains_nan_or_inf(tensor):
return torch.isnan(tensor).any() or torch.isinf(tensor).any()
def map_phonemes(phonemes):
new_phonemes = []
charset = string.printable.strip()
for phoneme in phonemes:
if phoneme == ' ':
new_phonemes.append(phoneme)
else:
index = phonemes.index(phoneme) - 1
new_phonemes.append(charset[index])
return new_phonemes
def empty_dir(directory):
for filename in os.listdir(directory):
file_path = os.path.join(directory, filename)
try:
if os.path.isfile(file_path):
os.remove(file_path)
elif os.path.islink(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
except Exception as e:
print('Failed to delete %s. Reason: %s' % (file_path, e)) |