mirror of
https://github.com/wassname/TTS.git
synced 2026-09-09 11:16:00 +08:00
mass linter fix
This commit is contained in:
@@ -1,35 +0,0 @@
|
||||
import unittest
|
||||
import torch as T
|
||||
|
||||
from mozilla_voice_tts.tts.utils.generic_utils import save_checkpoint, save_best_model
|
||||
from mozilla_voice_tts.tts.layers.tacotron import Prenet
|
||||
|
||||
OUT_PATH = '/tmp/test.pth.tar'
|
||||
|
||||
|
||||
class ModelSavingTests(unittest.TestCase):
|
||||
def save_checkpoint_test(self):
|
||||
# create a dummy model
|
||||
model = Prenet(128, out_features=[256, 128])
|
||||
model = T.nn.DataParallel(layer) #FIXME: undefined variable layer
|
||||
|
||||
# save the model
|
||||
save_checkpoint(model, None, 100, OUT_PATH, 1, 1)
|
||||
|
||||
# load the model to CPU
|
||||
model_dict = T.load(
|
||||
MODEL_PATH, map_location=lambda storage, loc: storage) #FIXME: undefined variable MODEL_PATH
|
||||
model.load_state_dict(model_dict['model'])
|
||||
|
||||
def save_best_model_test(self):
|
||||
# create a dummy model
|
||||
model = Prenet(256, out_features=[256, 256])
|
||||
model = T.nn.DataParallel(layer)
|
||||
|
||||
# save the model
|
||||
save_best_model(model, None, 0, 100, OUT_PATH, 10, 1)
|
||||
|
||||
# load the model to CPU
|
||||
model_dict = T.load(
|
||||
MODEL_PATH, map_location=lambda storage, loc: storage)
|
||||
model.load_state_dict(model_dict['model'])
|
||||
+5
-4
@@ -1,7 +1,8 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from tests import get_tests_path, get_tests_input_path, get_tests_output_path
|
||||
from tests import get_tests_input_path, get_tests_output_path, get_tests_path
|
||||
|
||||
from mozilla_voice_tts.utils.audio import AudioProcessor
|
||||
from mozilla_voice_tts.utils.io import load_config
|
||||
|
||||
@@ -103,7 +104,7 @@ class TestAudio(unittest.TestCase):
|
||||
assert (x_old - x).sum() == 0
|
||||
# check value range
|
||||
assert x_norm.max() <= self.ap.max_norm + 1, x_norm.max()
|
||||
assert x_norm.min() >= -self.ap.max_norm - 2, x_norm.min()
|
||||
assert x_norm.min() >= -self.ap.max_norm - 2, x_norm.min() #pylint: disable=invalid-unary-operand-type
|
||||
assert x_norm.min() <= 0, x_norm.min()
|
||||
# check denorm.
|
||||
x_ = self.ap._denormalize(x_norm)
|
||||
@@ -120,7 +121,7 @@ class TestAudio(unittest.TestCase):
|
||||
assert (x_old - x).sum() == 0
|
||||
# check value range
|
||||
assert x_norm.max() <= self.ap.max_norm, x_norm.max()
|
||||
assert x_norm.min() >= -self.ap.max_norm, x_norm.min()
|
||||
assert x_norm.min() >= -self.ap.max_norm, x_norm.min() #pylint: disable=invalid-unary-operand-type
|
||||
assert x_norm.min() <= 0, x_norm.min()
|
||||
# check denorm.
|
||||
x_ = self.ap._denormalize(x_norm)
|
||||
@@ -148,7 +149,7 @@ class TestAudio(unittest.TestCase):
|
||||
|
||||
assert (x_old - x).sum() == 0
|
||||
assert x_norm.max() <= self.ap.max_norm, x_norm.max()
|
||||
assert x_norm.min() >= -self.ap.max_norm, x_norm.min()
|
||||
assert x_norm.min() >= -self.ap.max_norm, x_norm.min() #pylint: disable=invalid-unary-operand-type
|
||||
assert x_norm.min() < 0, x_norm.min()
|
||||
x_ = self.ap._denormalize(x_norm)
|
||||
assert (x - x_).sum() < 1e-3
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import torch as T
|
||||
from tests import get_tests_input_path, get_tests_output_path
|
||||
|
||||
from mozilla_voice_tts.server.synthesizer import Synthesizer
|
||||
from tests import get_tests_input_path, get_tests_output_path
|
||||
from mozilla_voice_tts.tts.utils.text.symbols import make_symbols, phonemes, symbols
|
||||
from mozilla_voice_tts.tts.utils.generic_utils import setup_model
|
||||
from mozilla_voice_tts.tts.utils.io import save_checkpoint
|
||||
from mozilla_voice_tts.tts.utils.text.symbols import (make_symbols, phonemes,
|
||||
symbols)
|
||||
from mozilla_voice_tts.utils.io import load_config
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import torch as T
|
||||
from tests import get_tests_input_path
|
||||
|
||||
from tests import get_tests_path, get_tests_input_path
|
||||
from mozilla_voice_tts.speaker_encoder.model import SpeakerEncoder
|
||||
from mozilla_voice_tts.speaker_encoder.loss import GE2ELoss
|
||||
from mozilla_voice_tts.speaker_encoder.model import SpeakerEncoder
|
||||
from mozilla_voice_tts.utils.io import load_config
|
||||
|
||||
|
||||
file_path = get_tests_input_path()
|
||||
c = load_config(os.path.join(file_path, "test_config.json"))
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ from mozilla_voice_tts.tts.utils.generic_utils import sequence_mask
|
||||
|
||||
|
||||
class PrenetTests(unittest.TestCase):
|
||||
def test_in_out(self):
|
||||
def test_in_out(self): #pylint: disable=no-self-use
|
||||
layer = Prenet(128, out_features=[256, 128])
|
||||
dummy_input = T.rand(4, 128)
|
||||
|
||||
@@ -104,7 +104,7 @@ class DecoderTests(unittest.TestCase):
|
||||
|
||||
|
||||
class EncoderTests(unittest.TestCase):
|
||||
def test_in_out(self):
|
||||
def test_in_out(self): #pylint: disable=no-self-use
|
||||
layer = Encoder(128)
|
||||
dummy_input = T.rand(4, 8, 128)
|
||||
|
||||
@@ -117,7 +117,7 @@ class EncoderTests(unittest.TestCase):
|
||||
|
||||
|
||||
class L1LossMaskedTests(unittest.TestCase):
|
||||
def test_in_out(self):
|
||||
def test_in_out(self): #pylint: disable=no-self-use
|
||||
# test input == target
|
||||
layer = L1LossMasked(seq_len_norm=False)
|
||||
dummy_input = T.ones(4, 8, 128).float()
|
||||
|
||||
+10
-9
@@ -1,15 +1,16 @@
|
||||
import os
|
||||
import unittest
|
||||
import shutil
|
||||
import torch
|
||||
import numpy as np
|
||||
import unittest
|
||||
|
||||
from tests import get_tests_path, get_tests_input_path, get_tests_output_path
|
||||
import numpy as np
|
||||
import torch
|
||||
from tests import get_tests_input_path, get_tests_output_path
|
||||
from torch.utils.data import DataLoader
|
||||
from mozilla_voice_tts.utils.io import load_config
|
||||
from mozilla_voice_tts.utils.audio import AudioProcessor
|
||||
|
||||
from mozilla_voice_tts.tts.datasets import TTSDataset
|
||||
from mozilla_voice_tts.tts.datasets.preprocess import ljspeech
|
||||
from mozilla_voice_tts.utils.audio import AudioProcessor
|
||||
from mozilla_voice_tts.utils.io import load_config
|
||||
|
||||
#pylint: disable=unused-variable
|
||||
|
||||
@@ -32,7 +33,7 @@ class TestTTSDataset(unittest.TestCase):
|
||||
self.ap = AudioProcessor(**c.audio)
|
||||
|
||||
def _create_dataloader(self, batch_size, r, bgs):
|
||||
items = ljspeech(c.data_path,'metadata.csv')
|
||||
items = ljspeech(c.data_path, 'metadata.csv')
|
||||
dataset = TTSDataset.MyDataset(
|
||||
r,
|
||||
c.text_cleaner,
|
||||
@@ -74,7 +75,7 @@ class TestTTSDataset(unittest.TestCase):
|
||||
assert check_count == 0, \
|
||||
" !! Negative values in text_input: {}".format(check_count)
|
||||
# TODO: more assertion here
|
||||
assert type(speaker_name[0]) is str
|
||||
assert isinstance(speaker_name[0], str)
|
||||
assert linear_input.shape[0] == c.batch_size
|
||||
assert linear_input.shape[2] == self.ap.fft_size // 2 + 1
|
||||
assert mel_input.shape[0] == c.batch_size
|
||||
@@ -82,7 +83,7 @@ class TestTTSDataset(unittest.TestCase):
|
||||
# check normalization ranges
|
||||
if self.ap.symmetric_norm:
|
||||
assert mel_input.max() <= self.ap.max_norm
|
||||
assert mel_input.min() >= -self.ap.max_norm
|
||||
assert mel_input.min() >= -self.ap.max_norm #pylint: disable=invalid-unary-operand-type
|
||||
assert mel_input.min() < 0
|
||||
else:
|
||||
assert mel_input.max() <= self.ap.max_norm
|
||||
|
||||
@@ -7,7 +7,7 @@ from mozilla_voice_tts.tts.datasets.preprocess import common_voice
|
||||
|
||||
class TestPreprocessors(unittest.TestCase):
|
||||
|
||||
def test_common_voice_preprocessor(self):
|
||||
def test_common_voice_preprocessor(self): #pylint: disable=no-self-use
|
||||
root_path = get_tests_input_path()
|
||||
meta_file = "common_voice.tsv"
|
||||
items = common_voice(root_path, meta_file)
|
||||
|
||||
@@ -20,8 +20,8 @@ c = load_config(os.path.join(get_tests_input_path(), 'test_config.json'))
|
||||
|
||||
|
||||
class TacotronTrainTest(unittest.TestCase):
|
||||
def test_train_step(self):
|
||||
input = torch.randint(0, 24, (8, 128)).long().to(device)
|
||||
def test_train_step(self): # pylint: disable=no-self-use
|
||||
input_dummy = torch.randint(0, 24, (8, 128)).long().to(device)
|
||||
input_lengths = torch.randint(100, 128, (8, )).long().to(device)
|
||||
input_lengths = torch.sort(input_lengths, descending=True)[0]
|
||||
mel_spec = torch.rand(8, 30, c.audio['num_mels']).to(device)
|
||||
@@ -34,7 +34,7 @@ class TacotronTrainTest(unittest.TestCase):
|
||||
for idx in mel_lengths:
|
||||
stop_targets[:, int(idx.item()):, 0] = 1.0
|
||||
|
||||
stop_targets = stop_targets.view(input.shape[0],
|
||||
stop_targets = stop_targets.view(input_dummy.shape[0],
|
||||
stop_targets.size(1) // c.r, -1)
|
||||
stop_targets = (stop_targets.sum(2) > 0.0).unsqueeze(2).float().squeeze()
|
||||
|
||||
@@ -51,7 +51,7 @@ class TacotronTrainTest(unittest.TestCase):
|
||||
optimizer = optim.Adam(model.parameters(), lr=c.lr)
|
||||
for i in range(5):
|
||||
mel_out, mel_postnet_out, align, stop_tokens = model.forward(
|
||||
input, input_lengths, mel_spec, mel_lengths, speaker_ids)
|
||||
input_dummy, input_lengths, mel_spec, mel_lengths, speaker_ids)
|
||||
assert torch.sigmoid(stop_tokens).data.max() <= 1.0
|
||||
assert torch.sigmoid(stop_tokens).data.min() >= 0.0
|
||||
optimizer.zero_grad()
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
import os
|
||||
import torch
|
||||
import unittest
|
||||
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
import torch
|
||||
from tests import get_tests_input_path
|
||||
|
||||
from mozilla_voice_tts.tts.tf.models.tacotron2 import Tacotron2
|
||||
from mozilla_voice_tts.tts.tf.utils.tflite import (convert_tacotron2_to_tflite,
|
||||
load_tflite_model)
|
||||
from mozilla_voice_tts.utils.io import load_config
|
||||
|
||||
tf.get_logger().setLevel('INFO')
|
||||
|
||||
from tests import get_tests_path, get_tests_input_path, get_tests_output_path
|
||||
|
||||
from mozilla_voice_tts.utils.io import load_config
|
||||
from mozilla_voice_tts.tts.tf.models.tacotron2 import Tacotron2
|
||||
from mozilla_voice_tts.tts.tf.utils.tflite import convert_tacotron2_to_tflite, load_tflite_model
|
||||
|
||||
#pylint: disable=unused-variable
|
||||
|
||||
@@ -132,4 +136,3 @@ class TacotronTFTrainTest(unittest.TestCase):
|
||||
postnet_output = tflite_model.get_tensor(output_details[1]['index'])
|
||||
# remove tflite binary
|
||||
os.remove('test_tacotron2.tflite')
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ def test_phoneme_to_sequence():
|
||||
lang = "en-us"
|
||||
sequence = phoneme_to_sequence(text, text_cleaner, lang)
|
||||
text_hat = sequence_to_phoneme(sequence)
|
||||
sequence_with_params = phoneme_to_sequence(text, text_cleaner, lang, tp=conf.characters)
|
||||
_ = phoneme_to_sequence(text, text_cleaner, lang, tp=conf.characters)
|
||||
text_hat_with_params = sequence_to_phoneme(sequence, tp=conf.characters)
|
||||
gt = "ɹiːsənt ɹɪsɜːtʃ æt hɑːɹvɚd hɐz ʃoʊn mɛdᵻteɪɾɪŋ fɔːɹ æz lɪɾəl æz eɪt wiːks kæn æktʃuːəli ɪnkɹiːs, ðə ɡɹeɪ mæɾɚɹ ɪnðə pɑːɹts ʌvðə bɹeɪn ɹɪspɑːnsəbəl fɔːɹ ɪmoʊʃənəl ɹɛɡjuːleɪʃən ænd lɜːnɪŋ!"
|
||||
assert text_hat == text_hat_with_params == gt
|
||||
@@ -25,7 +25,7 @@ def test_phoneme_to_sequence():
|
||||
text = "Be a voice, not an! echo?"
|
||||
sequence = phoneme_to_sequence(text, text_cleaner, lang)
|
||||
text_hat = sequence_to_phoneme(sequence)
|
||||
sequence_with_params = phoneme_to_sequence(text, text_cleaner, lang, tp=conf.characters)
|
||||
_ = phoneme_to_sequence(text, text_cleaner, lang, tp=conf.characters)
|
||||
text_hat_with_params = sequence_to_phoneme(sequence, tp=conf.characters)
|
||||
gt = "biː ɐ vɔɪs, nɑːt ɐn! ɛkoʊ?"
|
||||
print(text_hat)
|
||||
@@ -36,7 +36,7 @@ def test_phoneme_to_sequence():
|
||||
text = "Be a voice, not an! echo"
|
||||
sequence = phoneme_to_sequence(text, text_cleaner, lang)
|
||||
text_hat = sequence_to_phoneme(sequence)
|
||||
sequence_with_params = phoneme_to_sequence(text, text_cleaner, lang, tp=conf.characters)
|
||||
_ = phoneme_to_sequence(text, text_cleaner, lang, tp=conf.characters)
|
||||
text_hat_with_params = sequence_to_phoneme(sequence, tp=conf.characters)
|
||||
gt = "biː ɐ vɔɪs, nɑːt ɐn! ɛkoʊ"
|
||||
print(text_hat)
|
||||
@@ -47,7 +47,7 @@ def test_phoneme_to_sequence():
|
||||
text = "Be a voice, not an echo!"
|
||||
sequence = phoneme_to_sequence(text, text_cleaner, lang)
|
||||
text_hat = sequence_to_phoneme(sequence)
|
||||
sequence_with_params = phoneme_to_sequence(text, text_cleaner, lang, tp=conf.characters)
|
||||
_ = phoneme_to_sequence(text, text_cleaner, lang, tp=conf.characters)
|
||||
text_hat_with_params = sequence_to_phoneme(sequence, tp=conf.characters)
|
||||
gt = "biː ɐ vɔɪs, nɑːt ɐn ɛkoʊ!"
|
||||
print(text_hat)
|
||||
@@ -58,7 +58,7 @@ def test_phoneme_to_sequence():
|
||||
text = "Be a voice, not an! echo. "
|
||||
sequence = phoneme_to_sequence(text, text_cleaner, lang)
|
||||
text_hat = sequence_to_phoneme(sequence)
|
||||
sequence_with_params = phoneme_to_sequence(text, text_cleaner, lang, tp=conf.characters)
|
||||
_ = phoneme_to_sequence(text, text_cleaner, lang, tp=conf.characters)
|
||||
text_hat_with_params = sequence_to_phoneme(sequence, tp=conf.characters)
|
||||
gt = "biː ɐ vɔɪs, nɑːt ɐn! ɛkoʊ."
|
||||
print(text_hat)
|
||||
@@ -69,7 +69,7 @@ def test_phoneme_to_sequence():
|
||||
text = "Be a voice, not an! echo. "
|
||||
sequence = phoneme_to_sequence(text, text_cleaner, lang, True)
|
||||
text_hat = sequence_to_phoneme(sequence)
|
||||
sequence_with_params = phoneme_to_sequence(text, text_cleaner, lang, tp=conf.characters)
|
||||
_ = phoneme_to_sequence(text, text_cleaner, lang, tp=conf.characters)
|
||||
text_hat_with_params = sequence_to_phoneme(sequence, tp=conf.characters)
|
||||
gt = "^biː ɐ vɔɪs, nɑːt ɐn! ɛkoʊ.~"
|
||||
print(text_hat)
|
||||
@@ -80,7 +80,7 @@ def test_phoneme_to_sequence():
|
||||
text = "_Be a _voice, not an! echo_"
|
||||
sequence = phoneme_to_sequence(text, text_cleaner, lang)
|
||||
text_hat = sequence_to_phoneme(sequence)
|
||||
sequence_with_params = phoneme_to_sequence(text, text_cleaner, lang, tp=conf.characters)
|
||||
_ = phoneme_to_sequence(text, text_cleaner, lang, tp=conf.characters)
|
||||
text_hat_with_params = sequence_to_phoneme(sequence, tp=conf.characters)
|
||||
gt = "biː ɐ vɔɪs, nɑːt ɐn! ɛkoʊ"
|
||||
print(text_hat)
|
||||
|
||||
@@ -23,4 +23,4 @@ def test_melgan_multi_scale_discriminator():
|
||||
assert np.all(scores[0].shape == (4, 1, 64))
|
||||
assert np.all(feats[0][0].shape == (4, 16, 4096))
|
||||
assert np.all(feats[0][1].shape == (4, 64, 1024))
|
||||
assert np.all(feats[0][2].shape == (4, 256, 256))
|
||||
assert np.all(feats[0][2].shape == (4, 256, 256))
|
||||
|
||||
@@ -11,4 +11,3 @@ def test_melgan_generator():
|
||||
assert np.all(output.shape == (4, 1, 64 * 256))
|
||||
output = model.inference(dummy_input)
|
||||
assert np.all(output.shape == (4, 1, (64 + 4) * 256))
|
||||
|
||||
|
||||
@@ -25,4 +25,3 @@ def test_pqmf():
|
||||
print(w2_.min())
|
||||
print(w2_.mean())
|
||||
sf.write('pqmf_output.wav', w2_.flatten().detach(), sr)
|
||||
|
||||
|
||||
@@ -26,4 +26,3 @@ def test_pqmf():
|
||||
print(w2_.min())
|
||||
print(w2_.mean())
|
||||
sf.write('tf_pqmf_output.wav', w2_.flatten(), sr)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user