mirror of
https://github.com/wassname/TTS.git
synced 2026-09-20 12:30:22 +08:00
reformatting and styling
This commit is contained in:
@@ -3,9 +3,10 @@ import unittest
|
||||
import numpy as np
|
||||
import torch
|
||||
from torch import optim
|
||||
|
||||
from TTS.vocoder.models.wavegrad import Wavegrad
|
||||
|
||||
#pylint: disable=unused-variable
|
||||
# pylint: disable=unused-variable
|
||||
|
||||
torch.manual_seed(1)
|
||||
use_cuda = torch.cuda.is_available()
|
||||
@@ -19,19 +20,19 @@ class WavegradTrainTest(unittest.TestCase):
|
||||
mel_spec = torch.rand(8, 80, 20).to(device)
|
||||
|
||||
criterion = torch.nn.L1Loss().to(device)
|
||||
model = Wavegrad(in_channels=80,
|
||||
out_channels=1,
|
||||
upsample_factors=[5, 5, 3, 2, 2],
|
||||
upsample_dilations=[[1, 2, 1, 2], [1, 2, 1, 2],
|
||||
[1, 2, 4, 8], [1, 2, 4, 8],
|
||||
[1, 2, 4, 8]])
|
||||
model = Wavegrad(
|
||||
in_channels=80,
|
||||
out_channels=1,
|
||||
upsample_factors=[5, 5, 3, 2, 2],
|
||||
upsample_dilations=[[1, 2, 1, 2], [1, 2, 1, 2], [1, 2, 4, 8], [1, 2, 4, 8], [1, 2, 4, 8]],
|
||||
)
|
||||
|
||||
model_ref = Wavegrad(in_channels=80,
|
||||
out_channels=1,
|
||||
upsample_factors=[5, 5, 3, 2, 2],
|
||||
upsample_dilations=[[1, 2, 1, 2], [1, 2, 1, 2],
|
||||
[1, 2, 4, 8], [1, 2, 4, 8],
|
||||
[1, 2, 4, 8]])
|
||||
model_ref = Wavegrad(
|
||||
in_channels=80,
|
||||
out_channels=1,
|
||||
upsample_factors=[5, 5, 3, 2, 2],
|
||||
upsample_dilations=[[1, 2, 1, 2], [1, 2, 1, 2], [1, 2, 4, 8], [1, 2, 4, 8], [1, 2, 4, 8]],
|
||||
)
|
||||
model.train()
|
||||
model.to(device)
|
||||
betas = np.linspace(1e-6, 1e-2, 1000)
|
||||
@@ -39,8 +40,7 @@ class WavegradTrainTest(unittest.TestCase):
|
||||
model_ref.load_state_dict(model.state_dict())
|
||||
model_ref.to(device)
|
||||
count = 0
|
||||
for param, param_ref in zip(model.parameters(),
|
||||
model_ref.parameters()):
|
||||
for param, param_ref in zip(model.parameters(), model_ref.parameters()):
|
||||
assert (param - param_ref).sum() == 0, param
|
||||
count += 1
|
||||
optimizer = optim.Adam(model.parameters(), lr=0.001)
|
||||
@@ -52,11 +52,10 @@ class WavegradTrainTest(unittest.TestCase):
|
||||
optimizer.step()
|
||||
# check parameter changes
|
||||
count = 0
|
||||
for param, param_ref in zip(model.parameters(),
|
||||
model_ref.parameters()):
|
||||
for param, param_ref in zip(model.parameters(), model_ref.parameters()):
|
||||
# ignore pre-higway layer since it works conditional
|
||||
# if count not in [145, 59]:
|
||||
assert (param != param_ref).any(
|
||||
), "param {} with shape {} not updated!! \n{}\n{}".format(
|
||||
count, param.shape, param, param_ref)
|
||||
assert (param != param_ref).any(), "param {} with shape {} not updated!! \n{}\n{}".format(
|
||||
count, param.shape, param, param_ref
|
||||
)
|
||||
count += 1
|
||||
|
||||
Reference in New Issue
Block a user