mirror of
https://github.com/wassname/TTS.git
synced 2026-09-11 12:00:24 +08:00
Merge branch 'master' of https://github.com/Mozilla/TTS
Conflicts: README.md best_model_config.json datasets/LJSpeech.py layers/tacotron.py notebooks/TacotronPlayGround.ipynb notebooks/utils.py tests/layers_tests.py tests/loader_tests.py tests/tacotron_tests.py train.py utils/generic_utils.py
This commit is contained in:
@@ -9,6 +9,7 @@ import torch
|
||||
import subprocess
|
||||
import numpy as np
|
||||
from collections import OrderedDict
|
||||
from torch.autograd import Variable
|
||||
|
||||
|
||||
class AttrDict(dict):
|
||||
@@ -134,6 +135,25 @@ def lr_decay(init_lr, global_step, warmup_steps):
|
||||
return lr
|
||||
|
||||
|
||||
def create_attn_mask(N, T, g=0.05):
|
||||
r'''creating attn mask for guided attention
|
||||
TODO: vectorize'''
|
||||
M = np.zeros([N, T])
|
||||
for t in range(T):
|
||||
for n in range(N):
|
||||
val = 20 * np.exp(-pow((n/N)-(t/T), 2.0)/g)
|
||||
M[n, t] = val
|
||||
e_x = np.exp(M - np.max(M))
|
||||
M = e_x / e_x.sum(axis=0) # only difference
|
||||
M = torch.FloatTensor(M).t().cuda()
|
||||
M = torch.stack([M]*32)
|
||||
return M
|
||||
|
||||
|
||||
def mk_decay(init_mk, max_epoch, n_epoch):
|
||||
return init_mk * ((max_epoch - n_epoch) / max_epoch)
|
||||
|
||||
|
||||
def count_parameters(model):
|
||||
r"""Count number of trainable parameters in a network"""
|
||||
return sum(p.numel() for p in model.parameters() if p.requires_grad)
|
||||
|
||||
Reference in New Issue
Block a user