Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
TensorSpeech
GitHub Repository: TensorSpeech/TensorFlowTTS
Path: blob/master/test/test_auto.py
1558 views
1
# -*- coding: utf-8 -*-
2
# Copyright 2020 Minh Nguyen (@dathudeptrai)
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
# http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
16
import logging
17
import os
18
19
import pytest
20
import tensorflow as tf
21
22
from tensorflow_tts.inference import AutoConfig
23
from tensorflow_tts.inference import AutoProcessor
24
from tensorflow_tts.inference import TFAutoModel
25
26
os.environ["CUDA_VISIBLE_DEVICES"] = ""
27
28
logging.basicConfig(
29
level=logging.DEBUG,
30
format="%(asctime)s (%(module)s:%(lineno)d) %(levelname)s: %(message)s",
31
)
32
33
34
@pytest.mark.parametrize(
35
"mapper_path",
36
[
37
"./test/files/baker_mapper.json",
38
"./test/files/kss_mapper.json",
39
"./test/files/libritts_mapper.json",
40
"./test/files/ljspeech_mapper.json",
41
]
42
)
43
def test_auto_processor(mapper_path):
44
processor = AutoProcessor.from_pretrained(pretrained_path=mapper_path)
45
processor.save_pretrained("./test_saved")
46
processor = AutoProcessor.from_pretrained("./test_saved/processor.json")
47
48
49
@pytest.mark.parametrize(
50
"config_path",
51
[
52
"./examples/fastspeech/conf/fastspeech.v1.yaml",
53
"./examples/fastspeech/conf/fastspeech.v3.yaml",
54
"./examples/fastspeech2/conf/fastspeech2.v1.yaml",
55
"./examples/fastspeech2/conf/fastspeech2.v2.yaml",
56
"./examples/fastspeech2/conf/fastspeech2.kss.v1.yaml",
57
"./examples/fastspeech2/conf/fastspeech2.kss.v2.yaml",
58
"./examples/melgan/conf/melgan.v1.yaml",
59
"./examples/melgan_stft/conf/melgan_stft.v1.yaml",
60
"./examples/multiband_melgan/conf/multiband_melgan.v1.yaml",
61
"./examples/tacotron2/conf/tacotron2.v1.yaml",
62
"./examples/tacotron2/conf/tacotron2.kss.v1.yaml",
63
"./examples/parallel_wavegan/conf/parallel_wavegan.v1.yaml",
64
"./examples/hifigan/conf/hifigan.v1.yaml",
65
"./examples/hifigan/conf/hifigan.v2.yaml",
66
]
67
)
68
def test_auto_model(config_path):
69
config = AutoConfig.from_pretrained(pretrained_path=config_path)
70
model = TFAutoModel.from_pretrained(pretrained_path=None, config=config)
71
72
# test save_pretrained
73
config.save_pretrained("./test_saved")
74
model.save_pretrained("./test_saved")
75
76
# test from_pretrained
77
config = AutoConfig.from_pretrained("./test_saved/config.yml")
78
model = TFAutoModel.from_pretrained("./test_saved/model.h5", config=config)
79
80