Spaces:
Sleeping
Sleeping
Naozumi0512
commited on
Commit
•
1a79a73
1
Parent(s):
f3babb1
init
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitignore +184 -0
- .gitmodules +0 -0
- LICENSE +661 -0
- app.py +560 -0
- attentions.py +464 -0
- bert_gen.py +93 -0
- commons.py +158 -0
- compress_model.py +89 -0
- config.py +261 -0
- config.yml +177 -0
- configs/config.json +955 -0
- css/custom.css +18 -0
- data/finetuned/configs/config.json +106 -0
- data/finetuned/models/G_43000.pth +3 -0
- data_utils.py +371 -0
- default_config.yml +177 -0
- emotional/clap-htsat-fused/.gitattributes +34 -0
- emotional/clap-htsat-fused/README.md +107 -0
- emotional/clap-htsat-fused/config.json +207 -0
- emotional/clap-htsat-fused/merges.txt +0 -0
- emotional/clap-htsat-fused/preprocessor_config.json +22 -0
- emotional/clap-htsat-fused/special_tokens_map.json +15 -0
- emotional/clap-htsat-fused/tokenizer.json +0 -0
- emotional/clap-htsat-fused/tokenizer_config.json +16 -0
- emotional/clap-htsat-fused/vocab.json +0 -0
- emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/.gitattributes +28 -0
- emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/LICENSE +437 -0
- emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/README.md +127 -0
- emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/config.json +122 -0
- emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/preprocessor_config.json +9 -0
- emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/vocab.json +1 -0
- export_onnx.py +15 -0
- img/yuyu.png +0 -0
- img//345/217/202/346/225/260/350/257/264/346/230/216.png +0 -0
- img//345/256/265/345/256/253.png +0 -0
- img//345/276/256/344/277/241/345/233/276/347/211/207_20231010105112.png +0 -0
- img//347/245/236/351/207/214/347/273/253/345/215/216.png +0 -0
- img//347/272/263/350/245/277/345/246/262.png +0 -0
- infer.py +366 -0
- losses.py +153 -0
- mel_processing.py +142 -0
- models.py +1071 -0
- modules.py +580 -0
- monotonic_align/__init__.py +16 -0
- monotonic_align/core.py +46 -0
- onnx_infer.py +60 -0
- onnx_modules/V200/__init__.py +4 -0
- onnx_modules/V200/attentions_onnx.py +378 -0
- onnx_modules/V200/models_onnx.py +990 -0
- onnx_modules/V200/text/__init__.py +1 -0
.gitignore
ADDED
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Byte-compiled / optimized / DLL files
|
2 |
+
__pycache__/
|
3 |
+
*.py[cod]
|
4 |
+
*$py.class
|
5 |
+
|
6 |
+
# C extensions
|
7 |
+
*.so
|
8 |
+
|
9 |
+
# Distribution / packaging
|
10 |
+
.Python
|
11 |
+
build/
|
12 |
+
develop-eggs/
|
13 |
+
dist/
|
14 |
+
downloads/
|
15 |
+
eggs/
|
16 |
+
.eggs/
|
17 |
+
lib/
|
18 |
+
lib64/
|
19 |
+
parts/
|
20 |
+
sdist/
|
21 |
+
var/
|
22 |
+
wheels/
|
23 |
+
share/python-wheels/
|
24 |
+
*.egg-info/
|
25 |
+
.installed.cfg
|
26 |
+
*.egg
|
27 |
+
MANIFEST
|
28 |
+
|
29 |
+
# PyInstaller
|
30 |
+
# Usually these files are written by a python script from a template
|
31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
32 |
+
*.manifest
|
33 |
+
*.spec
|
34 |
+
|
35 |
+
# Installer logs
|
36 |
+
pip-log.txt
|
37 |
+
pip-delete-this-directory.txt
|
38 |
+
|
39 |
+
# Unit test / coverage reports
|
40 |
+
htmlcov/
|
41 |
+
.tox/
|
42 |
+
.nox/
|
43 |
+
.coverage
|
44 |
+
.coverage.*
|
45 |
+
.cache
|
46 |
+
nosetests.xml
|
47 |
+
coverage.xml
|
48 |
+
*.cover
|
49 |
+
*.py,cover
|
50 |
+
.hypothesis/
|
51 |
+
.pytest_cache/
|
52 |
+
cover/
|
53 |
+
|
54 |
+
# Translations
|
55 |
+
*.mo
|
56 |
+
*.pot
|
57 |
+
|
58 |
+
# Django stuff:
|
59 |
+
*.log
|
60 |
+
local_settings.py
|
61 |
+
db.sqlite3
|
62 |
+
db.sqlite3-journal
|
63 |
+
|
64 |
+
# Flask stuff:
|
65 |
+
instance/
|
66 |
+
.webassets-cache
|
67 |
+
|
68 |
+
# Scrapy stuff:
|
69 |
+
.scrapy
|
70 |
+
|
71 |
+
# Sphinx documentation
|
72 |
+
docs/_build/
|
73 |
+
|
74 |
+
# PyBuilder
|
75 |
+
.pybuilder/
|
76 |
+
target/
|
77 |
+
|
78 |
+
# Jupyter Notebook
|
79 |
+
.ipynb_checkpoints
|
80 |
+
|
81 |
+
# IPython
|
82 |
+
profile_default/
|
83 |
+
ipython_config.py
|
84 |
+
|
85 |
+
# pyenv
|
86 |
+
# For a library or package, you might want to ignore these files since the code is
|
87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
88 |
+
# .python-version
|
89 |
+
|
90 |
+
# pipenv
|
91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
94 |
+
# install all needed dependencies.
|
95 |
+
#Pipfile.lock
|
96 |
+
|
97 |
+
# poetry
|
98 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
100 |
+
# commonly ignored for libraries.
|
101 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
102 |
+
#poetry.lock
|
103 |
+
|
104 |
+
# pdm
|
105 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
106 |
+
#pdm.lock
|
107 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
108 |
+
# in version control.
|
109 |
+
# https://pdm.fming.dev/#use-with-ide
|
110 |
+
.pdm.toml
|
111 |
+
|
112 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
113 |
+
__pypackages__/
|
114 |
+
|
115 |
+
# Celery stuff
|
116 |
+
celerybeat-schedule
|
117 |
+
celerybeat.pid
|
118 |
+
|
119 |
+
# SageMath parsed files
|
120 |
+
*.sage.py
|
121 |
+
|
122 |
+
# Environments
|
123 |
+
.env
|
124 |
+
.venv
|
125 |
+
env/
|
126 |
+
venv/
|
127 |
+
ENV/
|
128 |
+
env.bak/
|
129 |
+
venv.bak/
|
130 |
+
|
131 |
+
# Spyder project settings
|
132 |
+
.spyderproject
|
133 |
+
.spyproject
|
134 |
+
|
135 |
+
# Rope project settings
|
136 |
+
.ropeproject
|
137 |
+
|
138 |
+
# mkdocs documentation
|
139 |
+
/site
|
140 |
+
|
141 |
+
# mypy
|
142 |
+
.mypy_cache/
|
143 |
+
.dmypy.json
|
144 |
+
dmypy.json
|
145 |
+
|
146 |
+
# Pyre type checker
|
147 |
+
.pyre/
|
148 |
+
|
149 |
+
# pytype static type analyzer
|
150 |
+
.pytype/
|
151 |
+
|
152 |
+
# Cython debug symbols
|
153 |
+
cython_debug/
|
154 |
+
|
155 |
+
# PyCharm
|
156 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
157 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
158 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160 |
+
#.idea/
|
161 |
+
|
162 |
+
.DS_Store
|
163 |
+
/models
|
164 |
+
/logs
|
165 |
+
|
166 |
+
filelists/*
|
167 |
+
!/filelists/esd.list
|
168 |
+
!/default_config.yml
|
169 |
+
/Web/
|
170 |
+
/emotional/*/*.bin
|
171 |
+
/slm/*/*.bin
|
172 |
+
/bert/*/*.bin
|
173 |
+
/bert/*/*.h5
|
174 |
+
/bert/*/*.model
|
175 |
+
/bert/*/*.safetensors
|
176 |
+
/bert/*/*.msgpack
|
177 |
+
asr_transcript.py
|
178 |
+
extract_list.py
|
179 |
+
dataset
|
180 |
+
Model
|
181 |
+
raw/
|
182 |
+
logs/
|
183 |
+
/onnx
|
184 |
+
/.vs
|
.gitmodules
ADDED
File without changes
|
LICENSE
ADDED
@@ -0,0 +1,661 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GNU AFFERO GENERAL PUBLIC LICENSE
|
2 |
+
Version 3, 19 November 2007
|
3 |
+
|
4 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
5 |
+
Everyone is permitted to copy and distribute verbatim copies
|
6 |
+
of this license document, but changing it is not allowed.
|
7 |
+
|
8 |
+
Preamble
|
9 |
+
|
10 |
+
The GNU Affero General Public License is a free, copyleft license for
|
11 |
+
software and other kinds of works, specifically designed to ensure
|
12 |
+
cooperation with the community in the case of network server software.
|
13 |
+
|
14 |
+
The licenses for most software and other practical works are designed
|
15 |
+
to take away your freedom to share and change the works. By contrast,
|
16 |
+
our General Public Licenses are intended to guarantee your freedom to
|
17 |
+
share and change all versions of a program--to make sure it remains free
|
18 |
+
software for all its users.
|
19 |
+
|
20 |
+
When we speak of free software, we are referring to freedom, not
|
21 |
+
price. Our General Public Licenses are designed to make sure that you
|
22 |
+
have the freedom to distribute copies of free software (and charge for
|
23 |
+
them if you wish), that you receive source code or can get it if you
|
24 |
+
want it, that you can change the software or use pieces of it in new
|
25 |
+
free programs, and that you know you can do these things.
|
26 |
+
|
27 |
+
Developers that use our General Public Licenses protect your rights
|
28 |
+
with two steps: (1) assert copyright on the software, and (2) offer
|
29 |
+
you this License which gives you legal permission to copy, distribute
|
30 |
+
and/or modify the software.
|
31 |
+
|
32 |
+
A secondary benefit of defending all users' freedom is that
|
33 |
+
improvements made in alternate versions of the program, if they
|
34 |
+
receive widespread use, become available for other developers to
|
35 |
+
incorporate. Many developers of free software are heartened and
|
36 |
+
encouraged by the resulting cooperation. However, in the case of
|
37 |
+
software used on network servers, this result may fail to come about.
|
38 |
+
The GNU General Public License permits making a modified version and
|
39 |
+
letting the public access it on a server without ever releasing its
|
40 |
+
source code to the public.
|
41 |
+
|
42 |
+
The GNU Affero General Public License is designed specifically to
|
43 |
+
ensure that, in such cases, the modified source code becomes available
|
44 |
+
to the community. It requires the operator of a network server to
|
45 |
+
provide the source code of the modified version running there to the
|
46 |
+
users of that server. Therefore, public use of a modified version, on
|
47 |
+
a publicly accessible server, gives the public access to the source
|
48 |
+
code of the modified version.
|
49 |
+
|
50 |
+
An older license, called the Affero General Public License and
|
51 |
+
published by Affero, was designed to accomplish similar goals. This is
|
52 |
+
a different license, not a version of the Affero GPL, but Affero has
|
53 |
+
released a new version of the Affero GPL which permits relicensing under
|
54 |
+
this license.
|
55 |
+
|
56 |
+
The precise terms and conditions for copying, distribution and
|
57 |
+
modification follow.
|
58 |
+
|
59 |
+
TERMS AND CONDITIONS
|
60 |
+
|
61 |
+
0. Definitions.
|
62 |
+
|
63 |
+
"This License" refers to version 3 of the GNU Affero General Public License.
|
64 |
+
|
65 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
66 |
+
works, such as semiconductor masks.
|
67 |
+
|
68 |
+
"The Program" refers to any copyrightable work licensed under this
|
69 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
70 |
+
"recipients" may be individuals or organizations.
|
71 |
+
|
72 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
73 |
+
in a fashion requiring copyright permission, other than the making of an
|
74 |
+
exact copy. The resulting work is called a "modified version" of the
|
75 |
+
earlier work or a work "based on" the earlier work.
|
76 |
+
|
77 |
+
A "covered work" means either the unmodified Program or a work based
|
78 |
+
on the Program.
|
79 |
+
|
80 |
+
To "propagate" a work means to do anything with it that, without
|
81 |
+
permission, would make you directly or secondarily liable for
|
82 |
+
infringement under applicable copyright law, except executing it on a
|
83 |
+
computer or modifying a private copy. Propagation includes copying,
|
84 |
+
distribution (with or without modification), making available to the
|
85 |
+
public, and in some countries other activities as well.
|
86 |
+
|
87 |
+
To "convey" a work means any kind of propagation that enables other
|
88 |
+
parties to make or receive copies. Mere interaction with a user through
|
89 |
+
a computer network, with no transfer of a copy, is not conveying.
|
90 |
+
|
91 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
92 |
+
to the extent that it includes a convenient and prominently visible
|
93 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
94 |
+
tells the user that there is no warranty for the work (except to the
|
95 |
+
extent that warranties are provided), that licensees may convey the
|
96 |
+
work under this License, and how to view a copy of this License. If
|
97 |
+
the interface presents a list of user commands or options, such as a
|
98 |
+
menu, a prominent item in the list meets this criterion.
|
99 |
+
|
100 |
+
1. Source Code.
|
101 |
+
|
102 |
+
The "source code" for a work means the preferred form of the work
|
103 |
+
for making modifications to it. "Object code" means any non-source
|
104 |
+
form of a work.
|
105 |
+
|
106 |
+
A "Standard Interface" means an interface that either is an official
|
107 |
+
standard defined by a recognized standards body, or, in the case of
|
108 |
+
interfaces specified for a particular programming language, one that
|
109 |
+
is widely used among developers working in that language.
|
110 |
+
|
111 |
+
The "System Libraries" of an executable work include anything, other
|
112 |
+
than the work as a whole, that (a) is included in the normal form of
|
113 |
+
packaging a Major Component, but which is not part of that Major
|
114 |
+
Component, and (b) serves only to enable use of the work with that
|
115 |
+
Major Component, or to implement a Standard Interface for which an
|
116 |
+
implementation is available to the public in source code form. A
|
117 |
+
"Major Component", in this context, means a major essential component
|
118 |
+
(kernel, window system, and so on) of the specific operating system
|
119 |
+
(if any) on which the executable work runs, or a compiler used to
|
120 |
+
produce the work, or an object code interpreter used to run it.
|
121 |
+
|
122 |
+
The "Corresponding Source" for a work in object code form means all
|
123 |
+
the source code needed to generate, install, and (for an executable
|
124 |
+
work) run the object code and to modify the work, including scripts to
|
125 |
+
control those activities. However, it does not include the work's
|
126 |
+
System Libraries, or general-purpose tools or generally available free
|
127 |
+
programs which are used unmodified in performing those activities but
|
128 |
+
which are not part of the work. For example, Corresponding Source
|
129 |
+
includes interface definition files associated with source files for
|
130 |
+
the work, and the source code for shared libraries and dynamically
|
131 |
+
linked subprograms that the work is specifically designed to require,
|
132 |
+
such as by intimate data communication or control flow between those
|
133 |
+
subprograms and other parts of the work.
|
134 |
+
|
135 |
+
The Corresponding Source need not include anything that users
|
136 |
+
can regenerate automatically from other parts of the Corresponding
|
137 |
+
Source.
|
138 |
+
|
139 |
+
The Corresponding Source for a work in source code form is that
|
140 |
+
same work.
|
141 |
+
|
142 |
+
2. Basic Permissions.
|
143 |
+
|
144 |
+
All rights granted under this License are granted for the term of
|
145 |
+
copyright on the Program, and are irrevocable provided the stated
|
146 |
+
conditions are met. This License explicitly affirms your unlimited
|
147 |
+
permission to run the unmodified Program. The output from running a
|
148 |
+
covered work is covered by this License only if the output, given its
|
149 |
+
content, constitutes a covered work. This License acknowledges your
|
150 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
151 |
+
|
152 |
+
You may make, run and propagate covered works that you do not
|
153 |
+
convey, without conditions so long as your license otherwise remains
|
154 |
+
in force. You may convey covered works to others for the sole purpose
|
155 |
+
of having them make modifications exclusively for you, or provide you
|
156 |
+
with facilities for running those works, provided that you comply with
|
157 |
+
the terms of this License in conveying all material for which you do
|
158 |
+
not control copyright. Those thus making or running the covered works
|
159 |
+
for you must do so exclusively on your behalf, under your direction
|
160 |
+
and control, on terms that prohibit them from making any copies of
|
161 |
+
your copyrighted material outside their relationship with you.
|
162 |
+
|
163 |
+
Conveying under any other circumstances is permitted solely under
|
164 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
165 |
+
makes it unnecessary.
|
166 |
+
|
167 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
168 |
+
|
169 |
+
No covered work shall be deemed part of an effective technological
|
170 |
+
measure under any applicable law fulfilling obligations under article
|
171 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
172 |
+
similar laws prohibiting or restricting circumvention of such
|
173 |
+
measures.
|
174 |
+
|
175 |
+
When you convey a covered work, you waive any legal power to forbid
|
176 |
+
circumvention of technological measures to the extent such circumvention
|
177 |
+
is effected by exercising rights under this License with respect to
|
178 |
+
the covered work, and you disclaim any intention to limit operation or
|
179 |
+
modification of the work as a means of enforcing, against the work's
|
180 |
+
users, your or third parties' legal rights to forbid circumvention of
|
181 |
+
technological measures.
|
182 |
+
|
183 |
+
4. Conveying Verbatim Copies.
|
184 |
+
|
185 |
+
You may convey verbatim copies of the Program's source code as you
|
186 |
+
receive it, in any medium, provided that you conspicuously and
|
187 |
+
appropriately publish on each copy an appropriate copyright notice;
|
188 |
+
keep intact all notices stating that this License and any
|
189 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
190 |
+
keep intact all notices of the absence of any warranty; and give all
|
191 |
+
recipients a copy of this License along with the Program.
|
192 |
+
|
193 |
+
You may charge any price or no price for each copy that you convey,
|
194 |
+
and you may offer support or warranty protection for a fee.
|
195 |
+
|
196 |
+
5. Conveying Modified Source Versions.
|
197 |
+
|
198 |
+
You may convey a work based on the Program, or the modifications to
|
199 |
+
produce it from the Program, in the form of source code under the
|
200 |
+
terms of section 4, provided that you also meet all of these conditions:
|
201 |
+
|
202 |
+
a) The work must carry prominent notices stating that you modified
|
203 |
+
it, and giving a relevant date.
|
204 |
+
|
205 |
+
b) The work must carry prominent notices stating that it is
|
206 |
+
released under this License and any conditions added under section
|
207 |
+
7. This requirement modifies the requirement in section 4 to
|
208 |
+
"keep intact all notices".
|
209 |
+
|
210 |
+
c) You must license the entire work, as a whole, under this
|
211 |
+
License to anyone who comes into possession of a copy. This
|
212 |
+
License will therefore apply, along with any applicable section 7
|
213 |
+
additional terms, to the whole of the work, and all its parts,
|
214 |
+
regardless of how they are packaged. This License gives no
|
215 |
+
permission to license the work in any other way, but it does not
|
216 |
+
invalidate such permission if you have separately received it.
|
217 |
+
|
218 |
+
d) If the work has interactive user interfaces, each must display
|
219 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
220 |
+
interfaces that do not display Appropriate Legal Notices, your
|
221 |
+
work need not make them do so.
|
222 |
+
|
223 |
+
A compilation of a covered work with other separate and independent
|
224 |
+
works, which are not by their nature extensions of the covered work,
|
225 |
+
and which are not combined with it such as to form a larger program,
|
226 |
+
in or on a volume of a storage or distribution medium, is called an
|
227 |
+
"aggregate" if the compilation and its resulting copyright are not
|
228 |
+
used to limit the access or legal rights of the compilation's users
|
229 |
+
beyond what the individual works permit. Inclusion of a covered work
|
230 |
+
in an aggregate does not cause this License to apply to the other
|
231 |
+
parts of the aggregate.
|
232 |
+
|
233 |
+
6. Conveying Non-Source Forms.
|
234 |
+
|
235 |
+
You may convey a covered work in object code form under the terms
|
236 |
+
of sections 4 and 5, provided that you also convey the
|
237 |
+
machine-readable Corresponding Source under the terms of this License,
|
238 |
+
in one of these ways:
|
239 |
+
|
240 |
+
a) Convey the object code in, or embodied in, a physical product
|
241 |
+
(including a physical distribution medium), accompanied by the
|
242 |
+
Corresponding Source fixed on a durable physical medium
|
243 |
+
customarily used for software interchange.
|
244 |
+
|
245 |
+
b) Convey the object code in, or embodied in, a physical product
|
246 |
+
(including a physical distribution medium), accompanied by a
|
247 |
+
written offer, valid for at least three years and valid for as
|
248 |
+
long as you offer spare parts or customer support for that product
|
249 |
+
model, to give anyone who possesses the object code either (1) a
|
250 |
+
copy of the Corresponding Source for all the software in the
|
251 |
+
product that is covered by this License, on a durable physical
|
252 |
+
medium customarily used for software interchange, for a price no
|
253 |
+
more than your reasonable cost of physically performing this
|
254 |
+
conveying of source, or (2) access to copy the
|
255 |
+
Corresponding Source from a network server at no charge.
|
256 |
+
|
257 |
+
c) Convey individual copies of the object code with a copy of the
|
258 |
+
written offer to provide the Corresponding Source. This
|
259 |
+
alternative is allowed only occasionally and noncommercially, and
|
260 |
+
only if you received the object code with such an offer, in accord
|
261 |
+
with subsection 6b.
|
262 |
+
|
263 |
+
d) Convey the object code by offering access from a designated
|
264 |
+
place (gratis or for a charge), and offer equivalent access to the
|
265 |
+
Corresponding Source in the same way through the same place at no
|
266 |
+
further charge. You need not require recipients to copy the
|
267 |
+
Corresponding Source along with the object code. If the place to
|
268 |
+
copy the object code is a network server, the Corresponding Source
|
269 |
+
may be on a different server (operated by you or a third party)
|
270 |
+
that supports equivalent copying facilities, provided you maintain
|
271 |
+
clear directions next to the object code saying where to find the
|
272 |
+
Corresponding Source. Regardless of what server hosts the
|
273 |
+
Corresponding Source, you remain obligated to ensure that it is
|
274 |
+
available for as long as needed to satisfy these requirements.
|
275 |
+
|
276 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
277 |
+
you inform other peers where the object code and Corresponding
|
278 |
+
Source of the work are being offered to the general public at no
|
279 |
+
charge under subsection 6d.
|
280 |
+
|
281 |
+
A separable portion of the object code, whose source code is excluded
|
282 |
+
from the Corresponding Source as a System Library, need not be
|
283 |
+
included in conveying the object code work.
|
284 |
+
|
285 |
+
A "User Product" is either (1) a "consumer product", which means any
|
286 |
+
tangible personal property which is normally used for personal, family,
|
287 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
288 |
+
into a dwelling. In determining whether a product is a consumer product,
|
289 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
290 |
+
product received by a particular user, "normally used" refers to a
|
291 |
+
typical or common use of that class of product, regardless of the status
|
292 |
+
of the particular user or of the way in which the particular user
|
293 |
+
actually uses, or expects or is expected to use, the product. A product
|
294 |
+
is a consumer product regardless of whether the product has substantial
|
295 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
296 |
+
the only significant mode of use of the product.
|
297 |
+
|
298 |
+
"Installation Information" for a User Product means any methods,
|
299 |
+
procedures, authorization keys, or other information required to install
|
300 |
+
and execute modified versions of a covered work in that User Product from
|
301 |
+
a modified version of its Corresponding Source. The information must
|
302 |
+
suffice to ensure that the continued functioning of the modified object
|
303 |
+
code is in no case prevented or interfered with solely because
|
304 |
+
modification has been made.
|
305 |
+
|
306 |
+
If you convey an object code work under this section in, or with, or
|
307 |
+
specifically for use in, a User Product, and the conveying occurs as
|
308 |
+
part of a transaction in which the right of possession and use of the
|
309 |
+
User Product is transferred to the recipient in perpetuity or for a
|
310 |
+
fixed term (regardless of how the transaction is characterized), the
|
311 |
+
Corresponding Source conveyed under this section must be accompanied
|
312 |
+
by the Installation Information. But this requirement does not apply
|
313 |
+
if neither you nor any third party retains the ability to install
|
314 |
+
modified object code on the User Product (for example, the work has
|
315 |
+
been installed in ROM).
|
316 |
+
|
317 |
+
The requirement to provide Installation Information does not include a
|
318 |
+
requirement to continue to provide support service, warranty, or updates
|
319 |
+
for a work that has been modified or installed by the recipient, or for
|
320 |
+
the User Product in which it has been modified or installed. Access to a
|
321 |
+
network may be denied when the modification itself materially and
|
322 |
+
adversely affects the operation of the network or violates the rules and
|
323 |
+
protocols for communication across the network.
|
324 |
+
|
325 |
+
Corresponding Source conveyed, and Installation Information provided,
|
326 |
+
in accord with this section must be in a format that is publicly
|
327 |
+
documented (and with an implementation available to the public in
|
328 |
+
source code form), and must require no special password or key for
|
329 |
+
unpacking, reading or copying.
|
330 |
+
|
331 |
+
7. Additional Terms.
|
332 |
+
|
333 |
+
"Additional permissions" are terms that supplement the terms of this
|
334 |
+
License by making exceptions from one or more of its conditions.
|
335 |
+
Additional permissions that are applicable to the entire Program shall
|
336 |
+
be treated as though they were included in this License, to the extent
|
337 |
+
that they are valid under applicable law. If additional permissions
|
338 |
+
apply only to part of the Program, that part may be used separately
|
339 |
+
under those permissions, but the entire Program remains governed by
|
340 |
+
this License without regard to the additional permissions.
|
341 |
+
|
342 |
+
When you convey a copy of a covered work, you may at your option
|
343 |
+
remove any additional permissions from that copy, or from any part of
|
344 |
+
it. (Additional permissions may be written to require their own
|
345 |
+
removal in certain cases when you modify the work.) You may place
|
346 |
+
additional permissions on material, added by you to a covered work,
|
347 |
+
for which you have or can give appropriate copyright permission.
|
348 |
+
|
349 |
+
Notwithstanding any other provision of this License, for material you
|
350 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
351 |
+
that material) supplement the terms of this License with terms:
|
352 |
+
|
353 |
+
a) Disclaiming warranty or limiting liability differently from the
|
354 |
+
terms of sections 15 and 16 of this License; or
|
355 |
+
|
356 |
+
b) Requiring preservation of specified reasonable legal notices or
|
357 |
+
author attributions in that material or in the Appropriate Legal
|
358 |
+
Notices displayed by works containing it; or
|
359 |
+
|
360 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
361 |
+
requiring that modified versions of such material be marked in
|
362 |
+
reasonable ways as different from the original version; or
|
363 |
+
|
364 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
365 |
+
authors of the material; or
|
366 |
+
|
367 |
+
e) Declining to grant rights under trademark law for use of some
|
368 |
+
trade names, trademarks, or service marks; or
|
369 |
+
|
370 |
+
f) Requiring indemnification of licensors and authors of that
|
371 |
+
material by anyone who conveys the material (or modified versions of
|
372 |
+
it) with contractual assumptions of liability to the recipient, for
|
373 |
+
any liability that these contractual assumptions directly impose on
|
374 |
+
those licensors and authors.
|
375 |
+
|
376 |
+
All other non-permissive additional terms are considered "further
|
377 |
+
restrictions" within the meaning of section 10. If the Program as you
|
378 |
+
received it, or any part of it, contains a notice stating that it is
|
379 |
+
governed by this License along with a term that is a further
|
380 |
+
restriction, you may remove that term. If a license document contains
|
381 |
+
a further restriction but permits relicensing or conveying under this
|
382 |
+
License, you may add to a covered work material governed by the terms
|
383 |
+
of that license document, provided that the further restriction does
|
384 |
+
not survive such relicensing or conveying.
|
385 |
+
|
386 |
+
If you add terms to a covered work in accord with this section, you
|
387 |
+
must place, in the relevant source files, a statement of the
|
388 |
+
additional terms that apply to those files, or a notice indicating
|
389 |
+
where to find the applicable terms.
|
390 |
+
|
391 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
392 |
+
form of a separately written license, or stated as exceptions;
|
393 |
+
the above requirements apply either way.
|
394 |
+
|
395 |
+
8. Termination.
|
396 |
+
|
397 |
+
You may not propagate or modify a covered work except as expressly
|
398 |
+
provided under this License. Any attempt otherwise to propagate or
|
399 |
+
modify it is void, and will automatically terminate your rights under
|
400 |
+
this License (including any patent licenses granted under the third
|
401 |
+
paragraph of section 11).
|
402 |
+
|
403 |
+
However, if you cease all violation of this License, then your
|
404 |
+
license from a particular copyright holder is reinstated (a)
|
405 |
+
provisionally, unless and until the copyright holder explicitly and
|
406 |
+
finally terminates your license, and (b) permanently, if the copyright
|
407 |
+
holder fails to notify you of the violation by some reasonable means
|
408 |
+
prior to 60 days after the cessation.
|
409 |
+
|
410 |
+
Moreover, your license from a particular copyright holder is
|
411 |
+
reinstated permanently if the copyright holder notifies you of the
|
412 |
+
violation by some reasonable means, this is the first time you have
|
413 |
+
received notice of violation of this License (for any work) from that
|
414 |
+
copyright holder, and you cure the violation prior to 30 days after
|
415 |
+
your receipt of the notice.
|
416 |
+
|
417 |
+
Termination of your rights under this section does not terminate the
|
418 |
+
licenses of parties who have received copies or rights from you under
|
419 |
+
this License. If your rights have been terminated and not permanently
|
420 |
+
reinstated, you do not qualify to receive new licenses for the same
|
421 |
+
material under section 10.
|
422 |
+
|
423 |
+
9. Acceptance Not Required for Having Copies.
|
424 |
+
|
425 |
+
You are not required to accept this License in order to receive or
|
426 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
427 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
428 |
+
to receive a copy likewise does not require acceptance. However,
|
429 |
+
nothing other than this License grants you permission to propagate or
|
430 |
+
modify any covered work. These actions infringe copyright if you do
|
431 |
+
not accept this License. Therefore, by modifying or propagating a
|
432 |
+
covered work, you indicate your acceptance of this License to do so.
|
433 |
+
|
434 |
+
10. Automatic Licensing of Downstream Recipients.
|
435 |
+
|
436 |
+
Each time you convey a covered work, the recipient automatically
|
437 |
+
receives a license from the original licensors, to run, modify and
|
438 |
+
propagate that work, subject to this License. You are not responsible
|
439 |
+
for enforcing compliance by third parties with this License.
|
440 |
+
|
441 |
+
An "entity transaction" is a transaction transferring control of an
|
442 |
+
organization, or substantially all assets of one, or subdividing an
|
443 |
+
organization, or merging organizations. If propagation of a covered
|
444 |
+
work results from an entity transaction, each party to that
|
445 |
+
transaction who receives a copy of the work also receives whatever
|
446 |
+
licenses to the work the party's predecessor in interest had or could
|
447 |
+
give under the previous paragraph, plus a right to possession of the
|
448 |
+
Corresponding Source of the work from the predecessor in interest, if
|
449 |
+
the predecessor has it or can get it with reasonable efforts.
|
450 |
+
|
451 |
+
You may not impose any further restrictions on the exercise of the
|
452 |
+
rights granted or affirmed under this License. For example, you may
|
453 |
+
not impose a license fee, royalty, or other charge for exercise of
|
454 |
+
rights granted under this License, and you may not initiate litigation
|
455 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
456 |
+
any patent claim is infringed by making, using, selling, offering for
|
457 |
+
sale, or importing the Program or any portion of it.
|
458 |
+
|
459 |
+
11. Patents.
|
460 |
+
|
461 |
+
A "contributor" is a copyright holder who authorizes use under this
|
462 |
+
License of the Program or a work on which the Program is based. The
|
463 |
+
work thus licensed is called the contributor's "contributor version".
|
464 |
+
|
465 |
+
A contributor's "essential patent claims" are all patent claims
|
466 |
+
owned or controlled by the contributor, whether already acquired or
|
467 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
468 |
+
by this License, of making, using, or selling its contributor version,
|
469 |
+
but do not include claims that would be infringed only as a
|
470 |
+
consequence of further modification of the contributor version. For
|
471 |
+
purposes of this definition, "control" includes the right to grant
|
472 |
+
patent sublicenses in a manner consistent with the requirements of
|
473 |
+
this License.
|
474 |
+
|
475 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
476 |
+
patent license under the contributor's essential patent claims, to
|
477 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
478 |
+
propagate the contents of its contributor version.
|
479 |
+
|
480 |
+
In the following three paragraphs, a "patent license" is any express
|
481 |
+
agreement or commitment, however denominated, not to enforce a patent
|
482 |
+
(such as an express permission to practice a patent or covenant not to
|
483 |
+
sue for patent infringement). To "grant" such a patent license to a
|
484 |
+
party means to make such an agreement or commitment not to enforce a
|
485 |
+
patent against the party.
|
486 |
+
|
487 |
+
If you convey a covered work, knowingly relying on a patent license,
|
488 |
+
and the Corresponding Source of the work is not available for anyone
|
489 |
+
to copy, free of charge and under the terms of this License, through a
|
490 |
+
publicly available network server or other readily accessible means,
|
491 |
+
then you must either (1) cause the Corresponding Source to be so
|
492 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
493 |
+
patent license for this particular work, or (3) arrange, in a manner
|
494 |
+
consistent with the requirements of this License, to extend the patent
|
495 |
+
license to downstream recipients. "Knowingly relying" means you have
|
496 |
+
actual knowledge that, but for the patent license, your conveying the
|
497 |
+
covered work in a country, or your recipient's use of the covered work
|
498 |
+
in a country, would infringe one or more identifiable patents in that
|
499 |
+
country that you have reason to believe are valid.
|
500 |
+
|
501 |
+
If, pursuant to or in connection with a single transaction or
|
502 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
503 |
+
covered work, and grant a patent license to some of the parties
|
504 |
+
receiving the covered work authorizing them to use, propagate, modify
|
505 |
+
or convey a specific copy of the covered work, then the patent license
|
506 |
+
you grant is automatically extended to all recipients of the covered
|
507 |
+
work and works based on it.
|
508 |
+
|
509 |
+
A patent license is "discriminatory" if it does not include within
|
510 |
+
the scope of its coverage, prohibits the exercise of, or is
|
511 |
+
conditioned on the non-exercise of one or more of the rights that are
|
512 |
+
specifically granted under this License. You may not convey a covered
|
513 |
+
work if you are a party to an arrangement with a third party that is
|
514 |
+
in the business of distributing software, under which you make payment
|
515 |
+
to the third party based on the extent of your activity of conveying
|
516 |
+
the work, and under which the third party grants, to any of the
|
517 |
+
parties who would receive the covered work from you, a discriminatory
|
518 |
+
patent license (a) in connection with copies of the covered work
|
519 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
520 |
+
for and in connection with specific products or compilations that
|
521 |
+
contain the covered work, unless you entered into that arrangement,
|
522 |
+
or that patent license was granted, prior to 28 March 2007.
|
523 |
+
|
524 |
+
Nothing in this License shall be construed as excluding or limiting
|
525 |
+
any implied license or other defenses to infringement that may
|
526 |
+
otherwise be available to you under applicable patent law.
|
527 |
+
|
528 |
+
12. No Surrender of Others' Freedom.
|
529 |
+
|
530 |
+
If conditions are imposed on you (whether by court order, agreement or
|
531 |
+
otherwise) that contradict the conditions of this License, they do not
|
532 |
+
excuse you from the conditions of this License. If you cannot convey a
|
533 |
+
covered work so as to satisfy simultaneously your obligations under this
|
534 |
+
License and any other pertinent obligations, then as a consequence you may
|
535 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
536 |
+
to collect a royalty for further conveying from those to whom you convey
|
537 |
+
the Program, the only way you could satisfy both those terms and this
|
538 |
+
License would be to refrain entirely from conveying the Program.
|
539 |
+
|
540 |
+
13. Remote Network Interaction; Use with the GNU General Public License.
|
541 |
+
|
542 |
+
Notwithstanding any other provision of this License, if you modify the
|
543 |
+
Program, your modified version must prominently offer all users
|
544 |
+
interacting with it remotely through a computer network (if your version
|
545 |
+
supports such interaction) an opportunity to receive the Corresponding
|
546 |
+
Source of your version by providing access to the Corresponding Source
|
547 |
+
from a network server at no charge, through some standard or customary
|
548 |
+
means of facilitating copying of software. This Corresponding Source
|
549 |
+
shall include the Corresponding Source for any work covered by version 3
|
550 |
+
of the GNU General Public License that is incorporated pursuant to the
|
551 |
+
following paragraph.
|
552 |
+
|
553 |
+
Notwithstanding any other provision of this License, you have
|
554 |
+
permission to link or combine any covered work with a work licensed
|
555 |
+
under version 3 of the GNU General Public License into a single
|
556 |
+
combined work, and to convey the resulting work. The terms of this
|
557 |
+
License will continue to apply to the part which is the covered work,
|
558 |
+
but the work with which it is combined will remain governed by version
|
559 |
+
3 of the GNU General Public License.
|
560 |
+
|
561 |
+
14. Revised Versions of this License.
|
562 |
+
|
563 |
+
The Free Software Foundation may publish revised and/or new versions of
|
564 |
+
the GNU Affero General Public License from time to time. Such new versions
|
565 |
+
will be similar in spirit to the present version, but may differ in detail to
|
566 |
+
address new problems or concerns.
|
567 |
+
|
568 |
+
Each version is given a distinguishing version number. If the
|
569 |
+
Program specifies that a certain numbered version of the GNU Affero General
|
570 |
+
Public License "or any later version" applies to it, you have the
|
571 |
+
option of following the terms and conditions either of that numbered
|
572 |
+
version or of any later version published by the Free Software
|
573 |
+
Foundation. If the Program does not specify a version number of the
|
574 |
+
GNU Affero General Public License, you may choose any version ever published
|
575 |
+
by the Free Software Foundation.
|
576 |
+
|
577 |
+
If the Program specifies that a proxy can decide which future
|
578 |
+
versions of the GNU Affero General Public License can be used, that proxy's
|
579 |
+
public statement of acceptance of a version permanently authorizes you
|
580 |
+
to choose that version for the Program.
|
581 |
+
|
582 |
+
Later license versions may give you additional or different
|
583 |
+
permissions. However, no additional obligations are imposed on any
|
584 |
+
author or copyright holder as a result of your choosing to follow a
|
585 |
+
later version.
|
586 |
+
|
587 |
+
15. Disclaimer of Warranty.
|
588 |
+
|
589 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
590 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
591 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
592 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
593 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
594 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
595 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
596 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
597 |
+
|
598 |
+
16. Limitation of Liability.
|
599 |
+
|
600 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
601 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
602 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
603 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
604 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
605 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
606 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
607 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
608 |
+
SUCH DAMAGES.
|
609 |
+
|
610 |
+
17. Interpretation of Sections 15 and 16.
|
611 |
+
|
612 |
+
If the disclaimer of warranty and limitation of liability provided
|
613 |
+
above cannot be given local legal effect according to their terms,
|
614 |
+
reviewing courts shall apply local law that most closely approximates
|
615 |
+
an absolute waiver of all civil liability in connection with the
|
616 |
+
Program, unless a warranty or assumption of liability accompanies a
|
617 |
+
copy of the Program in return for a fee.
|
618 |
+
|
619 |
+
END OF TERMS AND CONDITIONS
|
620 |
+
|
621 |
+
How to Apply These Terms to Your New Programs
|
622 |
+
|
623 |
+
If you develop a new program, and you want it to be of the greatest
|
624 |
+
possible use to the public, the best way to achieve this is to make it
|
625 |
+
free software which everyone can redistribute and change under these terms.
|
626 |
+
|
627 |
+
To do so, attach the following notices to the program. It is safest
|
628 |
+
to attach them to the start of each source file to most effectively
|
629 |
+
state the exclusion of warranty; and each file should have at least
|
630 |
+
the "copyright" line and a pointer to where the full notice is found.
|
631 |
+
|
632 |
+
<one line to give the program's name and a brief idea of what it does.>
|
633 |
+
Copyright (C) <year> <name of author>
|
634 |
+
|
635 |
+
This program is free software: you can redistribute it and/or modify
|
636 |
+
it under the terms of the GNU Affero General Public License as published
|
637 |
+
by the Free Software Foundation, either version 3 of the License, or
|
638 |
+
(at your option) any later version.
|
639 |
+
|
640 |
+
This program is distributed in the hope that it will be useful,
|
641 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
642 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
643 |
+
GNU Affero General Public License for more details.
|
644 |
+
|
645 |
+
You should have received a copy of the GNU Affero General Public License
|
646 |
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
647 |
+
|
648 |
+
Also add information on how to contact you by electronic and paper mail.
|
649 |
+
|
650 |
+
If your software can interact with users remotely through a computer
|
651 |
+
network, you should also make sure that it provides a way for users to
|
652 |
+
get its source. For example, if your program is a web application, its
|
653 |
+
interface could display a "Source" link that leads users to an archive
|
654 |
+
of the code. There are many ways you could offer source, and different
|
655 |
+
solutions will be better for different programs; see section 13 for the
|
656 |
+
specific requirements.
|
657 |
+
|
658 |
+
You should also get your employer (if you work as a programmer) or school,
|
659 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
660 |
+
For more information on this, and how to apply and follow the GNU AGPL, see
|
661 |
+
<https://www.gnu.org/licenses/>.
|
app.py
ADDED
@@ -0,0 +1,560 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# flake8: noqa: E402
|
2 |
+
import os
|
3 |
+
import logging
|
4 |
+
import re_matching
|
5 |
+
from tools.sentence import split_by_language
|
6 |
+
|
7 |
+
logging.getLogger("numba").setLevel(logging.WARNING)
|
8 |
+
logging.getLogger("markdown_it").setLevel(logging.WARNING)
|
9 |
+
logging.getLogger("urllib3").setLevel(logging.WARNING)
|
10 |
+
logging.getLogger("matplotlib").setLevel(logging.WARNING)
|
11 |
+
|
12 |
+
logging.basicConfig(
|
13 |
+
level=logging.INFO, format="| %(name)s | %(levelname)s | %(message)s"
|
14 |
+
)
|
15 |
+
|
16 |
+
logger = logging.getLogger(__name__)
|
17 |
+
|
18 |
+
import torch
|
19 |
+
import utils
|
20 |
+
from infer import infer, latest_version, get_net_g, infer_multilang
|
21 |
+
import gradio as gr
|
22 |
+
import webbrowser
|
23 |
+
import numpy as np
|
24 |
+
from config import config
|
25 |
+
from tools.translate import translate
|
26 |
+
import librosa
|
27 |
+
|
28 |
+
net_g = None
|
29 |
+
|
30 |
+
device = config.webui_config.device
|
31 |
+
if device == "mps":
|
32 |
+
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
|
33 |
+
|
34 |
+
|
35 |
+
def generate_audio(
|
36 |
+
slices,
|
37 |
+
sdp_ratio,
|
38 |
+
noise_scale,
|
39 |
+
noise_scale_w,
|
40 |
+
length_scale,
|
41 |
+
speaker,
|
42 |
+
language,
|
43 |
+
reference_audio,
|
44 |
+
emotion,
|
45 |
+
style_text,
|
46 |
+
style_weight,
|
47 |
+
skip_start=False,
|
48 |
+
skip_end=False,
|
49 |
+
):
|
50 |
+
audio_list = []
|
51 |
+
# silence = np.zeros(hps.data.sampling_rate // 2, dtype=np.int16)
|
52 |
+
with torch.no_grad():
|
53 |
+
for idx, piece in enumerate(slices):
|
54 |
+
skip_start = idx != 0
|
55 |
+
skip_end = idx != len(slices) - 1
|
56 |
+
audio = infer(
|
57 |
+
piece,
|
58 |
+
reference_audio=reference_audio,
|
59 |
+
emotion=emotion,
|
60 |
+
sdp_ratio=sdp_ratio,
|
61 |
+
noise_scale=noise_scale,
|
62 |
+
noise_scale_w=noise_scale_w,
|
63 |
+
length_scale=length_scale,
|
64 |
+
sid=speaker,
|
65 |
+
language=language,
|
66 |
+
hps=hps,
|
67 |
+
net_g=net_g,
|
68 |
+
device=device,
|
69 |
+
skip_start=skip_start,
|
70 |
+
skip_end=skip_end,
|
71 |
+
style_text=style_text,
|
72 |
+
style_weight=style_weight,
|
73 |
+
)
|
74 |
+
audio16bit = gr.processing_utils.convert_to_16_bit_wav(audio)
|
75 |
+
audio_list.append(audio16bit)
|
76 |
+
return audio_list
|
77 |
+
|
78 |
+
|
79 |
+
def generate_audio_multilang(
|
80 |
+
slices,
|
81 |
+
sdp_ratio,
|
82 |
+
noise_scale,
|
83 |
+
noise_scale_w,
|
84 |
+
length_scale,
|
85 |
+
speaker,
|
86 |
+
language,
|
87 |
+
reference_audio,
|
88 |
+
emotion,
|
89 |
+
skip_start=False,
|
90 |
+
skip_end=False,
|
91 |
+
):
|
92 |
+
audio_list = []
|
93 |
+
# silence = np.zeros(hps.data.sampling_rate // 2, dtype=np.int16)
|
94 |
+
with torch.no_grad():
|
95 |
+
for idx, piece in enumerate(slices):
|
96 |
+
skip_start = idx != 0
|
97 |
+
skip_end = idx != len(slices) - 1
|
98 |
+
audio = infer_multilang(
|
99 |
+
piece,
|
100 |
+
reference_audio=reference_audio,
|
101 |
+
emotion=emotion,
|
102 |
+
sdp_ratio=sdp_ratio,
|
103 |
+
noise_scale=noise_scale,
|
104 |
+
noise_scale_w=noise_scale_w,
|
105 |
+
length_scale=length_scale,
|
106 |
+
sid=speaker,
|
107 |
+
language=language[idx],
|
108 |
+
hps=hps,
|
109 |
+
net_g=net_g,
|
110 |
+
device=device,
|
111 |
+
skip_start=skip_start,
|
112 |
+
skip_end=skip_end,
|
113 |
+
)
|
114 |
+
audio16bit = gr.processing_utils.convert_to_16_bit_wav(audio)
|
115 |
+
audio_list.append(audio16bit)
|
116 |
+
return audio_list
|
117 |
+
|
118 |
+
|
119 |
+
def tts_split(
|
120 |
+
text: str,
|
121 |
+
speaker,
|
122 |
+
sdp_ratio,
|
123 |
+
noise_scale,
|
124 |
+
noise_scale_w,
|
125 |
+
length_scale,
|
126 |
+
language,
|
127 |
+
cut_by_sent,
|
128 |
+
interval_between_para,
|
129 |
+
interval_between_sent,
|
130 |
+
reference_audio,
|
131 |
+
emotion,
|
132 |
+
style_text,
|
133 |
+
style_weight,
|
134 |
+
):
|
135 |
+
while text.find("\n\n") != -1:
|
136 |
+
text = text.replace("\n\n", "\n")
|
137 |
+
text = text.replace("|", "")
|
138 |
+
para_list = re_matching.cut_para(text)
|
139 |
+
para_list = [p for p in para_list if p != ""]
|
140 |
+
audio_list = []
|
141 |
+
for p in para_list:
|
142 |
+
if not cut_by_sent:
|
143 |
+
audio_list += process_text(
|
144 |
+
p,
|
145 |
+
speaker,
|
146 |
+
sdp_ratio,
|
147 |
+
noise_scale,
|
148 |
+
noise_scale_w,
|
149 |
+
length_scale,
|
150 |
+
language,
|
151 |
+
reference_audio,
|
152 |
+
emotion,
|
153 |
+
style_text,
|
154 |
+
style_weight,
|
155 |
+
)
|
156 |
+
silence = np.zeros((int)(44100 * interval_between_para), dtype=np.int16)
|
157 |
+
audio_list.append(silence)
|
158 |
+
else:
|
159 |
+
audio_list_sent = []
|
160 |
+
sent_list = re_matching.cut_sent(p)
|
161 |
+
sent_list = [s for s in sent_list if s != ""]
|
162 |
+
for s in sent_list:
|
163 |
+
audio_list_sent += process_text(
|
164 |
+
s,
|
165 |
+
speaker,
|
166 |
+
sdp_ratio,
|
167 |
+
noise_scale,
|
168 |
+
noise_scale_w,
|
169 |
+
length_scale,
|
170 |
+
language,
|
171 |
+
reference_audio,
|
172 |
+
emotion,
|
173 |
+
style_text,
|
174 |
+
style_weight,
|
175 |
+
)
|
176 |
+
silence = np.zeros((int)(44100 * interval_between_sent))
|
177 |
+
audio_list_sent.append(silence)
|
178 |
+
if (interval_between_para - interval_between_sent) > 0:
|
179 |
+
silence = np.zeros(
|
180 |
+
(int)(44100 * (interval_between_para - interval_between_sent))
|
181 |
+
)
|
182 |
+
audio_list_sent.append(silence)
|
183 |
+
audio16bit = gr.processing_utils.convert_to_16_bit_wav(
|
184 |
+
np.concatenate(audio_list_sent)
|
185 |
+
) # 对完整句子做音量归一
|
186 |
+
audio_list.append(audio16bit)
|
187 |
+
audio_concat = np.concatenate(audio_list)
|
188 |
+
return ("Success", (hps.data.sampling_rate, audio_concat))
|
189 |
+
|
190 |
+
|
191 |
+
def process_mix(slice):
|
192 |
+
_speaker = slice.pop()
|
193 |
+
_text, _lang = [], []
|
194 |
+
for lang, content in slice:
|
195 |
+
content = content.split("|")
|
196 |
+
content = [part for part in content if part != ""]
|
197 |
+
if len(content) == 0:
|
198 |
+
continue
|
199 |
+
if len(_text) == 0:
|
200 |
+
_text = [[part] for part in content]
|
201 |
+
_lang = [[lang] for part in content]
|
202 |
+
else:
|
203 |
+
_text[-1].append(content[0])
|
204 |
+
_lang[-1].append(lang)
|
205 |
+
if len(content) > 1:
|
206 |
+
_text += [[part] for part in content[1:]]
|
207 |
+
_lang += [[lang] for part in content[1:]]
|
208 |
+
return _text, _lang, _speaker
|
209 |
+
|
210 |
+
|
211 |
+
def process_auto(text):
|
212 |
+
_text, _lang = [], []
|
213 |
+
for slice in text.split("|"):
|
214 |
+
if slice == "":
|
215 |
+
continue
|
216 |
+
temp_text, temp_lang = [], []
|
217 |
+
sentences_list = split_by_language(slice, target_languages=["zh", "ja", "en"])
|
218 |
+
for sentence, lang in sentences_list:
|
219 |
+
if sentence == "":
|
220 |
+
continue
|
221 |
+
temp_text.append(sentence)
|
222 |
+
temp_lang.append(lang.upper())
|
223 |
+
_text.append(temp_text)
|
224 |
+
_lang.append(temp_lang)
|
225 |
+
return _text, _lang
|
226 |
+
|
227 |
+
|
228 |
+
def process_text(
|
229 |
+
text: str,
|
230 |
+
speaker,
|
231 |
+
sdp_ratio,
|
232 |
+
noise_scale,
|
233 |
+
noise_scale_w,
|
234 |
+
length_scale,
|
235 |
+
language,
|
236 |
+
reference_audio,
|
237 |
+
emotion,
|
238 |
+
style_text=None,
|
239 |
+
style_weight=0,
|
240 |
+
):
|
241 |
+
audio_list = []
|
242 |
+
if language == "mix":
|
243 |
+
bool_valid, str_valid = re_matching.validate_text(text)
|
244 |
+
if not bool_valid:
|
245 |
+
return str_valid, (
|
246 |
+
hps.data.sampling_rate,
|
247 |
+
np.concatenate([np.zeros(hps.data.sampling_rate // 2)]),
|
248 |
+
)
|
249 |
+
for slice in re_matching.text_matching(text):
|
250 |
+
_text, _lang, _speaker = process_mix(slice)
|
251 |
+
if _speaker is None:
|
252 |
+
continue
|
253 |
+
print(f"Text: {_text}\nLang: {_lang}")
|
254 |
+
audio_list.extend(
|
255 |
+
generate_audio_multilang(
|
256 |
+
_text,
|
257 |
+
sdp_ratio,
|
258 |
+
noise_scale,
|
259 |
+
noise_scale_w,
|
260 |
+
length_scale,
|
261 |
+
_speaker,
|
262 |
+
_lang,
|
263 |
+
reference_audio,
|
264 |
+
emotion,
|
265 |
+
)
|
266 |
+
)
|
267 |
+
elif language.lower() == "auto":
|
268 |
+
_text, _lang = process_auto(text)
|
269 |
+
print(f"Text: {_text}\nLang: {_lang}")
|
270 |
+
audio_list.extend(
|
271 |
+
generate_audio_multilang(
|
272 |
+
_text,
|
273 |
+
sdp_ratio,
|
274 |
+
noise_scale,
|
275 |
+
noise_scale_w,
|
276 |
+
length_scale,
|
277 |
+
speaker,
|
278 |
+
_lang,
|
279 |
+
reference_audio,
|
280 |
+
emotion,
|
281 |
+
)
|
282 |
+
)
|
283 |
+
else:
|
284 |
+
audio_list.extend(
|
285 |
+
generate_audio(
|
286 |
+
text.split("|"),
|
287 |
+
sdp_ratio,
|
288 |
+
noise_scale,
|
289 |
+
noise_scale_w,
|
290 |
+
length_scale,
|
291 |
+
speaker,
|
292 |
+
language,
|
293 |
+
reference_audio,
|
294 |
+
emotion,
|
295 |
+
style_text,
|
296 |
+
style_weight,
|
297 |
+
)
|
298 |
+
)
|
299 |
+
return audio_list
|
300 |
+
|
301 |
+
|
302 |
+
def tts_fn(
|
303 |
+
text: str,
|
304 |
+
speaker,
|
305 |
+
sdp_ratio,
|
306 |
+
noise_scale,
|
307 |
+
noise_scale_w,
|
308 |
+
length_scale,
|
309 |
+
language,
|
310 |
+
reference_audio,
|
311 |
+
emotion,
|
312 |
+
prompt_mode,
|
313 |
+
style_text=None,
|
314 |
+
style_weight=0,
|
315 |
+
):
|
316 |
+
if style_text == "":
|
317 |
+
style_text = None
|
318 |
+
if prompt_mode == "Audio prompt":
|
319 |
+
if reference_audio == None:
|
320 |
+
return ("Invalid audio prompt", None)
|
321 |
+
else:
|
322 |
+
reference_audio = load_audio(reference_audio)[1]
|
323 |
+
else:
|
324 |
+
reference_audio = None
|
325 |
+
|
326 |
+
audio_list = process_text(
|
327 |
+
text,
|
328 |
+
speaker,
|
329 |
+
sdp_ratio,
|
330 |
+
noise_scale,
|
331 |
+
noise_scale_w,
|
332 |
+
length_scale,
|
333 |
+
language,
|
334 |
+
reference_audio,
|
335 |
+
emotion,
|
336 |
+
style_text,
|
337 |
+
style_weight,
|
338 |
+
)
|
339 |
+
|
340 |
+
audio_concat = np.concatenate(audio_list)
|
341 |
+
return "Success", (hps.data.sampling_rate, audio_concat)
|
342 |
+
|
343 |
+
|
344 |
+
def format_utils(text, speaker):
|
345 |
+
_text, _lang = process_auto(text)
|
346 |
+
res = f"[{speaker}]"
|
347 |
+
for lang_s, content_s in zip(_lang, _text):
|
348 |
+
for lang, content in zip(lang_s, content_s):
|
349 |
+
res += f"<{lang.lower()}>{content}"
|
350 |
+
res += "|"
|
351 |
+
return "mix", res[:-1]
|
352 |
+
|
353 |
+
|
354 |
+
def load_audio(path):
|
355 |
+
audio, sr = librosa.load(path, 48000)
|
356 |
+
# audio = librosa.resample(audio, 44100, 48000)
|
357 |
+
return sr, audio
|
358 |
+
|
359 |
+
|
360 |
+
def gr_util(item):
|
361 |
+
if item == "Text prompt":
|
362 |
+
return {"visible": True, "__type__": "update"}, {
|
363 |
+
"visible": False,
|
364 |
+
"__type__": "update",
|
365 |
+
}
|
366 |
+
else:
|
367 |
+
return {"visible": False, "__type__": "update"}, {
|
368 |
+
"visible": True,
|
369 |
+
"__type__": "update",
|
370 |
+
}
|
371 |
+
|
372 |
+
|
373 |
+
if __name__ == "__main__":
|
374 |
+
if config.webui_config.debug:
|
375 |
+
logger.info("Enable DEBUG-LEVEL log")
|
376 |
+
logging.basicConfig(level=logging.DEBUG)
|
377 |
+
hps = utils.get_hparams_from_file(config.webui_config.config_path)
|
378 |
+
# 若config.json中未指定版本则默认为最新版本
|
379 |
+
version = hps.version if hasattr(hps, "version") else latest_version
|
380 |
+
net_g = get_net_g(
|
381 |
+
model_path=config.webui_config.model, version=version, device=device, hps=hps
|
382 |
+
)
|
383 |
+
speaker_ids = hps.data.spk2id
|
384 |
+
speakers = list(speaker_ids.keys())
|
385 |
+
languages = ["ZH", "JP", "EN", "mix", "auto"]
|
386 |
+
with gr.Blocks() as app:
|
387 |
+
with gr.Row():
|
388 |
+
with gr.Column():
|
389 |
+
text = gr.TextArea(
|
390 |
+
label="输入文本内容",
|
391 |
+
placeholder="""
|
392 |
+
如果你选择语言为\'mix\',必须按照格式输入,否则报错:
|
393 |
+
格式举例(zh是中文,jp是日语,不区分大小写;说话人举例:gongzi):
|
394 |
+
[说话人1]<zh>你好,こんにちは! <jp>こんにちは,世界。
|
395 |
+
[说话人2]<zh>你好吗?<jp>元気ですか?
|
396 |
+
[说话人3]<zh>谢谢。<jp>どういたしまして。
|
397 |
+
...
|
398 |
+
另外,所有的语言选项都可以用'|'分割长段实现分句生成。
|
399 |
+
""",
|
400 |
+
value="光合作用係指植物以光作為能源,將二氧化碳同水,轉化成為葡萄糖同氧氣嘅過程。植物會利用大氣中嘅二氧化碳,泥土中吸返嚟嘅水,加埋自己本身有嘅葉綠素,利用太陽光供給嘅能量,製造成糖分。好多粒糖聚埋一齊就會變成澱粉,植物會以澱粉嘅形式嚟儲存過多嘅萄葡糖。除咗糖粉之外,氧氣係光合作用嘅副產品(亦有佢係新陳代謝廢物嘅講法),呢啲氧氣會被釋放出大氣,維持大氣中氧氣嘅含量。光合作用除咗係自養生物嘅食物來源,重係呢個世界上其中一個非常重要嘅生物化學作用,因為全地球嘅生物都依賴佢所製造出嚟嘅氧氣同糖份嚟生存。好多綠色嘅生物,好似藻類,高級植物,某啲細菌,都會做光合作用。\n",
|
401 |
+
)
|
402 |
+
trans = gr.Button("中翻日", variant="primary")
|
403 |
+
slicer = gr.Button("快速切分", variant="primary")
|
404 |
+
formatter = gr.Button("检测语言,并整理为 MIX 格式", variant="primary")
|
405 |
+
speaker = gr.Dropdown(
|
406 |
+
choices=speakers, value=speakers[0], label="Speaker"
|
407 |
+
)
|
408 |
+
_ = gr.Markdown(
|
409 |
+
value="提示模式(Prompt mode):可选文字提示或音频提示,用于生成文字或音频指定风格的声音。\n",
|
410 |
+
visible=False,
|
411 |
+
)
|
412 |
+
prompt_mode = gr.Radio(
|
413 |
+
["Text prompt", "Audio prompt"],
|
414 |
+
label="Prompt Mode",
|
415 |
+
value="Text prompt",
|
416 |
+
visible=False,
|
417 |
+
)
|
418 |
+
text_prompt = gr.Textbox(
|
419 |
+
label="Text prompt",
|
420 |
+
placeholder="用文字描述生成风格。如:Happy",
|
421 |
+
value="Happy",
|
422 |
+
visible=False,
|
423 |
+
)
|
424 |
+
audio_prompt = gr.Audio(
|
425 |
+
label="Audio prompt", type="filepath", visible=False
|
426 |
+
)
|
427 |
+
sdp_ratio = gr.Slider(
|
428 |
+
minimum=0, maximum=1, value=0.5, step=0.1, label="SDP Ratio"
|
429 |
+
)
|
430 |
+
noise_scale = gr.Slider(
|
431 |
+
minimum=0.1, maximum=2, value=0.6, step=0.1, label="Noise"
|
432 |
+
)
|
433 |
+
noise_scale_w = gr.Slider(
|
434 |
+
minimum=0.1, maximum=2, value=0.9, step=0.1, label="Noise_W"
|
435 |
+
)
|
436 |
+
length_scale = gr.Slider(
|
437 |
+
minimum=0.1, maximum=2, value=1.05, step=0.1, label="Length"
|
438 |
+
)
|
439 |
+
language = gr.Dropdown(
|
440 |
+
choices=languages, value=languages[0], label="Language"
|
441 |
+
)
|
442 |
+
btn = gr.Button("生成音频!", variant="primary")
|
443 |
+
with gr.Column():
|
444 |
+
with gr.Accordion("融合文本语义", open=False):
|
445 |
+
gr.Markdown(
|
446 |
+
value="使用辅助文本的语意来辅助生成对话(语言保持与主文本相同)\n\n"
|
447 |
+
"**注意**:不要使用**指令式文本**(如:开心),要使用**带有强烈情感的文本**(如:我好快乐!!!)\n\n"
|
448 |
+
"效果较不明确,留空即为不使用该功能"
|
449 |
+
)
|
450 |
+
style_text = gr.Textbox(label="辅助文本")
|
451 |
+
style_weight = gr.Slider(
|
452 |
+
minimum=0,
|
453 |
+
maximum=1,
|
454 |
+
value=0.7,
|
455 |
+
step=0.1,
|
456 |
+
label="Weight",
|
457 |
+
info="主文本和辅助文本的bert混合比率,0表示仅主文本,1表示仅辅助文本",
|
458 |
+
)
|
459 |
+
with gr.Row():
|
460 |
+
with gr.Column():
|
461 |
+
interval_between_sent = gr.Slider(
|
462 |
+
minimum=0,
|
463 |
+
maximum=5,
|
464 |
+
value=0.2,
|
465 |
+
step=0.1,
|
466 |
+
label="句间停顿(秒),勾选按句切分才生效",
|
467 |
+
)
|
468 |
+
interval_between_para = gr.Slider(
|
469 |
+
minimum=0,
|
470 |
+
maximum=10,
|
471 |
+
value=1,
|
472 |
+
step=0.1,
|
473 |
+
label="段间停顿(秒),需要大于句间停顿才有效",
|
474 |
+
)
|
475 |
+
opt_cut_by_sent = gr.Checkbox(
|
476 |
+
label="按句切分 在按段落切分的基础上再按句子切分文本"
|
477 |
+
)
|
478 |
+
slicer = gr.Button("切分生成", variant="primary")
|
479 |
+
text_output = gr.Textbox(label="状态信息")
|
480 |
+
audio_output = gr.Audio(
|
481 |
+
label="输出音频",
|
482 |
+
value="https://github.com/Naozumi520/Bert-VITS2-Yue/raw/master/sample.wav",
|
483 |
+
)
|
484 |
+
# explain_image = gr.Image(
|
485 |
+
# label="参数解释信息",
|
486 |
+
# show_label=True,
|
487 |
+
# show_share_button=False,
|
488 |
+
# show_download_button=False,
|
489 |
+
# value=os.path.abspath("./img/参数说明.png"),
|
490 |
+
# )
|
491 |
+
btn.click(
|
492 |
+
tts_fn,
|
493 |
+
inputs=[
|
494 |
+
text,
|
495 |
+
speaker,
|
496 |
+
sdp_ratio,
|
497 |
+
noise_scale,
|
498 |
+
noise_scale_w,
|
499 |
+
length_scale,
|
500 |
+
language,
|
501 |
+
audio_prompt,
|
502 |
+
text_prompt,
|
503 |
+
prompt_mode,
|
504 |
+
style_text,
|
505 |
+
style_weight,
|
506 |
+
],
|
507 |
+
outputs=[text_output, audio_output],
|
508 |
+
)
|
509 |
+
|
510 |
+
trans.click(
|
511 |
+
translate,
|
512 |
+
inputs=[text],
|
513 |
+
outputs=[text],
|
514 |
+
)
|
515 |
+
slicer.click(
|
516 |
+
tts_split,
|
517 |
+
inputs=[
|
518 |
+
text,
|
519 |
+
speaker,
|
520 |
+
sdp_ratio,
|
521 |
+
noise_scale,
|
522 |
+
noise_scale_w,
|
523 |
+
length_scale,
|
524 |
+
language,
|
525 |
+
opt_cut_by_sent,
|
526 |
+
interval_between_para,
|
527 |
+
interval_between_sent,
|
528 |
+
audio_prompt,
|
529 |
+
text_prompt,
|
530 |
+
style_text,
|
531 |
+
style_weight,
|
532 |
+
],
|
533 |
+
outputs=[text_output, audio_output],
|
534 |
+
)
|
535 |
+
|
536 |
+
prompt_mode.change(
|
537 |
+
lambda x: gr_util(x),
|
538 |
+
inputs=[prompt_mode],
|
539 |
+
outputs=[text_prompt, audio_prompt],
|
540 |
+
)
|
541 |
+
|
542 |
+
audio_prompt.upload(
|
543 |
+
lambda x: load_audio(x),
|
544 |
+
inputs=[audio_prompt],
|
545 |
+
outputs=[audio_prompt],
|
546 |
+
)
|
547 |
+
|
548 |
+
formatter.click(
|
549 |
+
format_utils,
|
550 |
+
inputs=[text, speaker],
|
551 |
+
outputs=[language, text],
|
552 |
+
)
|
553 |
+
|
554 |
+
print("推理页面已开启!")
|
555 |
+
webbrowser.open(f"http://127.0.0.1:{config.webui_config.port}")
|
556 |
+
app.launch(
|
557 |
+
share=config.webui_config.share,
|
558 |
+
server_name="0.0.0.0",
|
559 |
+
server_port=config.webui_config.port,
|
560 |
+
)
|
attentions.py
ADDED
@@ -0,0 +1,464 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import torch
|
3 |
+
from torch import nn
|
4 |
+
from torch.nn import functional as F
|
5 |
+
|
6 |
+
import commons
|
7 |
+
import logging
|
8 |
+
|
9 |
+
logger = logging.getLogger(__name__)
|
10 |
+
|
11 |
+
|
12 |
+
class LayerNorm(nn.Module):
|
13 |
+
def __init__(self, channels, eps=1e-5):
|
14 |
+
super().__init__()
|
15 |
+
self.channels = channels
|
16 |
+
self.eps = eps
|
17 |
+
|
18 |
+
self.gamma = nn.Parameter(torch.ones(channels))
|
19 |
+
self.beta = nn.Parameter(torch.zeros(channels))
|
20 |
+
|
21 |
+
def forward(self, x):
|
22 |
+
x = x.transpose(1, -1)
|
23 |
+
x = F.layer_norm(x, (self.channels,), self.gamma, self.beta, self.eps)
|
24 |
+
return x.transpose(1, -1)
|
25 |
+
|
26 |
+
|
27 |
+
@torch.jit.script
|
28 |
+
def fused_add_tanh_sigmoid_multiply(input_a, input_b, n_channels):
|
29 |
+
n_channels_int = n_channels[0]
|
30 |
+
in_act = input_a + input_b
|
31 |
+
t_act = torch.tanh(in_act[:, :n_channels_int, :])
|
32 |
+
s_act = torch.sigmoid(in_act[:, n_channels_int:, :])
|
33 |
+
acts = t_act * s_act
|
34 |
+
return acts
|
35 |
+
|
36 |
+
|
37 |
+
class Encoder(nn.Module):
|
38 |
+
def __init__(
|
39 |
+
self,
|
40 |
+
hidden_channels,
|
41 |
+
filter_channels,
|
42 |
+
n_heads,
|
43 |
+
n_layers,
|
44 |
+
kernel_size=1,
|
45 |
+
p_dropout=0.0,
|
46 |
+
window_size=4,
|
47 |
+
isflow=True,
|
48 |
+
**kwargs
|
49 |
+
):
|
50 |
+
super().__init__()
|
51 |
+
self.hidden_channels = hidden_channels
|
52 |
+
self.filter_channels = filter_channels
|
53 |
+
self.n_heads = n_heads
|
54 |
+
self.n_layers = n_layers
|
55 |
+
self.kernel_size = kernel_size
|
56 |
+
self.p_dropout = p_dropout
|
57 |
+
self.window_size = window_size
|
58 |
+
# if isflow:
|
59 |
+
# cond_layer = torch.nn.Conv1d(256, 2*hidden_channels*n_layers, 1)
|
60 |
+
# self.cond_pre = torch.nn.Conv1d(hidden_channels, 2*hidden_channels, 1)
|
61 |
+
# self.cond_layer = weight_norm(cond_layer, name='weight')
|
62 |
+
# self.gin_channels = 256
|
63 |
+
self.cond_layer_idx = self.n_layers
|
64 |
+
if "gin_channels" in kwargs:
|
65 |
+
self.gin_channels = kwargs["gin_channels"]
|
66 |
+
if self.gin_channels != 0:
|
67 |
+
self.spk_emb_linear = nn.Linear(self.gin_channels, self.hidden_channels)
|
68 |
+
# vits2 says 3rd block, so idx is 2 by default
|
69 |
+
self.cond_layer_idx = (
|
70 |
+
kwargs["cond_layer_idx"] if "cond_layer_idx" in kwargs else 2
|
71 |
+
)
|
72 |
+
logging.debug(self.gin_channels, self.cond_layer_idx)
|
73 |
+
assert (
|
74 |
+
self.cond_layer_idx < self.n_layers
|
75 |
+
), "cond_layer_idx should be less than n_layers"
|
76 |
+
self.drop = nn.Dropout(p_dropout)
|
77 |
+
self.attn_layers = nn.ModuleList()
|
78 |
+
self.norm_layers_1 = nn.ModuleList()
|
79 |
+
self.ffn_layers = nn.ModuleList()
|
80 |
+
self.norm_layers_2 = nn.ModuleList()
|
81 |
+
for i in range(self.n_layers):
|
82 |
+
self.attn_layers.append(
|
83 |
+
MultiHeadAttention(
|
84 |
+
hidden_channels,
|
85 |
+
hidden_channels,
|
86 |
+
n_heads,
|
87 |
+
p_dropout=p_dropout,
|
88 |
+
window_size=window_size,
|
89 |
+
)
|
90 |
+
)
|
91 |
+
self.norm_layers_1.append(LayerNorm(hidden_channels))
|
92 |
+
self.ffn_layers.append(
|
93 |
+
FFN(
|
94 |
+
hidden_channels,
|
95 |
+
hidden_channels,
|
96 |
+
filter_channels,
|
97 |
+
kernel_size,
|
98 |
+
p_dropout=p_dropout,
|
99 |
+
)
|
100 |
+
)
|
101 |
+
self.norm_layers_2.append(LayerNorm(hidden_channels))
|
102 |
+
|
103 |
+
def forward(self, x, x_mask, g=None):
|
104 |
+
attn_mask = x_mask.unsqueeze(2) * x_mask.unsqueeze(-1)
|
105 |
+
x = x * x_mask
|
106 |
+
for i in range(self.n_layers):
|
107 |
+
if i == self.cond_layer_idx and g is not None:
|
108 |
+
g = self.spk_emb_linear(g.transpose(1, 2))
|
109 |
+
g = g.transpose(1, 2)
|
110 |
+
x = x + g
|
111 |
+
x = x * x_mask
|
112 |
+
y = self.attn_layers[i](x, x, attn_mask)
|
113 |
+
y = self.drop(y)
|
114 |
+
x = self.norm_layers_1[i](x + y)
|
115 |
+
|
116 |
+
y = self.ffn_layers[i](x, x_mask)
|
117 |
+
y = self.drop(y)
|
118 |
+
x = self.norm_layers_2[i](x + y)
|
119 |
+
x = x * x_mask
|
120 |
+
return x
|
121 |
+
|
122 |
+
|
123 |
+
class Decoder(nn.Module):
|
124 |
+
def __init__(
|
125 |
+
self,
|
126 |
+
hidden_channels,
|
127 |
+
filter_channels,
|
128 |
+
n_heads,
|
129 |
+
n_layers,
|
130 |
+
kernel_size=1,
|
131 |
+
p_dropout=0.0,
|
132 |
+
proximal_bias=False,
|
133 |
+
proximal_init=True,
|
134 |
+
**kwargs
|
135 |
+
):
|
136 |
+
super().__init__()
|
137 |
+
self.hidden_channels = hidden_channels
|
138 |
+
self.filter_channels = filter_channels
|
139 |
+
self.n_heads = n_heads
|
140 |
+
self.n_layers = n_layers
|
141 |
+
self.kernel_size = kernel_size
|
142 |
+
self.p_dropout = p_dropout
|
143 |
+
self.proximal_bias = proximal_bias
|
144 |
+
self.proximal_init = proximal_init
|
145 |
+
|
146 |
+
self.drop = nn.Dropout(p_dropout)
|
147 |
+
self.self_attn_layers = nn.ModuleList()
|
148 |
+
self.norm_layers_0 = nn.ModuleList()
|
149 |
+
self.encdec_attn_layers = nn.ModuleList()
|
150 |
+
self.norm_layers_1 = nn.ModuleList()
|
151 |
+
self.ffn_layers = nn.ModuleList()
|
152 |
+
self.norm_layers_2 = nn.ModuleList()
|
153 |
+
for i in range(self.n_layers):
|
154 |
+
self.self_attn_layers.append(
|
155 |
+
MultiHeadAttention(
|
156 |
+
hidden_channels,
|
157 |
+
hidden_channels,
|
158 |
+
n_heads,
|
159 |
+
p_dropout=p_dropout,
|
160 |
+
proximal_bias=proximal_bias,
|
161 |
+
proximal_init=proximal_init,
|
162 |
+
)
|
163 |
+
)
|
164 |
+
self.norm_layers_0.append(LayerNorm(hidden_channels))
|
165 |
+
self.encdec_attn_layers.append(
|
166 |
+
MultiHeadAttention(
|
167 |
+
hidden_channels, hidden_channels, n_heads, p_dropout=p_dropout
|
168 |
+
)
|
169 |
+
)
|
170 |
+
self.norm_layers_1.append(LayerNorm(hidden_channels))
|
171 |
+
self.ffn_layers.append(
|
172 |
+
FFN(
|
173 |
+
hidden_channels,
|
174 |
+
hidden_channels,
|
175 |
+
filter_channels,
|
176 |
+
kernel_size,
|
177 |
+
p_dropout=p_dropout,
|
178 |
+
causal=True,
|
179 |
+
)
|
180 |
+
)
|
181 |
+
self.norm_layers_2.append(LayerNorm(hidden_channels))
|
182 |
+
|
183 |
+
def forward(self, x, x_mask, h, h_mask):
|
184 |
+
"""
|
185 |
+
x: decoder input
|
186 |
+
h: encoder output
|
187 |
+
"""
|
188 |
+
self_attn_mask = commons.subsequent_mask(x_mask.size(2)).to(
|
189 |
+
device=x.device, dtype=x.dtype
|
190 |
+
)
|
191 |
+
encdec_attn_mask = h_mask.unsqueeze(2) * x_mask.unsqueeze(-1)
|
192 |
+
x = x * x_mask
|
193 |
+
for i in range(self.n_layers):
|
194 |
+
y = self.self_attn_layers[i](x, x, self_attn_mask)
|
195 |
+
y = self.drop(y)
|
196 |
+
x = self.norm_layers_0[i](x + y)
|
197 |
+
|
198 |
+
y = self.encdec_attn_layers[i](x, h, encdec_attn_mask)
|
199 |
+
y = self.drop(y)
|
200 |
+
x = self.norm_layers_1[i](x + y)
|
201 |
+
|
202 |
+
y = self.ffn_layers[i](x, x_mask)
|
203 |
+
y = self.drop(y)
|
204 |
+
x = self.norm_layers_2[i](x + y)
|
205 |
+
x = x * x_mask
|
206 |
+
return x
|
207 |
+
|
208 |
+
|
209 |
+
class MultiHeadAttention(nn.Module):
|
210 |
+
def __init__(
|
211 |
+
self,
|
212 |
+
channels,
|
213 |
+
out_channels,
|
214 |
+
n_heads,
|
215 |
+
p_dropout=0.0,
|
216 |
+
window_size=None,
|
217 |
+
heads_share=True,
|
218 |
+
block_length=None,
|
219 |
+
proximal_bias=False,
|
220 |
+
proximal_init=False,
|
221 |
+
):
|
222 |
+
super().__init__()
|
223 |
+
assert channels % n_heads == 0
|
224 |
+
|
225 |
+
self.channels = channels
|
226 |
+
self.out_channels = out_channels
|
227 |
+
self.n_heads = n_heads
|
228 |
+
self.p_dropout = p_dropout
|
229 |
+
self.window_size = window_size
|
230 |
+
self.heads_share = heads_share
|
231 |
+
self.block_length = block_length
|
232 |
+
self.proximal_bias = proximal_bias
|
233 |
+
self.proximal_init = proximal_init
|
234 |
+
self.attn = None
|
235 |
+
|
236 |
+
self.k_channels = channels // n_heads
|
237 |
+
self.conv_q = nn.Conv1d(channels, channels, 1)
|
238 |
+
self.conv_k = nn.Conv1d(channels, channels, 1)
|
239 |
+
self.conv_v = nn.Conv1d(channels, channels, 1)
|
240 |
+
self.conv_o = nn.Conv1d(channels, out_channels, 1)
|
241 |
+
self.drop = nn.Dropout(p_dropout)
|
242 |
+
|
243 |
+
if window_size is not None:
|
244 |
+
n_heads_rel = 1 if heads_share else n_heads
|
245 |
+
rel_stddev = self.k_channels**-0.5
|
246 |
+
self.emb_rel_k = nn.Parameter(
|
247 |
+
torch.randn(n_heads_rel, window_size * 2 + 1, self.k_channels)
|
248 |
+
* rel_stddev
|
249 |
+
)
|
250 |
+
self.emb_rel_v = nn.Parameter(
|
251 |
+
torch.randn(n_heads_rel, window_size * 2 + 1, self.k_channels)
|
252 |
+
* rel_stddev
|
253 |
+
)
|
254 |
+
|
255 |
+
nn.init.xavier_uniform_(self.conv_q.weight)
|
256 |
+
nn.init.xavier_uniform_(self.conv_k.weight)
|
257 |
+
nn.init.xavier_uniform_(self.conv_v.weight)
|
258 |
+
if proximal_init:
|
259 |
+
with torch.no_grad():
|
260 |
+
self.conv_k.weight.copy_(self.conv_q.weight)
|
261 |
+
self.conv_k.bias.copy_(self.conv_q.bias)
|
262 |
+
|
263 |
+
def forward(self, x, c, attn_mask=None):
|
264 |
+
q = self.conv_q(x)
|
265 |
+
k = self.conv_k(c)
|
266 |
+
v = self.conv_v(c)
|
267 |
+
|
268 |
+
x, self.attn = self.attention(q, k, v, mask=attn_mask)
|
269 |
+
|
270 |
+
x = self.conv_o(x)
|
271 |
+
return x
|
272 |
+
|
273 |
+
def attention(self, query, key, value, mask=None):
|
274 |
+
# reshape [b, d, t] -> [b, n_h, t, d_k]
|
275 |
+
b, d, t_s, t_t = (*key.size(), query.size(2))
|
276 |
+
query = query.view(b, self.n_heads, self.k_channels, t_t).transpose(2, 3)
|
277 |
+
key = key.view(b, self.n_heads, self.k_channels, t_s).transpose(2, 3)
|
278 |
+
value = value.view(b, self.n_heads, self.k_channels, t_s).transpose(2, 3)
|
279 |
+
|
280 |
+
scores = torch.matmul(query / math.sqrt(self.k_channels), key.transpose(-2, -1))
|
281 |
+
if self.window_size is not None:
|
282 |
+
assert (
|
283 |
+
t_s == t_t
|
284 |
+
), "Relative attention is only available for self-attention."
|
285 |
+
key_relative_embeddings = self._get_relative_embeddings(self.emb_rel_k, t_s)
|
286 |
+
rel_logits = self._matmul_with_relative_keys(
|
287 |
+
query / math.sqrt(self.k_channels), key_relative_embeddings
|
288 |
+
)
|
289 |
+
scores_local = self._relative_position_to_absolute_position(rel_logits)
|
290 |
+
scores = scores + scores_local
|
291 |
+
if self.proximal_bias:
|
292 |
+
assert t_s == t_t, "Proximal bias is only available for self-attention."
|
293 |
+
scores = scores + self._attention_bias_proximal(t_s).to(
|
294 |
+
device=scores.device, dtype=scores.dtype
|
295 |
+
)
|
296 |
+
if mask is not None:
|
297 |
+
scores = scores.masked_fill(mask == 0, -1e4)
|
298 |
+
if self.block_length is not None:
|
299 |
+
assert (
|
300 |
+
t_s == t_t
|
301 |
+
), "Local attention is only available for self-attention."
|
302 |
+
block_mask = (
|
303 |
+
torch.ones_like(scores)
|
304 |
+
.triu(-self.block_length)
|
305 |
+
.tril(self.block_length)
|
306 |
+
)
|
307 |
+
scores = scores.masked_fill(block_mask == 0, -1e4)
|
308 |
+
p_attn = F.softmax(scores, dim=-1) # [b, n_h, t_t, t_s]
|
309 |
+
p_attn = self.drop(p_attn)
|
310 |
+
output = torch.matmul(p_attn, value)
|
311 |
+
if self.window_size is not None:
|
312 |
+
relative_weights = self._absolute_position_to_relative_position(p_attn)
|
313 |
+
value_relative_embeddings = self._get_relative_embeddings(
|
314 |
+
self.emb_rel_v, t_s
|
315 |
+
)
|
316 |
+
output = output + self._matmul_with_relative_values(
|
317 |
+
relative_weights, value_relative_embeddings
|
318 |
+
)
|
319 |
+
output = (
|
320 |
+
output.transpose(2, 3).contiguous().view(b, d, t_t)
|
321 |
+
) # [b, n_h, t_t, d_k] -> [b, d, t_t]
|
322 |
+
return output, p_attn
|
323 |
+
|
324 |
+
def _matmul_with_relative_values(self, x, y):
|
325 |
+
"""
|
326 |
+
x: [b, h, l, m]
|
327 |
+
y: [h or 1, m, d]
|
328 |
+
ret: [b, h, l, d]
|
329 |
+
"""
|
330 |
+
ret = torch.matmul(x, y.unsqueeze(0))
|
331 |
+
return ret
|
332 |
+
|
333 |
+
def _matmul_with_relative_keys(self, x, y):
|
334 |
+
"""
|
335 |
+
x: [b, h, l, d]
|
336 |
+
y: [h or 1, m, d]
|
337 |
+
ret: [b, h, l, m]
|
338 |
+
"""
|
339 |
+
ret = torch.matmul(x, y.unsqueeze(0).transpose(-2, -1))
|
340 |
+
return ret
|
341 |
+
|
342 |
+
def _get_relative_embeddings(self, relative_embeddings, length):
|
343 |
+
2 * self.window_size + 1
|
344 |
+
# Pad first before slice to avoid using cond ops.
|
345 |
+
pad_length = max(length - (self.window_size + 1), 0)
|
346 |
+
slice_start_position = max((self.window_size + 1) - length, 0)
|
347 |
+
slice_end_position = slice_start_position + 2 * length - 1
|
348 |
+
if pad_length > 0:
|
349 |
+
padded_relative_embeddings = F.pad(
|
350 |
+
relative_embeddings,
|
351 |
+
commons.convert_pad_shape([[0, 0], [pad_length, pad_length], [0, 0]]),
|
352 |
+
)
|
353 |
+
else:
|
354 |
+
padded_relative_embeddings = relative_embeddings
|
355 |
+
used_relative_embeddings = padded_relative_embeddings[
|
356 |
+
:, slice_start_position:slice_end_position
|
357 |
+
]
|
358 |
+
return used_relative_embeddings
|
359 |
+
|
360 |
+
def _relative_position_to_absolute_position(self, x):
|
361 |
+
"""
|
362 |
+
x: [b, h, l, 2*l-1]
|
363 |
+
ret: [b, h, l, l]
|
364 |
+
"""
|
365 |
+
batch, heads, length, _ = x.size()
|
366 |
+
# Concat columns of pad to shift from relative to absolute indexing.
|
367 |
+
x = F.pad(x, commons.convert_pad_shape([[0, 0], [0, 0], [0, 0], [0, 1]]))
|
368 |
+
|
369 |
+
# Concat extra elements so to add up to shape (len+1, 2*len-1).
|
370 |
+
x_flat = x.view([batch, heads, length * 2 * length])
|
371 |
+
x_flat = F.pad(
|
372 |
+
x_flat, commons.convert_pad_shape([[0, 0], [0, 0], [0, length - 1]])
|
373 |
+
)
|
374 |
+
|
375 |
+
# Reshape and slice out the padded elements.
|
376 |
+
x_final = x_flat.view([batch, heads, length + 1, 2 * length - 1])[
|
377 |
+
:, :, :length, length - 1 :
|
378 |
+
]
|
379 |
+
return x_final
|
380 |
+
|
381 |
+
def _absolute_position_to_relative_position(self, x):
|
382 |
+
"""
|
383 |
+
x: [b, h, l, l]
|
384 |
+
ret: [b, h, l, 2*l-1]
|
385 |
+
"""
|
386 |
+
batch, heads, length, _ = x.size()
|
387 |
+
# pad along column
|
388 |
+
x = F.pad(
|
389 |
+
x, commons.convert_pad_shape([[0, 0], [0, 0], [0, 0], [0, length - 1]])
|
390 |
+
)
|
391 |
+
x_flat = x.view([batch, heads, length**2 + length * (length - 1)])
|
392 |
+
# add 0's in the beginning that will skew the elements after reshape
|
393 |
+
x_flat = F.pad(x_flat, commons.convert_pad_shape([[0, 0], [0, 0], [length, 0]]))
|
394 |
+
x_final = x_flat.view([batch, heads, length, 2 * length])[:, :, :, 1:]
|
395 |
+
return x_final
|
396 |
+
|
397 |
+
def _attention_bias_proximal(self, length):
|
398 |
+
"""Bias for self-attention to encourage attention to close positions.
|
399 |
+
Args:
|
400 |
+
length: an integer scalar.
|
401 |
+
Returns:
|
402 |
+
a Tensor with shape [1, 1, length, length]
|
403 |
+
"""
|
404 |
+
r = torch.arange(length, dtype=torch.float32)
|
405 |
+
diff = torch.unsqueeze(r, 0) - torch.unsqueeze(r, 1)
|
406 |
+
return torch.unsqueeze(torch.unsqueeze(-torch.log1p(torch.abs(diff)), 0), 0)
|
407 |
+
|
408 |
+
|
409 |
+
class FFN(nn.Module):
|
410 |
+
def __init__(
|
411 |
+
self,
|
412 |
+
in_channels,
|
413 |
+
out_channels,
|
414 |
+
filter_channels,
|
415 |
+
kernel_size,
|
416 |
+
p_dropout=0.0,
|
417 |
+
activation=None,
|
418 |
+
causal=False,
|
419 |
+
):
|
420 |
+
super().__init__()
|
421 |
+
self.in_channels = in_channels
|
422 |
+
self.out_channels = out_channels
|
423 |
+
self.filter_channels = filter_channels
|
424 |
+
self.kernel_size = kernel_size
|
425 |
+
self.p_dropout = p_dropout
|
426 |
+
self.activation = activation
|
427 |
+
self.causal = causal
|
428 |
+
|
429 |
+
if causal:
|
430 |
+
self.padding = self._causal_padding
|
431 |
+
else:
|
432 |
+
self.padding = self._same_padding
|
433 |
+
|
434 |
+
self.conv_1 = nn.Conv1d(in_channels, filter_channels, kernel_size)
|
435 |
+
self.conv_2 = nn.Conv1d(filter_channels, out_channels, kernel_size)
|
436 |
+
self.drop = nn.Dropout(p_dropout)
|
437 |
+
|
438 |
+
def forward(self, x, x_mask):
|
439 |
+
x = self.conv_1(self.padding(x * x_mask))
|
440 |
+
if self.activation == "gelu":
|
441 |
+
x = x * torch.sigmoid(1.702 * x)
|
442 |
+
else:
|
443 |
+
x = torch.relu(x)
|
444 |
+
x = self.drop(x)
|
445 |
+
x = self.conv_2(self.padding(x * x_mask))
|
446 |
+
return x * x_mask
|
447 |
+
|
448 |
+
def _causal_padding(self, x):
|
449 |
+
if self.kernel_size == 1:
|
450 |
+
return x
|
451 |
+
pad_l = self.kernel_size - 1
|
452 |
+
pad_r = 0
|
453 |
+
padding = [[0, 0], [0, 0], [pad_l, pad_r]]
|
454 |
+
x = F.pad(x, commons.convert_pad_shape(padding))
|
455 |
+
return x
|
456 |
+
|
457 |
+
def _same_padding(self, x):
|
458 |
+
if self.kernel_size == 1:
|
459 |
+
return x
|
460 |
+
pad_l = (self.kernel_size - 1) // 2
|
461 |
+
pad_r = self.kernel_size // 2
|
462 |
+
padding = [[0, 0], [0, 0], [pad_l, pad_r]]
|
463 |
+
x = F.pad(x, commons.convert_pad_shape(padding))
|
464 |
+
return x
|
bert_gen.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from multiprocessing import Pool
|
3 |
+
import commons
|
4 |
+
import utils
|
5 |
+
from tqdm import tqdm
|
6 |
+
from text import check_bert_models, cleaned_text_to_sequence, get_bert
|
7 |
+
import argparse
|
8 |
+
import torch.multiprocessing as mp
|
9 |
+
from config import config
|
10 |
+
|
11 |
+
|
12 |
+
def process_line(x):
|
13 |
+
line, add_blank = x
|
14 |
+
device = config.bert_gen_config.device
|
15 |
+
if config.bert_gen_config.use_multi_device:
|
16 |
+
rank = mp.current_process()._identity
|
17 |
+
rank = rank[0] if len(rank) > 0 else 0
|
18 |
+
if torch.cuda.is_available():
|
19 |
+
gpu_id = rank % torch.cuda.device_count()
|
20 |
+
device = torch.device(f"cuda:{gpu_id}")
|
21 |
+
else:
|
22 |
+
device = torch.device("cpu")
|
23 |
+
wav_path, _, language_str, text, phones, tone, word2ph = line.strip().split("|")
|
24 |
+
phone = phones.split(" ")
|
25 |
+
tone = [int(i) for i in tone.split(" ")]
|
26 |
+
word2ph = [int(i) for i in word2ph.split(" ")]
|
27 |
+
word2ph = [i for i in word2ph]
|
28 |
+
phone, tone, language = cleaned_text_to_sequence(phone, tone, language_str)
|
29 |
+
|
30 |
+
if add_blank:
|
31 |
+
phone = commons.intersperse(phone, 0)
|
32 |
+
tone = commons.intersperse(tone, 0)
|
33 |
+
language = commons.intersperse(language, 0)
|
34 |
+
for i in range(len(word2ph)):
|
35 |
+
word2ph[i] = word2ph[i] * 2
|
36 |
+
word2ph[0] += 1
|
37 |
+
|
38 |
+
bert_path = wav_path.replace(".WAV", ".wav").replace(".wav", ".bert.pt")
|
39 |
+
|
40 |
+
try:
|
41 |
+
bert = torch.load(bert_path)
|
42 |
+
assert bert.shape[0] == 2048
|
43 |
+
except Exception:
|
44 |
+
try:
|
45 |
+
bert = get_bert(text, word2ph, language_str, device)
|
46 |
+
assert bert.shape[-1] == len(phone)
|
47 |
+
torch.save(bert, bert_path)
|
48 |
+
except Exception as e:
|
49 |
+
print(f"Error: {text=}")
|
50 |
+
print(f"Error: {phone=}")
|
51 |
+
print(f"Error: {tone=}")
|
52 |
+
print(f"Error: {word2ph=}")
|
53 |
+
print(f"Error: {language_str=}")
|
54 |
+
print(f"Error: {device=}")
|
55 |
+
print(f"Error: {add_blank=}")
|
56 |
+
print(line.strip().split("|"))
|
57 |
+
|
58 |
+
raise e
|
59 |
+
|
60 |
+
|
61 |
+
preprocess_text_config = config.preprocess_text_config
|
62 |
+
|
63 |
+
if __name__ == "__main__":
|
64 |
+
parser = argparse.ArgumentParser()
|
65 |
+
parser.add_argument(
|
66 |
+
"-c", "--config", type=str, default=config.bert_gen_config.config_path
|
67 |
+
)
|
68 |
+
parser.add_argument(
|
69 |
+
"--num_processes", type=int, default=config.bert_gen_config.num_processes
|
70 |
+
)
|
71 |
+
args, _ = parser.parse_known_args()
|
72 |
+
config_path = args.config
|
73 |
+
hps = utils.get_hparams_from_file(config_path)
|
74 |
+
check_bert_models()
|
75 |
+
lines = []
|
76 |
+
with open(hps.data.training_files, encoding="utf-8") as f:
|
77 |
+
lines.extend(f.readlines())
|
78 |
+
|
79 |
+
with open(hps.data.validation_files, encoding="utf-8") as f:
|
80 |
+
lines.extend(f.readlines())
|
81 |
+
add_blank = [hps.data.add_blank] * len(lines)
|
82 |
+
|
83 |
+
if len(lines) != 0:
|
84 |
+
num_processes = args.num_processes
|
85 |
+
with Pool(processes=num_processes) as pool:
|
86 |
+
for _ in tqdm(
|
87 |
+
pool.imap_unordered(process_line, zip(lines, add_blank)),
|
88 |
+
total=len(lines),
|
89 |
+
):
|
90 |
+
# 这里是缩进的代码块,表示循环体
|
91 |
+
pass # 使用pass语句作为占位符
|
92 |
+
|
93 |
+
print(f"bert生成完毕!, 共有{len(lines)}个bert.pt生成!")
|
commons.py
ADDED
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import torch
|
3 |
+
from torch.nn import functional as F
|
4 |
+
|
5 |
+
|
6 |
+
def init_weights(m, mean=0.0, std=0.01):
|
7 |
+
classname = m.__class__.__name__
|
8 |
+
if classname.find("Conv") != -1:
|
9 |
+
m.weight.data.normal_(mean, std)
|
10 |
+
|
11 |
+
|
12 |
+
def get_padding(kernel_size, dilation=1):
|
13 |
+
return int((kernel_size * dilation - dilation) / 2)
|
14 |
+
|
15 |
+
|
16 |
+
def convert_pad_shape(pad_shape):
|
17 |
+
layer = pad_shape[::-1]
|
18 |
+
pad_shape = [item for sublist in layer for item in sublist]
|
19 |
+
return pad_shape
|
20 |
+
|
21 |
+
|
22 |
+
def intersperse(lst, item):
|
23 |
+
result = [item] * (len(lst) * 2 + 1)
|
24 |
+
result[1::2] = lst
|
25 |
+
return result
|
26 |
+
|
27 |
+
|
28 |
+
def kl_divergence(m_p, logs_p, m_q, logs_q):
|
29 |
+
"""KL(P||Q)"""
|
30 |
+
kl = (logs_q - logs_p) - 0.5
|
31 |
+
kl += (
|
32 |
+
0.5 * (torch.exp(2.0 * logs_p) + ((m_p - m_q) ** 2)) * torch.exp(-2.0 * logs_q)
|
33 |
+
)
|
34 |
+
return kl
|
35 |
+
|
36 |
+
|
37 |
+
def rand_gumbel(shape):
|
38 |
+
"""Sample from the Gumbel distribution, protect from overflows."""
|
39 |
+
uniform_samples = torch.rand(shape) * 0.99998 + 0.00001
|
40 |
+
return -torch.log(-torch.log(uniform_samples))
|
41 |
+
|
42 |
+
|
43 |
+
def rand_gumbel_like(x):
|
44 |
+
g = rand_gumbel(x.size()).to(dtype=x.dtype, device=x.device)
|
45 |
+
return g
|
46 |
+
|
47 |
+
|
48 |
+
def slice_segments(x, ids_str, segment_size=4):
|
49 |
+
gather_indices = ids_str.view(x.size(0), 1, 1).repeat(
|
50 |
+
1, x.size(1), 1
|
51 |
+
) + torch.arange(segment_size, device=x.device)
|
52 |
+
return torch.gather(x, 2, gather_indices)
|
53 |
+
|
54 |
+
|
55 |
+
def rand_slice_segments(x, x_lengths=None, segment_size=4):
|
56 |
+
b, d, t = x.size()
|
57 |
+
if x_lengths is None:
|
58 |
+
x_lengths = t
|
59 |
+
ids_str_max = torch.clamp(x_lengths - segment_size + 1, min=0)
|
60 |
+
ids_str = (torch.rand([b], device=x.device) * ids_str_max).to(dtype=torch.long)
|
61 |
+
ret = slice_segments(x, ids_str, segment_size)
|
62 |
+
return ret, ids_str
|
63 |
+
|
64 |
+
|
65 |
+
def get_timing_signal_1d(length, channels, min_timescale=1.0, max_timescale=1.0e4):
|
66 |
+
position = torch.arange(length, dtype=torch.float)
|
67 |
+
num_timescales = channels // 2
|
68 |
+
log_timescale_increment = math.log(float(max_timescale) / float(min_timescale)) / (
|
69 |
+
num_timescales - 1
|
70 |
+
)
|
71 |
+
inv_timescales = min_timescale * torch.exp(
|
72 |
+
torch.arange(num_timescales, dtype=torch.float) * -log_timescale_increment
|
73 |
+
)
|
74 |
+
scaled_time = position.unsqueeze(0) * inv_timescales.unsqueeze(1)
|
75 |
+
signal = torch.cat([torch.sin(scaled_time), torch.cos(scaled_time)], 0)
|
76 |
+
signal = F.pad(signal, [0, 0, 0, channels % 2])
|
77 |
+
signal = signal.view(1, channels, length)
|
78 |
+
return signal
|
79 |
+
|
80 |
+
|
81 |
+
def add_timing_signal_1d(x, min_timescale=1.0, max_timescale=1.0e4):
|
82 |
+
b, channels, length = x.size()
|
83 |
+
signal = get_timing_signal_1d(length, channels, min_timescale, max_timescale)
|
84 |
+
return x + signal.to(dtype=x.dtype, device=x.device)
|
85 |
+
|
86 |
+
|
87 |
+
def cat_timing_signal_1d(x, min_timescale=1.0, max_timescale=1.0e4, axis=1):
|
88 |
+
b, channels, length = x.size()
|
89 |
+
signal = get_timing_signal_1d(length, channels, min_timescale, max_timescale)
|
90 |
+
return torch.cat([x, signal.to(dtype=x.dtype, device=x.device)], axis)
|
91 |
+
|
92 |
+
|
93 |
+
def subsequent_mask(length):
|
94 |
+
mask = torch.tril(torch.ones(length, length)).unsqueeze(0).unsqueeze(0)
|
95 |
+
return mask
|
96 |
+
|
97 |
+
|
98 |
+
@torch.jit.script
|
99 |
+
def fused_add_tanh_sigmoid_multiply(input_a, input_b, n_channels):
|
100 |
+
n_channels_int = n_channels[0]
|
101 |
+
in_act = input_a + input_b
|
102 |
+
t_act = torch.tanh(in_act[:, :n_channels_int, :])
|
103 |
+
s_act = torch.sigmoid(in_act[:, n_channels_int:, :])
|
104 |
+
acts = t_act * s_act
|
105 |
+
return acts
|
106 |
+
|
107 |
+
|
108 |
+
def convert_pad_shape(pad_shape):
|
109 |
+
layer = pad_shape[::-1]
|
110 |
+
pad_shape = [item for sublist in layer for item in sublist]
|
111 |
+
return pad_shape
|
112 |
+
|
113 |
+
|
114 |
+
def shift_1d(x):
|
115 |
+
x = F.pad(x, convert_pad_shape([[0, 0], [0, 0], [1, 0]]))[:, :, :-1]
|
116 |
+
return x
|
117 |
+
|
118 |
+
|
119 |
+
def sequence_mask(length, max_length=None):
|
120 |
+
if max_length is None:
|
121 |
+
max_length = length.max()
|
122 |
+
x = torch.arange(max_length, dtype=length.dtype, device=length.device)
|
123 |
+
return x.unsqueeze(0) < length.unsqueeze(1)
|
124 |
+
|
125 |
+
|
126 |
+
def generate_path(duration, mask):
|
127 |
+
"""
|
128 |
+
duration: [b, 1, t_x]
|
129 |
+
mask: [b, 1, t_y, t_x]
|
130 |
+
"""
|
131 |
+
|
132 |
+
b, _, t_y, t_x = mask.shape
|
133 |
+
cum_duration = torch.cumsum(duration, -1)
|
134 |
+
|
135 |
+
cum_duration_flat = cum_duration.view(b * t_x)
|
136 |
+
path = sequence_mask(cum_duration_flat, t_y).to(mask.dtype)
|
137 |
+
path = path.view(b, t_x, t_y)
|
138 |
+
path = path - F.pad(path, convert_pad_shape([[0, 0], [1, 0], [0, 0]]))[:, :-1]
|
139 |
+
path = path.unsqueeze(1).transpose(2, 3) * mask
|
140 |
+
return path
|
141 |
+
|
142 |
+
|
143 |
+
def clip_grad_value_(parameters, clip_value, norm_type=2):
|
144 |
+
if isinstance(parameters, torch.Tensor):
|
145 |
+
parameters = [parameters]
|
146 |
+
parameters = list(filter(lambda p: p.grad is not None, parameters))
|
147 |
+
norm_type = float(norm_type)
|
148 |
+
if clip_value is not None:
|
149 |
+
clip_value = float(clip_value)
|
150 |
+
|
151 |
+
total_norm = 0
|
152 |
+
for p in parameters:
|
153 |
+
param_norm = p.grad.data.norm(norm_type)
|
154 |
+
total_norm += param_norm.item() ** norm_type
|
155 |
+
if clip_value is not None:
|
156 |
+
p.grad.data.clamp_(min=-clip_value, max=clip_value)
|
157 |
+
total_norm = total_norm ** (1.0 / norm_type)
|
158 |
+
return total_norm
|
compress_model.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from collections import OrderedDict
|
2 |
+
from text.symbols import symbols
|
3 |
+
import torch
|
4 |
+
|
5 |
+
from tools.log import logger
|
6 |
+
import utils
|
7 |
+
from models import SynthesizerTrn
|
8 |
+
import os
|
9 |
+
|
10 |
+
|
11 |
+
def copyStateDict(state_dict):
|
12 |
+
if list(state_dict.keys())[0].startswith("module"):
|
13 |
+
start_idx = 1
|
14 |
+
else:
|
15 |
+
start_idx = 0
|
16 |
+
new_state_dict = OrderedDict()
|
17 |
+
for k, v in state_dict.items():
|
18 |
+
name = ",".join(k.split(".")[start_idx:])
|
19 |
+
new_state_dict[name] = v
|
20 |
+
return new_state_dict
|
21 |
+
|
22 |
+
|
23 |
+
def removeOptimizer(config: str, input_model: str, ishalf: bool, output_model: str):
|
24 |
+
hps = utils.get_hparams_from_file(config)
|
25 |
+
|
26 |
+
net_g = SynthesizerTrn(
|
27 |
+
len(symbols),
|
28 |
+
hps.data.filter_length // 2 + 1,
|
29 |
+
hps.train.segment_size // hps.data.hop_length,
|
30 |
+
n_speakers=hps.data.n_speakers,
|
31 |
+
**hps.model,
|
32 |
+
)
|
33 |
+
|
34 |
+
optim_g = torch.optim.AdamW(
|
35 |
+
net_g.parameters(),
|
36 |
+
hps.train.learning_rate,
|
37 |
+
betas=hps.train.betas,
|
38 |
+
eps=hps.train.eps,
|
39 |
+
)
|
40 |
+
|
41 |
+
state_dict_g = torch.load(input_model, map_location="cpu")
|
42 |
+
new_dict_g = copyStateDict(state_dict_g)
|
43 |
+
keys = []
|
44 |
+
for k, v in new_dict_g["model"].items():
|
45 |
+
if "enc_q" in k:
|
46 |
+
continue # noqa: E701
|
47 |
+
keys.append(k)
|
48 |
+
|
49 |
+
new_dict_g = (
|
50 |
+
{k: new_dict_g["model"][k].half() for k in keys}
|
51 |
+
if ishalf
|
52 |
+
else {k: new_dict_g["model"][k] for k in keys}
|
53 |
+
)
|
54 |
+
|
55 |
+
torch.save(
|
56 |
+
{
|
57 |
+
"model": new_dict_g,
|
58 |
+
"iteration": 0,
|
59 |
+
"optimizer": optim_g.state_dict(),
|
60 |
+
"learning_rate": 0.0001,
|
61 |
+
},
|
62 |
+
output_model,
|
63 |
+
)
|
64 |
+
|
65 |
+
|
66 |
+
if __name__ == "__main__":
|
67 |
+
import argparse
|
68 |
+
|
69 |
+
parser = argparse.ArgumentParser()
|
70 |
+
parser.add_argument("-c", "--config", type=str, default="configs/config.json")
|
71 |
+
parser.add_argument("-i", "--input", type=str)
|
72 |
+
parser.add_argument("-o", "--output", type=str, default=None)
|
73 |
+
parser.add_argument(
|
74 |
+
"-hf", "--half", action="store_true", default=False, help="Save as FP16"
|
75 |
+
)
|
76 |
+
|
77 |
+
args = parser.parse_args()
|
78 |
+
|
79 |
+
output = args.output
|
80 |
+
|
81 |
+
if output is None:
|
82 |
+
import os.path
|
83 |
+
|
84 |
+
filename, ext = os.path.splitext(args.input)
|
85 |
+
half = "_half" if args.half else ""
|
86 |
+
output = filename + "_release" + half + ext
|
87 |
+
|
88 |
+
removeOptimizer(args.config, args.input, args.half, output)
|
89 |
+
logger.info(f"压缩模型成功, 输出模型: {os.path.abspath(output)}")
|
config.py
ADDED
@@ -0,0 +1,261 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
@Desc: 全局配置文件读取
|
3 |
+
"""
|
4 |
+
|
5 |
+
import argparse
|
6 |
+
import yaml
|
7 |
+
from typing import Dict, List
|
8 |
+
import os
|
9 |
+
import shutil
|
10 |
+
import sys
|
11 |
+
|
12 |
+
|
13 |
+
class Resample_config:
|
14 |
+
"""重采样配置"""
|
15 |
+
|
16 |
+
def __init__(self, in_dir: str, out_dir: str, sampling_rate: int = 44100):
|
17 |
+
self.sampling_rate: int = sampling_rate # 目标采样率
|
18 |
+
self.in_dir: str = in_dir # 待处理音频目录路径
|
19 |
+
self.out_dir: str = out_dir # 重采样输出路径
|
20 |
+
|
21 |
+
@classmethod
|
22 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
23 |
+
"""从字典中生成实例"""
|
24 |
+
|
25 |
+
# 不检查路径是否有效,此逻辑在resample.py中处理
|
26 |
+
data["in_dir"] = os.path.join(dataset_path, data["in_dir"])
|
27 |
+
data["out_dir"] = os.path.join(dataset_path, data["out_dir"])
|
28 |
+
|
29 |
+
return cls(**data)
|
30 |
+
|
31 |
+
|
32 |
+
class Preprocess_text_config:
|
33 |
+
"""数据预处理配置"""
|
34 |
+
|
35 |
+
def __init__(
|
36 |
+
self,
|
37 |
+
transcription_path: str,
|
38 |
+
cleaned_path: str,
|
39 |
+
train_path: str,
|
40 |
+
val_path: str,
|
41 |
+
config_path: str,
|
42 |
+
val_per_lang: int = 5,
|
43 |
+
max_val_total: int = 10000,
|
44 |
+
clean: bool = True,
|
45 |
+
):
|
46 |
+
self.transcription_path: str = (
|
47 |
+
transcription_path # 原始文本文件路径,文本格式应为{wav_path}|{speaker_name}|{language}|{text}。
|
48 |
+
)
|
49 |
+
self.cleaned_path: str = (
|
50 |
+
cleaned_path # 数据清洗后文本路径,可以不填。不填则将在原始文本目录生成
|
51 |
+
)
|
52 |
+
self.train_path: str = (
|
53 |
+
train_path # 训练集路径,可以不填。不填则将在原始文本目录生成
|
54 |
+
)
|
55 |
+
self.val_path: str = (
|
56 |
+
val_path # 验证集路径,可以不填。不填则将在原始文本目录生成
|
57 |
+
)
|
58 |
+
self.config_path: str = config_path # 配置文件路径
|
59 |
+
self.val_per_lang: int = val_per_lang # 每个speaker的验证集条数
|
60 |
+
self.max_val_total: int = (
|
61 |
+
max_val_total # 验证集最大条数,多于的会被截断并放到训练集中
|
62 |
+
)
|
63 |
+
self.clean: bool = clean # 是否进行数据清洗
|
64 |
+
|
65 |
+
@classmethod
|
66 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
67 |
+
"""从字典中生成实例"""
|
68 |
+
|
69 |
+
data["transcription_path"] = os.path.join(
|
70 |
+
dataset_path, data["transcription_path"]
|
71 |
+
)
|
72 |
+
if data["cleaned_path"] == "" or data["cleaned_path"] is None:
|
73 |
+
data["cleaned_path"] = None
|
74 |
+
else:
|
75 |
+
data["cleaned_path"] = os.path.join(dataset_path, data["cleaned_path"])
|
76 |
+
data["train_path"] = os.path.join(dataset_path, data["train_path"])
|
77 |
+
data["val_path"] = os.path.join(dataset_path, data["val_path"])
|
78 |
+
data["config_path"] = os.path.join(dataset_path, data["config_path"])
|
79 |
+
|
80 |
+
return cls(**data)
|
81 |
+
|
82 |
+
|
83 |
+
class Bert_gen_config:
|
84 |
+
"""bert_gen 配置"""
|
85 |
+
|
86 |
+
def __init__(
|
87 |
+
self,
|
88 |
+
config_path: str,
|
89 |
+
num_processes: int = 2,
|
90 |
+
device: str = "cuda",
|
91 |
+
use_multi_device: bool = False,
|
92 |
+
):
|
93 |
+
self.config_path = config_path
|
94 |
+
self.num_processes = num_processes
|
95 |
+
self.device = device
|
96 |
+
self.use_multi_device = use_multi_device
|
97 |
+
|
98 |
+
@classmethod
|
99 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
100 |
+
data["config_path"] = os.path.join(dataset_path, data["config_path"])
|
101 |
+
|
102 |
+
return cls(**data)
|
103 |
+
|
104 |
+
|
105 |
+
class Emo_gen_config:
|
106 |
+
"""emo_gen 配置"""
|
107 |
+
|
108 |
+
def __init__(
|
109 |
+
self,
|
110 |
+
config_path: str,
|
111 |
+
num_processes: int = 2,
|
112 |
+
device: str = "cuda",
|
113 |
+
use_multi_device: bool = False,
|
114 |
+
):
|
115 |
+
self.config_path = config_path
|
116 |
+
self.num_processes = num_processes
|
117 |
+
self.device = device
|
118 |
+
self.use_multi_device = use_multi_device
|
119 |
+
|
120 |
+
@classmethod
|
121 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
122 |
+
data["config_path"] = os.path.join(dataset_path, data["config_path"])
|
123 |
+
|
124 |
+
return cls(**data)
|
125 |
+
|
126 |
+
|
127 |
+
class Train_ms_config:
|
128 |
+
"""训练配置"""
|
129 |
+
|
130 |
+
def __init__(
|
131 |
+
self,
|
132 |
+
config_path: str,
|
133 |
+
env: Dict[str, any],
|
134 |
+
base: Dict[str, any],
|
135 |
+
model: str,
|
136 |
+
num_workers: int,
|
137 |
+
spec_cache: bool,
|
138 |
+
keep_ckpts: int,
|
139 |
+
):
|
140 |
+
self.env = env # 需要加载的环境变量
|
141 |
+
self.base = base # 底模配置
|
142 |
+
self.model = (
|
143 |
+
model # 训练模型存储目录,该路径为相对于dataset_path的路径,而非项目根目录
|
144 |
+
)
|
145 |
+
self.config_path = config_path # 配置文件路径
|
146 |
+
self.num_workers = num_workers # worker数量
|
147 |
+
self.spec_cache = spec_cache # 是否启用spec缓存
|
148 |
+
self.keep_ckpts = keep_ckpts # ckpt数量
|
149 |
+
|
150 |
+
@classmethod
|
151 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
152 |
+
# data["model"] = os.path.join(dataset_path, data["model"])
|
153 |
+
data["config_path"] = os.path.join(dataset_path, data["config_path"])
|
154 |
+
|
155 |
+
return cls(**data)
|
156 |
+
|
157 |
+
|
158 |
+
class Webui_config:
|
159 |
+
"""webui 配置"""
|
160 |
+
|
161 |
+
def __init__(
|
162 |
+
self,
|
163 |
+
device: str,
|
164 |
+
model: str,
|
165 |
+
config_path: str,
|
166 |
+
language_identification_library: str,
|
167 |
+
port: int = 7860,
|
168 |
+
share: bool = False,
|
169 |
+
debug: bool = False,
|
170 |
+
):
|
171 |
+
self.device: str = device
|
172 |
+
self.model: str = model # 端口号
|
173 |
+
self.config_path: str = config_path # 是否公开部署,对外网开放
|
174 |
+
self.port: int = port # 是否开启debug模式
|
175 |
+
self.share: bool = share # 模型路径
|
176 |
+
self.debug: bool = debug # 配置文件路径
|
177 |
+
self.language_identification_library: str = (
|
178 |
+
language_identification_library # 语种识别库
|
179 |
+
)
|
180 |
+
|
181 |
+
@classmethod
|
182 |
+
def from_dict(cls, dataset_path: str, data: Dict[str, any]):
|
183 |
+
data["config_path"] = os.path.join(dataset_path, data["config_path"])
|
184 |
+
data["model"] = os.path.join(dataset_path, data["model"])
|
185 |
+
return cls(**data)
|
186 |
+
|
187 |
+
|
188 |
+
class Server_config:
|
189 |
+
def __init__(
|
190 |
+
self, models: List[Dict[str, any]], port: int = 5000, device: str = "cuda"
|
191 |
+
):
|
192 |
+
self.models: List[Dict[str, any]] = models # 需要加载的所有模型的配置
|
193 |
+
self.port: int = port # 端口号
|
194 |
+
self.device: str = device # 模型默认使用设备
|
195 |
+
|
196 |
+
@classmethod
|
197 |
+
def from_dict(cls, data: Dict[str, any]):
|
198 |
+
return cls(**data)
|
199 |
+
|
200 |
+
|
201 |
+
class Translate_config:
|
202 |
+
"""翻译api配置"""
|
203 |
+
|
204 |
+
def __init__(self, app_key: str, secret_key: str):
|
205 |
+
self.app_key = app_key
|
206 |
+
self.secret_key = secret_key
|
207 |
+
|
208 |
+
@classmethod
|
209 |
+
def from_dict(cls, data: Dict[str, any]):
|
210 |
+
return cls(**data)
|
211 |
+
|
212 |
+
|
213 |
+
class Config:
|
214 |
+
def __init__(self, config_path: str):
|
215 |
+
if not os.path.isfile(config_path) and os.path.isfile("default_config.yml"):
|
216 |
+
shutil.copy(src="default_config.yml", dst=config_path)
|
217 |
+
print(
|
218 |
+
f"已根据默认配置文件default_config.yml生成配置文件{config_path}。请按该配置文件的说明进行配置后重新运行。"
|
219 |
+
)
|
220 |
+
print("如无特殊需求,请勿修改default_config.yml或备份该文件。")
|
221 |
+
sys.exit(0)
|
222 |
+
with open(file=config_path, mode="r", encoding="utf-8") as file:
|
223 |
+
yaml_config: Dict[str, any] = yaml.safe_load(file.read())
|
224 |
+
dataset_path: str = yaml_config["dataset_path"]
|
225 |
+
openi_token: str = yaml_config["openi_token"]
|
226 |
+
self.dataset_path: str = dataset_path
|
227 |
+
self.mirror: str = yaml_config["mirror"]
|
228 |
+
self.openi_token: str = openi_token
|
229 |
+
self.resample_config: Resample_config = Resample_config.from_dict(
|
230 |
+
dataset_path, yaml_config["resample"]
|
231 |
+
)
|
232 |
+
self.preprocess_text_config: Preprocess_text_config = (
|
233 |
+
Preprocess_text_config.from_dict(
|
234 |
+
dataset_path, yaml_config["preprocess_text"]
|
235 |
+
)
|
236 |
+
)
|
237 |
+
self.bert_gen_config: Bert_gen_config = Bert_gen_config.from_dict(
|
238 |
+
dataset_path, yaml_config["bert_gen"]
|
239 |
+
)
|
240 |
+
self.emo_gen_config: Emo_gen_config = Emo_gen_config.from_dict(
|
241 |
+
dataset_path, yaml_config["emo_gen"]
|
242 |
+
)
|
243 |
+
self.train_ms_config: Train_ms_config = Train_ms_config.from_dict(
|
244 |
+
dataset_path, yaml_config["train_ms"]
|
245 |
+
)
|
246 |
+
self.webui_config: Webui_config = Webui_config.from_dict(
|
247 |
+
dataset_path, yaml_config["webui"]
|
248 |
+
)
|
249 |
+
self.server_config: Server_config = Server_config.from_dict(
|
250 |
+
yaml_config["server"]
|
251 |
+
)
|
252 |
+
self.translate_config: Translate_config = Translate_config.from_dict(
|
253 |
+
yaml_config["translate"]
|
254 |
+
)
|
255 |
+
|
256 |
+
|
257 |
+
parser = argparse.ArgumentParser()
|
258 |
+
# 为避免与以前的config.json起冲突,将其更名如下
|
259 |
+
parser.add_argument("-y", "--yml_config", type=str, default="config.yml")
|
260 |
+
args, _ = parser.parse_known_args()
|
261 |
+
config = Config(args.yml_config)
|
config.yml
ADDED
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 全局配置
|
2 |
+
# 对于希望在同一时间使用多个配置文件的情况,例如两个GPU同时跑两个训练集:通过环境变量指定配置文件,不指定则默认为./config.yml
|
3 |
+
|
4 |
+
# 拟提供通用路径配置,统一存放数据,避免数据放得很乱
|
5 |
+
# 每个数据集与其对应的模型存放至统一路径下,后续所有的路径配置均为相对于datasetPath的路径
|
6 |
+
# 不填或者填空则路径为相对于项目根目录的路径
|
7 |
+
dataset_path: "data/finetuned"
|
8 |
+
|
9 |
+
# 模型镜像源,默认huggingface,使用openi镜像源需指定openi_token
|
10 |
+
mirror: ""
|
11 |
+
openi_token: "" # openi token
|
12 |
+
|
13 |
+
# resample 音频重采样配置
|
14 |
+
# 注意, “:” 后需要加空格
|
15 |
+
resample:
|
16 |
+
# 目标重采样率
|
17 |
+
sampling_rate: 44100
|
18 |
+
# 音频文件输入路径,重采样会将该路径下所有.wav音频文件重采样
|
19 |
+
# 请填入相对于datasetPath的相对路径
|
20 |
+
in_dir: "audios/raw" # 相对于根目录的路径为 /datasetPath/in_dir
|
21 |
+
# 音频文件重采样后输出路径
|
22 |
+
out_dir: "audios/wavs"
|
23 |
+
|
24 |
+
|
25 |
+
# preprocess_text 数据集预处理相关配置
|
26 |
+
# 注意, “:” 后需要加空格
|
27 |
+
preprocess_text:
|
28 |
+
# 原始文本文件路径,文本格式应为{wav_path}|{speaker_name}|{language}|{text}。
|
29 |
+
transcription_path: "filelists/你的数据集文本.list"
|
30 |
+
# 数据清洗后文本路径,可以不填。不填则将在原始文本目录生成
|
31 |
+
cleaned_path: ""
|
32 |
+
# 训练集路径
|
33 |
+
train_path: "filelists/train.list"
|
34 |
+
# 验证集路径
|
35 |
+
val_path: "filelists/val.list"
|
36 |
+
# 配置文件路径
|
37 |
+
config_path: "configs/config.json"
|
38 |
+
# 每个语言的验证集条数
|
39 |
+
val_per_lang: 400
|
40 |
+
# 验证集最大条数,多于的会被截断并放到训练集中
|
41 |
+
max_val_total: 1200
|
42 |
+
# 是否进行数据清洗
|
43 |
+
clean: true
|
44 |
+
|
45 |
+
|
46 |
+
# bert_gen 相关配置
|
47 |
+
# 注意, “:” 后需要加空格
|
48 |
+
bert_gen:
|
49 |
+
# 训练数据集配置文件路径
|
50 |
+
config_path: "configs/config.json"
|
51 |
+
# 并行数
|
52 |
+
num_processes: 4
|
53 |
+
# 使用设备:可选项 "cuda" 显卡推理,"cpu" cpu推理
|
54 |
+
# 该选项同时决定了get_bert_feature的默认设备
|
55 |
+
device: "cuda"
|
56 |
+
# 使用多卡推理
|
57 |
+
use_multi_device: false
|
58 |
+
|
59 |
+
# emo_gen 相关配置
|
60 |
+
# 注意, “:” 后需要加空格
|
61 |
+
emo_gen:
|
62 |
+
# 训练数据集配置文件路径
|
63 |
+
config_path: "configs/config.json"
|
64 |
+
# 并行数
|
65 |
+
num_processes: 4
|
66 |
+
# 使用设备:可选项 "cuda" 显卡推理,"cpu" cpu推理
|
67 |
+
device: "cuda"
|
68 |
+
# 使用多卡推理
|
69 |
+
use_multi_device: false
|
70 |
+
|
71 |
+
# train 训练配置
|
72 |
+
# 注意, “:” 后需要加空格
|
73 |
+
train_ms:
|
74 |
+
env:
|
75 |
+
MASTER_ADDR: "localhost"
|
76 |
+
MASTER_PORT: 10086
|
77 |
+
WORLD_SIZE: 1
|
78 |
+
LOCAL_RANK: 0
|
79 |
+
RANK: 0
|
80 |
+
# 可以填写任意名的环境变量
|
81 |
+
# THE_ENV_VAR_YOU_NEED_TO_USE: "1234567"
|
82 |
+
# 底模设置
|
83 |
+
base:
|
84 |
+
use_base_model: false
|
85 |
+
repo_id: "Stardust_minus/Bert-VITS2"
|
86 |
+
model_image: "Bert-VITS2_2.3底模" # openi网页的模型名
|
87 |
+
# 训练模型存储目录:与旧版本的区别,原先数据集是存放在logs/model_name下的,现在改为统一存放在Data/你的数据集/models下
|
88 |
+
model: "models"
|
89 |
+
# 配置文件路径
|
90 |
+
config_path: "configs/config.json"
|
91 |
+
# 训练使用的worker,不建议超过CPU核心数
|
92 |
+
num_workers: 16
|
93 |
+
# 关闭此项可以节约接近70%的磁盘空间,但是可能导致实际训练速度变慢和更高的CPU使用率。
|
94 |
+
spec_cache: False
|
95 |
+
# 保存的检查点数量,多于此数目的权重会被删除来节省空间。
|
96 |
+
keep_ckpts: 8
|
97 |
+
|
98 |
+
|
99 |
+
# webui webui配置
|
100 |
+
# 注意, “:” 后需要加空格
|
101 |
+
webui:
|
102 |
+
# 推理设备
|
103 |
+
device: "cuda"
|
104 |
+
# 模型路径
|
105 |
+
model: "models/G_43000.pth"
|
106 |
+
# 配置文件路径
|
107 |
+
config_path: "configs/config.json"
|
108 |
+
# 端口号
|
109 |
+
port: 7860
|
110 |
+
# 是否公开部署,对外网开放
|
111 |
+
share: false
|
112 |
+
# 是否开启debug模式
|
113 |
+
debug: false
|
114 |
+
# 语种识别库,可选langid, fastlid
|
115 |
+
language_identification_library: "langid"
|
116 |
+
|
117 |
+
|
118 |
+
# server-fastapi配置
|
119 |
+
# 注意, “:” 后需要加空格
|
120 |
+
# 注意,本配置下的所有配置均为相对于根目录的路径
|
121 |
+
server:
|
122 |
+
# 端口号
|
123 |
+
port: 5000
|
124 |
+
# 模型默认使用设备:但是当前并没有实现这个配置。
|
125 |
+
device: "cuda"
|
126 |
+
# 需要加载的所有模型的配置,可以填多个模型,也可以不填模型,等网页成功后手动加载模型
|
127 |
+
# 不加载模型的配置格式:删除默认给的两个模型配置,给models赋值 [ ],也就是空列表。参考模型2的speakers 即 models: [ ]
|
128 |
+
# 注意,所有模型都必须正确配置model与config的路径,空路径会导致加载错误。
|
129 |
+
# 也可以不填模型,等网页加载成功后手动填写models。
|
130 |
+
models:
|
131 |
+
- # 模型的路径
|
132 |
+
model: ""
|
133 |
+
# 模型config.json的路径
|
134 |
+
config: ""
|
135 |
+
# 模型使用设备,若填写则会覆盖默认配置
|
136 |
+
device: "cuda"
|
137 |
+
# 模型默认使用的语言
|
138 |
+
language: "YUE"
|
139 |
+
# 模型人物默认参数
|
140 |
+
# 不必填写所有人物,不填的使用默认值
|
141 |
+
# 暂时不用填写,当前尚未实现按人区分配置
|
142 |
+
speakers:
|
143 |
+
- speaker: "科比"
|
144 |
+
sdp_ratio: 0.2
|
145 |
+
noise_scale: 0.6
|
146 |
+
noise_scale_w: 0.8
|
147 |
+
length_scale: 1
|
148 |
+
- speaker: "五条悟"
|
149 |
+
sdp_ratio: 0.3
|
150 |
+
noise_scale: 0.7
|
151 |
+
noise_scale_w: 0.8
|
152 |
+
length_scale: 0.5
|
153 |
+
- speaker: "安倍晋三"
|
154 |
+
sdp_ratio: 0.2
|
155 |
+
noise_scale: 0.6
|
156 |
+
noise_scale_w: 0.8
|
157 |
+
length_scale: 1.2
|
158 |
+
- # 模型的路径
|
159 |
+
model: ""
|
160 |
+
# 模型config.json的路径
|
161 |
+
config: ""
|
162 |
+
# 模型使用设备,若填写则会覆盖默认配置
|
163 |
+
device: "cpu"
|
164 |
+
# 模型默认使用的语言
|
165 |
+
language: "JP"
|
166 |
+
# 模型人物默认参数
|
167 |
+
# 不必填写所有人物,不填的使用默认值
|
168 |
+
speakers: [ ] # 也可以不填
|
169 |
+
|
170 |
+
# 百度翻译开放平台 api配置
|
171 |
+
# api接入文档 https://api.fanyi.baidu.com/doc/21
|
172 |
+
# 请不要在github等网站公开分享你的app id 与 key
|
173 |
+
translate:
|
174 |
+
# 你的APPID
|
175 |
+
"app_key": ""
|
176 |
+
# 你的密钥
|
177 |
+
"secret_key": ""
|
configs/config.json
ADDED
@@ -0,0 +1,955 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"train": {
|
3 |
+
"log_interval": 200,
|
4 |
+
"eval_interval": 1000,
|
5 |
+
"seed": 42,
|
6 |
+
"epochs": 1000,
|
7 |
+
"learning_rate": 0.0002,
|
8 |
+
"betas": [
|
9 |
+
0.8,
|
10 |
+
0.99
|
11 |
+
],
|
12 |
+
"eps": 1e-09,
|
13 |
+
"batch_size": 22,
|
14 |
+
"bf16_run": false,
|
15 |
+
"lr_decay": 0.99995,
|
16 |
+
"segment_size": 16384,
|
17 |
+
"init_lr_ratio": 1,
|
18 |
+
"warmup_epochs": 0,
|
19 |
+
"c_mel": 45,
|
20 |
+
"c_kl": 1.0,
|
21 |
+
"c_commit": 100,
|
22 |
+
"skip_optimizer": true,
|
23 |
+
"freeze_YUE_bert": false,
|
24 |
+
"freeze_emo": false
|
25 |
+
},
|
26 |
+
"data": {
|
27 |
+
"training_files": "filelists/train.list",
|
28 |
+
"validation_files": "filelists/val.list",
|
29 |
+
"max_wav_value": 32768.0,
|
30 |
+
"sampling_rate": 44100,
|
31 |
+
"filter_length": 2048,
|
32 |
+
"hop_length": 512,
|
33 |
+
"win_length": 2048,
|
34 |
+
"n_mel_channels": 128,
|
35 |
+
"mel_fmin": 0.0,
|
36 |
+
"mel_fmax": null,
|
37 |
+
"add_blank": true,
|
38 |
+
"n_speakers": 850,
|
39 |
+
"cleaned_text": true,
|
40 |
+
"spk2id": {
|
41 |
+
"派蒙_ZH": 0,
|
42 |
+
"纳西妲_ZH": 1,
|
43 |
+
"凯亚_ZH": 2,
|
44 |
+
"阿贝多_ZH": 3,
|
45 |
+
"温迪_ZH": 4,
|
46 |
+
"枫原万叶_ZH": 5,
|
47 |
+
"钟离_ZH": 6,
|
48 |
+
"荒泷一斗_ZH": 7,
|
49 |
+
"八重神子_ZH": 8,
|
50 |
+
"艾尔海森_ZH": 9,
|
51 |
+
"提纳里_ZH": 10,
|
52 |
+
"迪希雅_ZH": 11,
|
53 |
+
"卡维_ZH": 12,
|
54 |
+
"宵宫_ZH": 13,
|
55 |
+
"那维莱特_ZH": 14,
|
56 |
+
"莱依拉_ZH": 15,
|
57 |
+
"赛诺_ZH": 16,
|
58 |
+
"莫娜_ZH": 17,
|
59 |
+
"诺艾尔_ZH": 18,
|
60 |
+
"托马_ZH": 19,
|
61 |
+
"凝光_ZH": 20,
|
62 |
+
"林尼_ZH": 21,
|
63 |
+
"北斗_ZH": 22,
|
64 |
+
"柯莱_ZH": 23,
|
65 |
+
"神里绫华_ZH": 24,
|
66 |
+
"可莉_ZH": 25,
|
67 |
+
"芭芭拉_ZH": 26,
|
68 |
+
"雷电将军_ZH": 27,
|
69 |
+
"娜维娅_ZH": 28,
|
70 |
+
"芙宁娜_ZH": 29,
|
71 |
+
"珊瑚宫心海_ZH": 30,
|
72 |
+
"鹿野院平藏_ZH": 31,
|
73 |
+
"迪奥娜_ZH": 32,
|
74 |
+
"琴_ZH": 33,
|
75 |
+
"五郎_ZH": 34,
|
76 |
+
"班尼特_ZH": 35,
|
77 |
+
"达达利亚_ZH": 36,
|
78 |
+
"安柏_ZH": 37,
|
79 |
+
"莱欧斯利_ZH": 38,
|
80 |
+
"夜兰_ZH": 39,
|
81 |
+
"妮露_ZH": 40,
|
82 |
+
"辛焱_ZH": 41,
|
83 |
+
"丽莎_ZH": 42,
|
84 |
+
"珐露珊_ZH": 43,
|
85 |
+
"魈_ZH": 44,
|
86 |
+
"香菱_ZH": 45,
|
87 |
+
"迪卢克_ZH": 46,
|
88 |
+
"砂糖_ZH": 47,
|
89 |
+
"烟绯_ZH": 48,
|
90 |
+
"早柚_ZH": 49,
|
91 |
+
"云堇_ZH": 50,
|
92 |
+
"刻晴_ZH": 51,
|
93 |
+
"重云_ZH": 52,
|
94 |
+
"优菈_ZH": 53,
|
95 |
+
"胡桃_ZH": 54,
|
96 |
+
"流浪者_ZH": 55,
|
97 |
+
"久岐忍_ZH": 56,
|
98 |
+
"神里绫人_ZH": 57,
|
99 |
+
"甘雨_ZH": 58,
|
100 |
+
"戴因斯雷布_ZH": 59,
|
101 |
+
"菲谢尔_ZH": 60,
|
102 |
+
"白术_ZH": 61,
|
103 |
+
"行秋_ZH": 62,
|
104 |
+
"九条裟罗_ZH": 63,
|
105 |
+
"夏洛蒂_ZH": 64,
|
106 |
+
"雷泽_ZH": 65,
|
107 |
+
"申鹤_ZH": 66,
|
108 |
+
"荧_ZH": 67,
|
109 |
+
"空_ZH": 68,
|
110 |
+
"迪娜泽黛_ZH": 69,
|
111 |
+
"凯瑟琳_ZH": 70,
|
112 |
+
"多莉_ZH": 71,
|
113 |
+
"坎蒂丝_ZH": 72,
|
114 |
+
"琳妮特_ZH": 73,
|
115 |
+
"萍姥姥_ZH": 74,
|
116 |
+
"罗莎莉亚_ZH": 75,
|
117 |
+
"埃德_ZH": 76,
|
118 |
+
"爱贝尔_ZH": 77,
|
119 |
+
"伊迪娅_ZH": 78,
|
120 |
+
"留云借风真君_ZH": 79,
|
121 |
+
"绮良良_ZH": 80,
|
122 |
+
"陌生人_ZH": 81,
|
123 |
+
"七七_ZH": 82,
|
124 |
+
"式大将_ZH": 83,
|
125 |
+
"瑶瑶_ZH": 84,
|
126 |
+
"奥兹_ZH": 85,
|
127 |
+
"菲米尼_ZH": 86,
|
128 |
+
"米卡_ZH": 87,
|
129 |
+
"哲平_ZH": 88,
|
130 |
+
"浮游水蕈兽·元素生命_ZH": 89,
|
131 |
+
"大肉丸_ZH": 90,
|
132 |
+
"托克_ZH": 91,
|
133 |
+
"蒂玛乌斯_ZH": 92,
|
134 |
+
"昆钧_ZH": 93,
|
135 |
+
"欧菲妮_ZH": 94,
|
136 |
+
"塞琉斯_ZH": 95,
|
137 |
+
"仆人_ZH": 96,
|
138 |
+
"迈勒斯_ZH": 97,
|
139 |
+
"希格雯_ZH": 98,
|
140 |
+
"阿守_ZH": 99,
|
141 |
+
"拉赫曼_ZH": 100,
|
142 |
+
"杜拉夫_ZH": 101,
|
143 |
+
"伊利亚斯_ZH": 102,
|
144 |
+
"阿晃_ZH": 103,
|
145 |
+
"旁白_ZH": 104,
|
146 |
+
"爱德琳_ZH": 105,
|
147 |
+
"埃洛伊_ZH": 106,
|
148 |
+
"德沃沙克_ZH": 107,
|
149 |
+
"玛乔丽_ZH": 108,
|
150 |
+
"塞塔蕾_ZH": 109,
|
151 |
+
"柊千里_ZH": 110,
|
152 |
+
"海芭夏_ZH": 111,
|
153 |
+
"九条镰治_ZH": 112,
|
154 |
+
"阿娜耶_ZH": 113,
|
155 |
+
"笼钓瓶一心_ZH": 114,
|
156 |
+
"回声海螺_ZH": 115,
|
157 |
+
"劳维克_ZH": 116,
|
158 |
+
"元太_ZH": 117,
|
159 |
+
"阿扎尔_ZH": 118,
|
160 |
+
"查尔斯_ZH": 119,
|
161 |
+
"阿洛瓦_ZH": 120,
|
162 |
+
"埃勒曼_ZH": 121,
|
163 |
+
"纳比尔_ZH": 122,
|
164 |
+
"莎拉_ZH": 123,
|
165 |
+
"康纳_ZH": 124,
|
166 |
+
"博来_ZH": 125,
|
167 |
+
"玛塞勒_ZH": 126,
|
168 |
+
"阿祇_ZH": 127,
|
169 |
+
"博士_ZH": 128,
|
170 |
+
"玛格丽特_ZH": 129,
|
171 |
+
"迪尔菲_ZH": 130,
|
172 |
+
"宛烟_ZH": 131,
|
173 |
+
"羽生田千鹤_ZH": 132,
|
174 |
+
"海妮耶_ZH": 133,
|
175 |
+
"旅行者_ZH": 134,
|
176 |
+
"霍夫曼_ZH": 135,
|
177 |
+
"佐西摩斯_ZH": 136,
|
178 |
+
"鹿野奈奈_ZH": 137,
|
179 |
+
"舒伯特_ZH": 138,
|
180 |
+
"天叔_ZH": 139,
|
181 |
+
"艾莉丝_ZH": 140,
|
182 |
+
"龙二_ZH": 141,
|
183 |
+
"莺儿_ZH": 142,
|
184 |
+
"嘉良_ZH": 143,
|
185 |
+
"一心传名刀_ZH": 144,
|
186 |
+
"珊瑚_ZH": 145,
|
187 |
+
"言笑_ZH": 146,
|
188 |
+
"久利须_ZH": 147,
|
189 |
+
"嘉玛_ZH": 148,
|
190 |
+
"艾文_ZH": 149,
|
191 |
+
"克洛琳德_ZH": 150,
|
192 |
+
"丹吉尔_ZH": 151,
|
193 |
+
"女士_ZH": 152,
|
194 |
+
"白老先生_ZH": 153,
|
195 |
+
"天目十五_ZH": 154,
|
196 |
+
"老孟_ZH": 155,
|
197 |
+
"巴达维_ZH": 156,
|
198 |
+
"长生_ZH": 157,
|
199 |
+
"吴船长_ZH": 158,
|
200 |
+
"拉齐_ZH": 159,
|
201 |
+
"艾伯特_ZH": 160,
|
202 |
+
"松浦_ZH": 161,
|
203 |
+
"埃泽_ZH": 162,
|
204 |
+
"阿圆_ZH": 163,
|
205 |
+
"莫塞伊思_ZH": 164,
|
206 |
+
"阿拉夫_ZH": 165,
|
207 |
+
"杜吉耶_ZH": 166,
|
208 |
+
"石头_ZH": 167,
|
209 |
+
"百闻_ZH": 168,
|
210 |
+
"波洛_ZH": 169,
|
211 |
+
"斯坦利_ZH": 170,
|
212 |
+
"博易_ZH": 171,
|
213 |
+
"迈蒙_ZH": 172,
|
214 |
+
"掇星攫辰天君_ZH": 173,
|
215 |
+
"毗伽尔_ZH": 174,
|
216 |
+
"芙卡洛斯_ZH": 175,
|
217 |
+
"恶龙_ZH": 176,
|
218 |
+
"恕筠_ZH": 177,
|
219 |
+
"知易_ZH": 178,
|
220 |
+
"克列门特_ZH": 179,
|
221 |
+
"大慈树王_ZH": 180,
|
222 |
+
"西拉杰_ZH": 181,
|
223 |
+
"上杉_ZH": 182,
|
224 |
+
"阿尔卡米_ZH": 183,
|
225 |
+
"纯水精灵_ZH": 184,
|
226 |
+
"常九爷_ZH": 185,
|
227 |
+
"沙扎曼_ZH": 186,
|
228 |
+
"田铁嘴_ZH": 187,
|
229 |
+
"克罗索_ZH": 188,
|
230 |
+
"阿巴图伊_ZH": 189,
|
231 |
+
"阿佩普_ZH": 190,
|
232 |
+
"埃尔欣根_ZH": 191,
|
233 |
+
"萨赫哈蒂_ZH": 192,
|
234 |
+
"塔杰·拉德卡尼_ZH": 193,
|
235 |
+
"安西_ZH": 194,
|
236 |
+
"陆行岩本真蕈·元素生命_ZH": 195,
|
237 |
+
"派蒙_JP": 196,
|
238 |
+
"纳西妲_JP": 197,
|
239 |
+
"凯亚_JP": 198,
|
240 |
+
"阿贝多_JP": 199,
|
241 |
+
"温迪_JP": 200,
|
242 |
+
"枫原万叶_JP": 201,
|
243 |
+
"钟离_JP": 202,
|
244 |
+
"荒泷一斗_JP": 203,
|
245 |
+
"八重神子_JP": 204,
|
246 |
+
"艾尔海森_JP": 205,
|
247 |
+
"提纳里_JP": 206,
|
248 |
+
"迪希雅_JP": 207,
|
249 |
+
"卡维_JP": 208,
|
250 |
+
"宵宫_JP": 209,
|
251 |
+
"那维莱特_JP": 210,
|
252 |
+
"莱依拉_JP": 211,
|
253 |
+
"赛诺_JP": 212,
|
254 |
+
"莫娜_JP": 213,
|
255 |
+
"诺艾尔_JP": 214,
|
256 |
+
"托马_JP": 215,
|
257 |
+
"凝光_JP": 216,
|
258 |
+
"林尼_JP": 217,
|
259 |
+
"北斗_JP": 218,
|
260 |
+
"柯莱_JP": 219,
|
261 |
+
"神里绫华_JP": 220,
|
262 |
+
"可莉_JP": 221,
|
263 |
+
"芭芭拉_JP": 222,
|
264 |
+
"雷电将军_JP": 223,
|
265 |
+
"娜维娅_JP": 224,
|
266 |
+
"芙宁娜_JP": 225,
|
267 |
+
"珊瑚宫心海_JP": 226,
|
268 |
+
"鹿野院平藏_JP": 227,
|
269 |
+
"迪奥娜_JP": 228,
|
270 |
+
"琴_JP": 229,
|
271 |
+
"五郎_JP": 230,
|
272 |
+
"班尼特_JP": 231,
|
273 |
+
"达达利亚_JP": 232,
|
274 |
+
"安柏_JP": 233,
|
275 |
+
"莱欧斯利_JP": 234,
|
276 |
+
"夜兰_JP": 235,
|
277 |
+
"妮露_JP": 236,
|
278 |
+
"辛焱_JP": 237,
|
279 |
+
"丽莎_JP": 238,
|
280 |
+
"珐露珊_JP": 239,
|
281 |
+
"魈_JP": 240,
|
282 |
+
"香菱_JP": 241,
|
283 |
+
"迪卢克_JP": 242,
|
284 |
+
"砂糖_JP": 243,
|
285 |
+
"烟绯_JP": 244,
|
286 |
+
"早柚_JP": 245,
|
287 |
+
"云堇_JP": 246,
|
288 |
+
"刻晴_JP": 247,
|
289 |
+
"重云_JP": 248,
|
290 |
+
"优菈_JP": 249,
|
291 |
+
"胡桃_JP": 250,
|
292 |
+
"流浪者_JP": 251,
|
293 |
+
"久岐忍_JP": 252,
|
294 |
+
"神里绫人_JP": 253,
|
295 |
+
"甘雨_JP": 254,
|
296 |
+
"戴因斯雷布_JP": 255,
|
297 |
+
"菲谢尔_JP": 256,
|
298 |
+
"白术_JP": 257,
|
299 |
+
"行秋_JP": 258,
|
300 |
+
"九条裟罗_JP": 259,
|
301 |
+
"夏洛蒂_JP": 260,
|
302 |
+
"雷泽_JP": 261,
|
303 |
+
"申鹤_JP": 262,
|
304 |
+
"空_JP": 263,
|
305 |
+
"荧_JP": 264,
|
306 |
+
"迪娜泽黛_JP": 265,
|
307 |
+
"凯瑟琳_JP": 266,
|
308 |
+
"多莉_JP": 267,
|
309 |
+
"坎蒂丝_JP": 268,
|
310 |
+
"琳妮特_JP": 269,
|
311 |
+
"萍姥姥_JP": 270,
|
312 |
+
"罗莎莉亚_JP": 271,
|
313 |
+
"埃德_JP": 272,
|
314 |
+
"爱贝尔_JP": 273,
|
315 |
+
"伊迪娅_JP": 274,
|
316 |
+
"留云借风真君_JP": 275,
|
317 |
+
"绮良良_JP": 276,
|
318 |
+
"陌生人_JP": 277,
|
319 |
+
"七七_JP": 278,
|
320 |
+
"式大将_JP": 279,
|
321 |
+
"瑶瑶_JP": 280,
|
322 |
+
"奥兹_JP": 281,
|
323 |
+
"菲米尼_JP": 282,
|
324 |
+
"米卡_JP": 283,
|
325 |
+
"哲平_JP": 284,
|
326 |
+
"浮游水蕈兽·元素生命_JP": 285,
|
327 |
+
"大肉丸_JP": 286,
|
328 |
+
"托克_JP": 287,
|
329 |
+
"蒂玛乌斯_JP": 288,
|
330 |
+
"昆钧_JP": 289,
|
331 |
+
"欧菲妮_JP": 290,
|
332 |
+
"塞琉斯_JP": 291,
|
333 |
+
"仆人_JP": 292,
|
334 |
+
"迈勒斯_JP": 293,
|
335 |
+
"希格雯_JP": 294,
|
336 |
+
"阿守_JP": 295,
|
337 |
+
"拉赫曼_JP": 296,
|
338 |
+
"杜拉夫_JP": 297,
|
339 |
+
"伊利亚斯_JP": 298,
|
340 |
+
"阿晃_JP": 299,
|
341 |
+
"旁白_JP": 300,
|
342 |
+
"爱德琳_JP": 301,
|
343 |
+
"埃洛伊_JP": 302,
|
344 |
+
"德沃沙克_JP": 303,
|
345 |
+
"玛乔丽_JP": 304,
|
346 |
+
"塞塔蕾_JP": 305,
|
347 |
+
"柊千里_JP": 306,
|
348 |
+
"海芭夏_JP": 307,
|
349 |
+
"九条镰治_JP": 308,
|
350 |
+
"阿娜耶_JP": 309,
|
351 |
+
"笼钓瓶一心_JP": 310,
|
352 |
+
"回声海螺_JP": 311,
|
353 |
+
"劳维克_JP": 312,
|
354 |
+
"元太_JP": 313,
|
355 |
+
"阿扎尔_JP": 314,
|
356 |
+
"查尔斯_JP": 315,
|
357 |
+
"阿洛瓦_JP": 316,
|
358 |
+
"埃勒曼_JP": 317,
|
359 |
+
"纳比尔_JP": 318,
|
360 |
+
"莎拉_JP": 319,
|
361 |
+
"康纳_JP": 320,
|
362 |
+
"博来_JP": 321,
|
363 |
+
"玛塞勒_JP": 322,
|
364 |
+
"阿祇_JP": 323,
|
365 |
+
"博士_JP": 324,
|
366 |
+
"迪尔菲_JP": 325,
|
367 |
+
"玛格丽特_JP": 326,
|
368 |
+
"宛烟_JP": 327,
|
369 |
+
"羽生田千鹤_JP": 328,
|
370 |
+
"海妮耶_JP": 329,
|
371 |
+
"霍夫曼_JP": 330,
|
372 |
+
"旅行者_JP": 331,
|
373 |
+
"佐西摩斯_JP": 332,
|
374 |
+
"舒伯特_JP": 333,
|
375 |
+
"鹿野奈奈_JP": 334,
|
376 |
+
"天叔_JP": 335,
|
377 |
+
"龙二_JP": 336,
|
378 |
+
"艾莉丝_JP": 337,
|
379 |
+
"莺儿_JP": 338,
|
380 |
+
"嘉良_JP": 339,
|
381 |
+
"珊瑚_JP": 340,
|
382 |
+
"言笑_JP": 341,
|
383 |
+
"一心传名刀_JP": 342,
|
384 |
+
"费迪南德_JP": 343,
|
385 |
+
"久利须_JP": 344,
|
386 |
+
"嘉玛_JP": 345,
|
387 |
+
"艾文_JP": 346,
|
388 |
+
"克洛琳德_JP": 347,
|
389 |
+
"丹吉尔_JP": 348,
|
390 |
+
"天目十五_JP": 349,
|
391 |
+
"女士_JP": 350,
|
392 |
+
"老孟_JP": 351,
|
393 |
+
"白老先生_JP": 352,
|
394 |
+
"舍利夫_JP": 353,
|
395 |
+
"巴达维_JP": 354,
|
396 |
+
"拉齐_JP": 355,
|
397 |
+
"长生_JP": 356,
|
398 |
+
"吴船长_JP": 357,
|
399 |
+
"艾伯特_JP": 358,
|
400 |
+
"松浦_JP": 359,
|
401 |
+
"埃泽_JP": 360,
|
402 |
+
"阿圆_JP": 361,
|
403 |
+
"阿拉夫_JP": 362,
|
404 |
+
"莫塞伊思_JP": 363,
|
405 |
+
"石头_JP": 364,
|
406 |
+
"百闻_JP": 365,
|
407 |
+
"杜吉耶_JP": 366,
|
408 |
+
"波洛_JP": 367,
|
409 |
+
"掇星攫辰天君_JP": 368,
|
410 |
+
"迈蒙_JP": 369,
|
411 |
+
"博易_JP": 370,
|
412 |
+
"诗筠_JP": 371,
|
413 |
+
"斯坦利_JP": 372,
|
414 |
+
"毗伽尔_JP": 373,
|
415 |
+
"芙卡洛斯_JP": 374,
|
416 |
+
"恶龙_JP": 375,
|
417 |
+
"小仓澪_JP": 376,
|
418 |
+
"恕筠_JP": 377,
|
419 |
+
"知易_JP": 378,
|
420 |
+
"克列门特_JP": 379,
|
421 |
+
"大慈树王_JP": 380,
|
422 |
+
"望雅_JP": 381,
|
423 |
+
"黑田_JP": 382,
|
424 |
+
"卡莉娜_JP": 383,
|
425 |
+
"马姆杜_JP": 384,
|
426 |
+
"科林斯_JP": 385,
|
427 |
+
"上杉_JP": 386,
|
428 |
+
"西拉杰_JP": 387,
|
429 |
+
"菲尔戈黛特_JP": 388,
|
430 |
+
"一平_JP": 389,
|
431 |
+
"纯水精灵_JP": 390,
|
432 |
+
"阿尔卡米_JP": 391,
|
433 |
+
"老戴_JP": 392,
|
434 |
+
"谢赫祖拜尔_JP": 393,
|
435 |
+
"沙扎曼_JP": 394,
|
436 |
+
"田铁嘴_JP": 395,
|
437 |
+
"小野寺_JP": 396,
|
438 |
+
"百识_JP": 397,
|
439 |
+
"克罗索_JP": 398,
|
440 |
+
"莱斯格_JP": 399,
|
441 |
+
"芷巧_JP": 400,
|
442 |
+
"加藤洋平_JP": 401,
|
443 |
+
"阿巴图伊_JP": 402,
|
444 |
+
"埃尔欣根_JP": 403,
|
445 |
+
"斯嘉莉_JP": 404,
|
446 |
+
"阿佩普_JP": 405,
|
447 |
+
"巫女_JP": 406,
|
448 |
+
"卡布斯_JP": 407,
|
449 |
+
"洛伦佐_JP": 408,
|
450 |
+
"萨赫哈蒂_JP": 409,
|
451 |
+
"娜德瓦_JP": 410,
|
452 |
+
"塞德娜_JP": 411,
|
453 |
+
"塔杰·拉德卡尼_JP": 412,
|
454 |
+
"绘星_JP": 413,
|
455 |
+
"泽田_JP": 414,
|
456 |
+
"安西_JP": 415,
|
457 |
+
"拉伊德_JP": 416,
|
458 |
+
"亚卡巴_JP": 417,
|
459 |
+
"有乐斋_JP": 418,
|
460 |
+
"莱昂_JP": 419,
|
461 |
+
"尤苏波夫_JP": 420,
|
462 |
+
"夏妮_JP": 421,
|
463 |
+
"埃舍尔_JP": 422,
|
464 |
+
"萨齐因_JP": 423,
|
465 |
+
"古山_JP": 424,
|
466 |
+
"自称渊上之物_JP": 425,
|
467 |
+
"丹羽_JP": 426,
|
468 |
+
"塞萨尔的日记_JP": 427,
|
469 |
+
"派蒙_EN": 428,
|
470 |
+
"纳西妲_EN": 429,
|
471 |
+
"凯亚_EN": 430,
|
472 |
+
"阿贝多_EN": 431,
|
473 |
+
"温迪_EN": 432,
|
474 |
+
"枫原万叶_EN": 433,
|
475 |
+
"钟离_EN": 434,
|
476 |
+
"荒泷一斗_EN": 435,
|
477 |
+
"八重神子_EN": 436,
|
478 |
+
"艾尔海森_EN": 437,
|
479 |
+
"提纳里_EN": 438,
|
480 |
+
"迪希雅_EN": 439,
|
481 |
+
"卡维_EN": 440,
|
482 |
+
"宵宫_EN": 441,
|
483 |
+
"莱依拉_EN": 442,
|
484 |
+
"那维莱特_EN": 443,
|
485 |
+
"赛诺_EN": 444,
|
486 |
+
"莫娜_EN": 445,
|
487 |
+
"诺艾尔_EN": 446,
|
488 |
+
"托马_EN": 447,
|
489 |
+
"凝光_EN": 448,
|
490 |
+
"林尼_EN": 449,
|
491 |
+
"北斗_EN": 450,
|
492 |
+
"柯莱_EN": 451,
|
493 |
+
"神里绫华_EN": 452,
|
494 |
+
"可莉_EN": 453,
|
495 |
+
"芭芭拉_EN": 454,
|
496 |
+
"雷电将军_EN": 455,
|
497 |
+
"娜维娅_EN": 456,
|
498 |
+
"芙宁娜_EN": 457,
|
499 |
+
"珊瑚宫心海_EN": 458,
|
500 |
+
"鹿野院平藏_EN": 459,
|
501 |
+
"迪奥娜_EN": 460,
|
502 |
+
"五郎_EN": 461,
|
503 |
+
"琴_EN": 462,
|
504 |
+
"班尼特_EN": 463,
|
505 |
+
"达达利亚_EN": 464,
|
506 |
+
"安柏_EN": 465,
|
507 |
+
"莱欧斯利_EN": 466,
|
508 |
+
"夜兰_EN": 467,
|
509 |
+
"妮露_EN": 468,
|
510 |
+
"辛焱_EN": 469,
|
511 |
+
"珐露珊_EN": 470,
|
512 |
+
"丽莎_EN": 471,
|
513 |
+
"魈_EN": 472,
|
514 |
+
"香菱_EN": 473,
|
515 |
+
"迪卢克_EN": 474,
|
516 |
+
"砂糖_EN": 475,
|
517 |
+
"烟绯_EN": 476,
|
518 |
+
"早柚_EN": 477,
|
519 |
+
"云堇_EN": 478,
|
520 |
+
"刻晴_EN": 479,
|
521 |
+
"重云_EN": 480,
|
522 |
+
"优菈_EN": 481,
|
523 |
+
"胡桃_EN": 482,
|
524 |
+
"流浪者_EN": 483,
|
525 |
+
"久岐忍_EN": 484,
|
526 |
+
"神里绫人_EN": 485,
|
527 |
+
"甘雨_EN": 486,
|
528 |
+
"戴因斯雷布_EN": 487,
|
529 |
+
"菲谢尔_EN": 488,
|
530 |
+
"白术_EN": 489,
|
531 |
+
"行秋_EN": 490,
|
532 |
+
"九条裟罗_EN": 491,
|
533 |
+
"夏洛蒂_EN": 492,
|
534 |
+
"雷泽_EN": 493,
|
535 |
+
"申鹤_EN": 494,
|
536 |
+
"荧_EN": 495,
|
537 |
+
"空_EN": 496,
|
538 |
+
"迪娜泽黛_EN": 497,
|
539 |
+
"凯瑟琳_EN": 498,
|
540 |
+
"多莉_EN": 499,
|
541 |
+
"坎蒂丝_EN": 500,
|
542 |
+
"琳妮特_EN": 501,
|
543 |
+
"萍姥姥_EN": 502,
|
544 |
+
"罗莎莉亚_EN": 503,
|
545 |
+
"埃德_EN": 504,
|
546 |
+
"爱贝尔_EN": 505,
|
547 |
+
"伊迪娅_EN": 506,
|
548 |
+
"留云借风真君_EN": 507,
|
549 |
+
"绮良良_EN": 508,
|
550 |
+
"陌生人_EN": 509,
|
551 |
+
"七七_EN": 510,
|
552 |
+
"式大将_EN": 511,
|
553 |
+
"瑶瑶_EN": 512,
|
554 |
+
"奥兹_EN": 513,
|
555 |
+
"菲米尼_EN": 514,
|
556 |
+
"米卡_EN": 515,
|
557 |
+
"哲平_EN": 516,
|
558 |
+
"浮游水蕈兽·元素生命_EN": 517,
|
559 |
+
"大肉丸_EN": 518,
|
560 |
+
"托克_EN": 519,
|
561 |
+
"蒂玛乌斯_EN": 520,
|
562 |
+
"昆钧_EN": 521,
|
563 |
+
"欧菲妮_EN": 522,
|
564 |
+
"塞琉斯_EN": 523,
|
565 |
+
"仆人_EN": 524,
|
566 |
+
"迈勒斯_EN": 525,
|
567 |
+
"��格雯_EN": 526,
|
568 |
+
"阿守_EN": 527,
|
569 |
+
"拉赫曼_EN": 528,
|
570 |
+
"杜拉夫_EN": 529,
|
571 |
+
"伊利亚斯_EN": 530,
|
572 |
+
"阿晃_EN": 531,
|
573 |
+
"旁白_EN": 532,
|
574 |
+
"爱德琳_EN": 533,
|
575 |
+
"埃洛伊_EN": 534,
|
576 |
+
"德沃沙克_EN": 535,
|
577 |
+
"玛乔丽_EN": 536,
|
578 |
+
"塞塔蕾_EN": 537,
|
579 |
+
"柊千里_EN": 538,
|
580 |
+
"海芭夏_EN": 539,
|
581 |
+
"九条镰治_EN": 540,
|
582 |
+
"阿娜耶_EN": 541,
|
583 |
+
"笼钓瓶一心_EN": 542,
|
584 |
+
"回声海螺_EN": 543,
|
585 |
+
"劳维克_EN": 544,
|
586 |
+
"元太_EN": 545,
|
587 |
+
"阿扎尔_EN": 546,
|
588 |
+
"查尔斯_EN": 547,
|
589 |
+
"阿洛瓦_EN": 548,
|
590 |
+
"埃勒曼_EN": 549,
|
591 |
+
"纳比尔_EN": 550,
|
592 |
+
"莎拉_EN": 551,
|
593 |
+
"康纳_EN": 552,
|
594 |
+
"博来_EN": 553,
|
595 |
+
"玛塞勒_EN": 554,
|
596 |
+
"阿祇_EN": 555,
|
597 |
+
"博士_EN": 556,
|
598 |
+
"迪尔菲_EN": 557,
|
599 |
+
"宛烟_EN": 558,
|
600 |
+
"玛格丽特_EN": 559,
|
601 |
+
"羽生田千鹤_EN": 560,
|
602 |
+
"海妮耶_EN": 561,
|
603 |
+
"霍夫曼_EN": 562,
|
604 |
+
"旅行者_EN": 563,
|
605 |
+
"佐西摩斯_EN": 564,
|
606 |
+
"鹿野奈奈_EN": 565,
|
607 |
+
"舒伯特_EN": 566,
|
608 |
+
"天叔_EN": 567,
|
609 |
+
"艾莉丝_EN": 568,
|
610 |
+
"龙二_EN": 569,
|
611 |
+
"莺儿_EN": 570,
|
612 |
+
"嘉良_EN": 571,
|
613 |
+
"珊瑚_EN": 572,
|
614 |
+
"费迪南德_EN": 573,
|
615 |
+
"言笑_EN": 574,
|
616 |
+
"一心传名刀_EN": 575,
|
617 |
+
"久利须_EN": 576,
|
618 |
+
"嘉玛_EN": 577,
|
619 |
+
"艾文_EN": 578,
|
620 |
+
"克洛琳德_EN": 579,
|
621 |
+
"丹吉尔_EN": 580,
|
622 |
+
"女士_EN": 581,
|
623 |
+
"天目十五_EN": 582,
|
624 |
+
"老孟_EN": 583,
|
625 |
+
"白老先生_EN": 584,
|
626 |
+
"舍利夫_EN": 585,
|
627 |
+
"巴达维_EN": 586,
|
628 |
+
"拉齐_EN": 587,
|
629 |
+
"长生_EN": 588,
|
630 |
+
"吴船长_EN": 589,
|
631 |
+
"艾伯特_EN": 590,
|
632 |
+
"松浦_EN": 591,
|
633 |
+
"埃泽_EN": 592,
|
634 |
+
"阿圆_EN": 593,
|
635 |
+
"阿拉夫_EN": 594,
|
636 |
+
"莫塞伊思_EN": 595,
|
637 |
+
"石头_EN": 596,
|
638 |
+
"百闻_EN": 597,
|
639 |
+
"杜吉耶_EN": 598,
|
640 |
+
"波洛_EN": 599,
|
641 |
+
"斯坦利_EN": 600,
|
642 |
+
"掇星攫辰天君_EN": 601,
|
643 |
+
"迈蒙_EN": 602,
|
644 |
+
"博易_EN": 603,
|
645 |
+
"诗筠_EN": 604,
|
646 |
+
"毗伽尔_EN": 605,
|
647 |
+
"慧心_EN": 606,
|
648 |
+
"芙卡洛斯_EN": 607,
|
649 |
+
"恶龙_EN": 608,
|
650 |
+
"小仓澪_EN": 609,
|
651 |
+
"恕筠_EN": 610,
|
652 |
+
"知易_EN": 611,
|
653 |
+
"克列门特_EN": 612,
|
654 |
+
"大慈树王_EN": 613,
|
655 |
+
"维多利亚_EN": 614,
|
656 |
+
"黑田_EN": 615,
|
657 |
+
"马姆杜_EN": 616,
|
658 |
+
"科林斯_EN": 617,
|
659 |
+
"上杉_EN": 618,
|
660 |
+
"西拉杰_EN": 619,
|
661 |
+
"宁禄_EN": 620,
|
662 |
+
"纯水精灵_EN": 621,
|
663 |
+
"常九爷_EN": 622,
|
664 |
+
"阿尔卡米_EN": 623,
|
665 |
+
"沙扎曼_EN": 624,
|
666 |
+
"田铁嘴_EN": 625,
|
667 |
+
"加萨尼_EN": 626,
|
668 |
+
"克罗索_EN": 627,
|
669 |
+
"星稀_EN": 628,
|
670 |
+
"莱斯格_EN": 629,
|
671 |
+
"阿巴图伊_EN": 630,
|
672 |
+
"埃尔欣根_EN": 631,
|
673 |
+
"阿佩普_EN": 632,
|
674 |
+
"萨赫哈蒂_EN": 633,
|
675 |
+
"洛伦佐_EN": 634,
|
676 |
+
"塔杰·拉德卡尼_EN": 635,
|
677 |
+
"泽田_EN": 636,
|
678 |
+
"安西_EN": 637,
|
679 |
+
"埃舍尔_EN": 638,
|
680 |
+
"三月七_ZH": 639,
|
681 |
+
"丹恒_ZH": 640,
|
682 |
+
"希儿_ZH": 641,
|
683 |
+
"娜塔莎_ZH": 642,
|
684 |
+
"希露瓦_ZH": 643,
|
685 |
+
"瓦尔特_ZH": 644,
|
686 |
+
"佩拉_ZH": 645,
|
687 |
+
"布洛妮娅_ZH": 646,
|
688 |
+
"虎克_ZH": 647,
|
689 |
+
"素裳_ZH": 648,
|
690 |
+
"克拉拉_ZH": 649,
|
691 |
+
"符玄_ZH": 650,
|
692 |
+
"白露_ZH": 651,
|
693 |
+
"杰帕德_ZH": 652,
|
694 |
+
"景元_ZH": 653,
|
695 |
+
"藿藿_ZH": 654,
|
696 |
+
"姬子_ZH": 655,
|
697 |
+
"穹_ZH": 656,
|
698 |
+
"星_ZH": 657,
|
699 |
+
"卡芙卡_ZH": 658,
|
700 |
+
"桂乃芬_ZH": 659,
|
701 |
+
"艾丝妲_ZH": 660,
|
702 |
+
"玲可_ZH": 661,
|
703 |
+
"彦卿_ZH": 662,
|
704 |
+
"托帕_ZH": 663,
|
705 |
+
"驭空_ZH": 664,
|
706 |
+
"浮烟_ZH": 665,
|
707 |
+
"停云_ZH": 666,
|
708 |
+
"镜流_ZH": 667,
|
709 |
+
"罗刹_ZH": 668,
|
710 |
+
"卢卡_ZH": 669,
|
711 |
+
"史瓦罗_ZH": 670,
|
712 |
+
"黑塔_ZH": 671,
|
713 |
+
"桑博_ZH": 672,
|
714 |
+
"伦纳德_ZH": 673,
|
715 |
+
"明曦_ZH": 674,
|
716 |
+
"银狼_ZH": 675,
|
717 |
+
"帕姆_ZH": 676,
|
718 |
+
"青雀_ZH": 677,
|
719 |
+
"乔瓦尼_ZH": 678,
|
720 |
+
"公输师傅_ZH": 679,
|
721 |
+
"晴霓_ZH": 680,
|
722 |
+
"螺丝咕姆_ZH": 681,
|
723 |
+
"阿兰_ZH": 682,
|
724 |
+
"奥列格_ZH": 683,
|
725 |
+
"丹枢_ZH": 684,
|
726 |
+
"尾巴_ZH": 685,
|
727 |
+
"寒鸦_ZH": 686,
|
728 |
+
"雪衣_ZH": 687,
|
729 |
+
"可可利亚_ZH": 688,
|
730 |
+
"青镞_ZH": 689,
|
731 |
+
"半夏_ZH": 690,
|
732 |
+
"银枝_ZH": 691,
|
733 |
+
"大毫_ZH": 692,
|
734 |
+
"霄翰_ZH": 693,
|
735 |
+
"信使_ZH": 694,
|
736 |
+
"费斯曼_ZH": 695,
|
737 |
+
"绿芙蓉_ZH": 696,
|
738 |
+
"金人会长_ZH": 697,
|
739 |
+
"维利特_ZH": 698,
|
740 |
+
"维尔德_ZH": 699,
|
741 |
+
"斯科特_ZH": 700,
|
742 |
+
"卡波特_ZH": 701,
|
743 |
+
"刃_ZH": 702,
|
744 |
+
"岩明_ZH": 703,
|
745 |
+
"浣溪_ZH": 704,
|
746 |
+
"三月七_JP": 705,
|
747 |
+
"丹恒_JP": 706,
|
748 |
+
"希儿_JP": 707,
|
749 |
+
"娜塔莎_JP": 708,
|
750 |
+
"希露瓦_JP": 709,
|
751 |
+
"瓦尔特_JP": 710,
|
752 |
+
"佩拉_JP": 711,
|
753 |
+
"布洛妮娅_JP": 712,
|
754 |
+
"虎克_JP": 713,
|
755 |
+
"素裳_JP": 714,
|
756 |
+
"克拉拉_JP": 715,
|
757 |
+
"符玄_JP": 716,
|
758 |
+
"白露_JP": 717,
|
759 |
+
"杰帕德_JP": 718,
|
760 |
+
"景元_JP": 719,
|
761 |
+
"藿藿_JP": 720,
|
762 |
+
"姬子_JP": 721,
|
763 |
+
"卡芙卡_JP": 722,
|
764 |
+
"穹_JP": 723,
|
765 |
+
"星_JP": 724,
|
766 |
+
"桂乃芬_JP": 725,
|
767 |
+
"艾丝妲_JP": 726,
|
768 |
+
"彦卿_JP": 727,
|
769 |
+
"玲可_JP": 728,
|
770 |
+
"托帕_JP": 729,
|
771 |
+
"驭空_JP": 730,
|
772 |
+
"浮烟_JP": 731,
|
773 |
+
"停云_JP": 732,
|
774 |
+
"镜流_JP": 733,
|
775 |
+
"罗刹_JP": 734,
|
776 |
+
"卢卡_JP": 735,
|
777 |
+
"史瓦罗_JP": 736,
|
778 |
+
"黑塔_JP": 737,
|
779 |
+
"桑博_JP": 738,
|
780 |
+
"伦纳德_JP": 739,
|
781 |
+
"明曦_JP": 740,
|
782 |
+
"银狼_JP": 741,
|
783 |
+
"帕姆_JP": 742,
|
784 |
+
"青雀_JP": 743,
|
785 |
+
"乔瓦尼_JP": 744,
|
786 |
+
"公输师傅_JP": 745,
|
787 |
+
"晴霓_JP": 746,
|
788 |
+
"螺丝咕姆_JP": 747,
|
789 |
+
"阿兰_JP": 748,
|
790 |
+
"奥列格_JP": 749,
|
791 |
+
"丹枢_JP": 750,
|
792 |
+
"尾巴_JP": 751,
|
793 |
+
"寒鸦_JP": 752,
|
794 |
+
"雪衣_JP": 753,
|
795 |
+
"可可利亚_JP": 754,
|
796 |
+
"青镞_JP": 755,
|
797 |
+
"半夏_JP": 756,
|
798 |
+
"银枝_JP": 757,
|
799 |
+
"大毫_JP": 758,
|
800 |
+
"霄翰_JP": 759,
|
801 |
+
"信使_JP": 760,
|
802 |
+
"费斯曼_JP": 761,
|
803 |
+
"绿芙蓉_JP": 762,
|
804 |
+
"金人会长_JP": 763,
|
805 |
+
"维利特_JP": 764,
|
806 |
+
"维尔德_JP": 765,
|
807 |
+
"斯科特_JP": 766,
|
808 |
+
"刃_JP": 767,
|
809 |
+
"卡波特_JP": 768,
|
810 |
+
"岩明_JP": 769,
|
811 |
+
"浣溪_JP": 770,
|
812 |
+
"净砚_JP": 771,
|
813 |
+
"紫月季_JP": 772,
|
814 |
+
"歌蒂_JP": 773,
|
815 |
+
"奇怪的云骑_JP": 774,
|
816 |
+
"幻胧_JP": 775,
|
817 |
+
"斯薇塔_JP": 776,
|
818 |
+
"隐书_JP": 777,
|
819 |
+
"三月七_EN": 778,
|
820 |
+
"丹恒_EN": 779,
|
821 |
+
"希儿_EN": 780,
|
822 |
+
"娜塔莎_EN": 781,
|
823 |
+
"希露瓦_EN": 782,
|
824 |
+
"瓦尔特_EN": 783,
|
825 |
+
"佩拉_EN": 784,
|
826 |
+
"布洛妮娅_EN": 785,
|
827 |
+
"虎克_EN": 786,
|
828 |
+
"素裳_EN": 787,
|
829 |
+
"克拉拉_EN": 788,
|
830 |
+
"符玄_EN": 789,
|
831 |
+
"白露_EN": 790,
|
832 |
+
"杰帕德_EN": 791,
|
833 |
+
"景元_EN": 792,
|
834 |
+
"藿藿_EN": 793,
|
835 |
+
"姬子_EN": 794,
|
836 |
+
"卡芙卡_EN": 795,
|
837 |
+
"穹_EN": 796,
|
838 |
+
"星_EN": 797,
|
839 |
+
"桂乃芬_EN": 798,
|
840 |
+
"艾丝妲_EN": 799,
|
841 |
+
"彦卿_EN": 800,
|
842 |
+
"玲可_EN": 801,
|
843 |
+
"托帕_EN": 802,
|
844 |
+
"驭空_EN": 803,
|
845 |
+
"浮烟_EN": 804,
|
846 |
+
"停云_EN": 805,
|
847 |
+
"镜流_EN": 806,
|
848 |
+
"罗刹_EN": 807,
|
849 |
+
"卢卡_EN": 808,
|
850 |
+
"史瓦罗_EN": 809,
|
851 |
+
"黑塔_EN": 810,
|
852 |
+
"桑博_EN": 811,
|
853 |
+
"伦纳德_EN": 812,
|
854 |
+
"明曦_EN": 813,
|
855 |
+
"银狼_EN": 814,
|
856 |
+
"帕姆_EN": 815,
|
857 |
+
"青雀_EN": 816,
|
858 |
+
"乔瓦尼_EN": 817,
|
859 |
+
"公输师傅_EN": 818,
|
860 |
+
"晴霓_EN": 819,
|
861 |
+
"螺丝咕姆_EN": 820,
|
862 |
+
"阿兰_EN": 821,
|
863 |
+
"奥列格_EN": 822,
|
864 |
+
"丹枢_EN": 823,
|
865 |
+
"尾巴_EN": 824,
|
866 |
+
"寒鸦_EN": 825,
|
867 |
+
"雪衣_EN": 826,
|
868 |
+
"可可利亚_EN": 827,
|
869 |
+
"青镞_EN": 828,
|
870 |
+
"半夏_EN": 829,
|
871 |
+
"银枝_EN": 830,
|
872 |
+
"大毫_EN": 831,
|
873 |
+
"霄翰_EN": 832,
|
874 |
+
"信使_EN": 833,
|
875 |
+
"费斯曼_EN": 834,
|
876 |
+
"绿芙蓉_EN": 835,
|
877 |
+
"金人会长_EN": 836,
|
878 |
+
"维利特_EN": 837,
|
879 |
+
"维尔德_EN": 838,
|
880 |
+
"刃_EN": 839,
|
881 |
+
"卡波特_EN": 840,
|
882 |
+
"岩明_EN": 841,
|
883 |
+
"浣溪_EN": 842,
|
884 |
+
"紫月季_EN": 843,
|
885 |
+
"幻胧_EN": 844,
|
886 |
+
"女声_EN": 845,
|
887 |
+
"陆景和": 846,
|
888 |
+
"莫弈": 847,
|
889 |
+
"左然": 848,
|
890 |
+
"夏彦": 849
|
891 |
+
}
|
892 |
+
},
|
893 |
+
"model": {
|
894 |
+
"use_spk_conditioned_encoder": true,
|
895 |
+
"use_noise_scaled_mas": true,
|
896 |
+
"use_mel_posterior_encoder": false,
|
897 |
+
"use_duration_discriminator": true,
|
898 |
+
"inter_channels": 192,
|
899 |
+
"hidden_channels": 192,
|
900 |
+
"filter_channels": 768,
|
901 |
+
"n_heads": 2,
|
902 |
+
"n_layers": 6,
|
903 |
+
"kernel_size": 3,
|
904 |
+
"p_dropout": 0.1,
|
905 |
+
"resblock": "1",
|
906 |
+
"resblock_kernel_sizes": [
|
907 |
+
3,
|
908 |
+
7,
|
909 |
+
11
|
910 |
+
],
|
911 |
+
"resblock_dilation_sizes": [
|
912 |
+
[
|
913 |
+
1,
|
914 |
+
3,
|
915 |
+
5
|
916 |
+
],
|
917 |
+
[
|
918 |
+
1,
|
919 |
+
3,
|
920 |
+
5
|
921 |
+
],
|
922 |
+
[
|
923 |
+
1,
|
924 |
+
3,
|
925 |
+
5
|
926 |
+
]
|
927 |
+
],
|
928 |
+
"upsample_rates": [
|
929 |
+
8,
|
930 |
+
8,
|
931 |
+
2,
|
932 |
+
2,
|
933 |
+
2
|
934 |
+
],
|
935 |
+
"upsample_initial_channel": 512,
|
936 |
+
"upsample_kernel_sizes": [
|
937 |
+
16,
|
938 |
+
16,
|
939 |
+
8,
|
940 |
+
2,
|
941 |
+
2
|
942 |
+
],
|
943 |
+
"n_layers_q": 3,
|
944 |
+
"use_spectral_norm": false,
|
945 |
+
"gin_channels": 512,
|
946 |
+
"slm": {
|
947 |
+
"model": "./slm/wavlm-base-plus",
|
948 |
+
"sr": 16000,
|
949 |
+
"hidden": 768,
|
950 |
+
"nlayers": 13,
|
951 |
+
"initial_channel": 64
|
952 |
+
}
|
953 |
+
},
|
954 |
+
"version": "2.3"
|
955 |
+
}
|
css/custom.css
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
#yml_code {
|
3 |
+
height: 600px;
|
4 |
+
flex-grow: inherit;
|
5 |
+
overflow-y: auto;
|
6 |
+
}
|
7 |
+
|
8 |
+
#json_code {
|
9 |
+
height: 600px;
|
10 |
+
flex-grow: inherit;
|
11 |
+
overflow-y: auto;
|
12 |
+
}
|
13 |
+
|
14 |
+
#gpu_code {
|
15 |
+
height: 300px;
|
16 |
+
flex-grow: inherit;
|
17 |
+
overflow-y: auto;
|
18 |
+
}
|
data/finetuned/configs/config.json
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"train": {
|
3 |
+
"log_interval": 200,
|
4 |
+
"eval_interval": 1000,
|
5 |
+
"seed": 42,
|
6 |
+
"epochs": 1000,
|
7 |
+
"learning_rate": 0.0002,
|
8 |
+
"betas": [
|
9 |
+
0.8,
|
10 |
+
0.99
|
11 |
+
],
|
12 |
+
"eps": 1e-09,
|
13 |
+
"batch_size": 12,
|
14 |
+
"bf16_run": false,
|
15 |
+
"lr_decay": 0.99995,
|
16 |
+
"segment_size": 16384,
|
17 |
+
"init_lr_ratio": 1,
|
18 |
+
"warmup_epochs": 0,
|
19 |
+
"c_mel": 45,
|
20 |
+
"c_kl": 1.0,
|
21 |
+
"c_commit": 100,
|
22 |
+
"skip_optimizer": true,
|
23 |
+
"freeze_YUE_bert": false,
|
24 |
+
"freeze_emo": false
|
25 |
+
},
|
26 |
+
"data": {
|
27 |
+
"training_files": "data/finetune/train.list",
|
28 |
+
"validation_files": "data/finetune/val.list",
|
29 |
+
"max_wav_value": 32768.0,
|
30 |
+
"sampling_rate": 44100,
|
31 |
+
"filter_length": 2048,
|
32 |
+
"hop_length": 512,
|
33 |
+
"win_length": 2048,
|
34 |
+
"n_mel_channels": 128,
|
35 |
+
"mel_fmin": 0.0,
|
36 |
+
"mel_fmax": null,
|
37 |
+
"add_blank": true,
|
38 |
+
"n_speakers": 1,
|
39 |
+
"cleaned_text": true,
|
40 |
+
"spk2id": {
|
41 |
+
"SPK1": 0
|
42 |
+
}
|
43 |
+
},
|
44 |
+
"model": {
|
45 |
+
"use_spk_conditioned_encoder": true,
|
46 |
+
"use_noise_scaled_mas": true,
|
47 |
+
"use_mel_posterior_encoder": false,
|
48 |
+
"use_duration_discriminator": true,
|
49 |
+
"inter_channels": 192,
|
50 |
+
"hidden_channels": 192,
|
51 |
+
"filter_channels": 768,
|
52 |
+
"n_heads": 2,
|
53 |
+
"n_layers": 6,
|
54 |
+
"kernel_size": 3,
|
55 |
+
"p_dropout": 0.1,
|
56 |
+
"resblock": "1",
|
57 |
+
"resblock_kernel_sizes": [
|
58 |
+
3,
|
59 |
+
7,
|
60 |
+
11
|
61 |
+
],
|
62 |
+
"resblock_dilation_sizes": [
|
63 |
+
[
|
64 |
+
1,
|
65 |
+
3,
|
66 |
+
5
|
67 |
+
],
|
68 |
+
[
|
69 |
+
1,
|
70 |
+
3,
|
71 |
+
5
|
72 |
+
],
|
73 |
+
[
|
74 |
+
1,
|
75 |
+
3,
|
76 |
+
5
|
77 |
+
]
|
78 |
+
],
|
79 |
+
"upsample_rates": [
|
80 |
+
8,
|
81 |
+
8,
|
82 |
+
2,
|
83 |
+
2,
|
84 |
+
2
|
85 |
+
],
|
86 |
+
"upsample_initial_channel": 512,
|
87 |
+
"upsample_kernel_sizes": [
|
88 |
+
16,
|
89 |
+
16,
|
90 |
+
8,
|
91 |
+
2,
|
92 |
+
2
|
93 |
+
],
|
94 |
+
"n_layers_q": 3,
|
95 |
+
"use_spectral_norm": false,
|
96 |
+
"gin_channels": 512,
|
97 |
+
"slm": {
|
98 |
+
"model": "./slm/wavlm-base-plus",
|
99 |
+
"sr": 16000,
|
100 |
+
"hidden": 768,
|
101 |
+
"nlayers": 13,
|
102 |
+
"initial_channel": 64
|
103 |
+
}
|
104 |
+
},
|
105 |
+
"version": "2.3"
|
106 |
+
}
|
data/finetuned/models/G_43000.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:06a5cb843b6eef268351b5c9ffe0886c9bd3ad1da07c3d96664d58e339b0cb66
|
3 |
+
size 721223374
|
data_utils.py
ADDED
@@ -0,0 +1,371 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import random
|
3 |
+
import torch
|
4 |
+
import torch.utils.data
|
5 |
+
from tqdm import tqdm
|
6 |
+
from tools.log import logger
|
7 |
+
import commons
|
8 |
+
from mel_processing import spectrogram_torch, mel_spectrogram_torch
|
9 |
+
from utils import load_wav_to_torch, load_filepaths_and_text
|
10 |
+
from text import cleaned_text_to_sequence
|
11 |
+
from config import config
|
12 |
+
|
13 |
+
"""Multi speaker version"""
|
14 |
+
|
15 |
+
|
16 |
+
class TextAudioSpeakerLoader(torch.utils.data.Dataset):
|
17 |
+
"""
|
18 |
+
1) loads audio, speaker_id, text pairs
|
19 |
+
2) normalizes text and converts them to sequences of integers
|
20 |
+
3) computes spectrograms from audio files.
|
21 |
+
"""
|
22 |
+
|
23 |
+
def __init__(self, audiopaths_sid_text, hparams):
|
24 |
+
self.audiopaths_sid_text = load_filepaths_and_text(audiopaths_sid_text)
|
25 |
+
self.max_wav_value = hparams.max_wav_value
|
26 |
+
self.sampling_rate = hparams.sampling_rate
|
27 |
+
self.filter_length = hparams.filter_length
|
28 |
+
self.hop_length = hparams.hop_length
|
29 |
+
self.win_length = hparams.win_length
|
30 |
+
self.sampling_rate = hparams.sampling_rate
|
31 |
+
self.spk_map = hparams.spk2id
|
32 |
+
self.hparams = hparams
|
33 |
+
|
34 |
+
self.use_mel_spec_posterior = getattr(
|
35 |
+
hparams, "use_mel_posterior_encoder", False
|
36 |
+
)
|
37 |
+
if self.use_mel_spec_posterior:
|
38 |
+
self.n_mel_channels = getattr(hparams, "n_mel_channels", 80)
|
39 |
+
|
40 |
+
self.cleaned_text = getattr(hparams, "cleaned_text", False)
|
41 |
+
|
42 |
+
self.add_blank = hparams.add_blank
|
43 |
+
self.min_text_len = getattr(hparams, "min_text_len", 1)
|
44 |
+
self.max_text_len = getattr(hparams, "max_text_len", 384)
|
45 |
+
|
46 |
+
random.seed(1234)
|
47 |
+
random.shuffle(self.audiopaths_sid_text)
|
48 |
+
self._filter()
|
49 |
+
|
50 |
+
def _filter(self):
|
51 |
+
"""
|
52 |
+
Filter text & store spec lengths
|
53 |
+
"""
|
54 |
+
# Store spectrogram lengths for Bucketing
|
55 |
+
# wav_length ~= file_size / (wav_channels * Bytes per dim) = file_size / (1 * 2)
|
56 |
+
# spec_length = wav_length // hop_length
|
57 |
+
|
58 |
+
audiopaths_sid_text_new = []
|
59 |
+
lengths = []
|
60 |
+
skipped = 0
|
61 |
+
logger.info("Init dataset...")
|
62 |
+
for _id, spk, language, text, phones, tone, word2ph in tqdm(
|
63 |
+
self.audiopaths_sid_text
|
64 |
+
):
|
65 |
+
audiopath = f"{_id}"
|
66 |
+
if self.min_text_len <= len(phones) and len(phones) <= self.max_text_len:
|
67 |
+
phones = phones.split(" ")
|
68 |
+
tone = [int(i) for i in tone.split(" ")]
|
69 |
+
word2ph = [int(i) for i in word2ph.split(" ")]
|
70 |
+
audiopaths_sid_text_new.append(
|
71 |
+
[audiopath, spk, language, text, phones, tone, word2ph]
|
72 |
+
)
|
73 |
+
lengths.append(os.path.getsize(audiopath) //
|
74 |
+
(2 * self.hop_length))
|
75 |
+
else:
|
76 |
+
skipped += 1
|
77 |
+
logger.info(
|
78 |
+
"skipped: "
|
79 |
+
+ str(skipped)
|
80 |
+
+ ", total: "
|
81 |
+
+ str(len(self.audiopaths_sid_text))
|
82 |
+
)
|
83 |
+
self.audiopaths_sid_text = audiopaths_sid_text_new
|
84 |
+
self.lengths = lengths
|
85 |
+
|
86 |
+
def get_audio_text_speaker_pair(self, audiopath_sid_text):
|
87 |
+
# separate filename, speaker_id and text
|
88 |
+
audiopath, sid, language, text, phones, tone, word2ph = audiopath_sid_text
|
89 |
+
|
90 |
+
phones, tone, language = self.get_text(
|
91 |
+
text, word2ph, phones, tone, language, audiopath
|
92 |
+
)
|
93 |
+
|
94 |
+
spec, wav = self.get_audio(audiopath)
|
95 |
+
sid = torch.LongTensor([int(self.spk_map[sid])])
|
96 |
+
|
97 |
+
return (phones, spec, wav, sid, tone, language)
|
98 |
+
|
99 |
+
def get_audio(self, filename):
|
100 |
+
audio, sampling_rate = load_wav_to_torch(filename)
|
101 |
+
if sampling_rate != self.sampling_rate:
|
102 |
+
raise ValueError(
|
103 |
+
"{} {} SR doesn't match target {} SR".format(
|
104 |
+
filename, sampling_rate, self.sampling_rate
|
105 |
+
)
|
106 |
+
)
|
107 |
+
audio_norm = audio / self.max_wav_value
|
108 |
+
audio_norm = audio_norm.unsqueeze(0)
|
109 |
+
spec_filename = filename.replace(".wav", ".spec.pt")
|
110 |
+
if self.use_mel_spec_posterior:
|
111 |
+
spec_filename = spec_filename.replace(".spec.pt", ".mel.pt")
|
112 |
+
try:
|
113 |
+
spec = torch.load(spec_filename)
|
114 |
+
except:
|
115 |
+
if self.use_mel_spec_posterior:
|
116 |
+
spec = mel_spectrogram_torch(
|
117 |
+
audio_norm,
|
118 |
+
self.filter_length,
|
119 |
+
self.n_mel_channels,
|
120 |
+
self.sampling_rate,
|
121 |
+
self.hop_length,
|
122 |
+
self.win_length,
|
123 |
+
self.hparams.mel_fmin,
|
124 |
+
self.hparams.mel_fmax,
|
125 |
+
center=False,
|
126 |
+
)
|
127 |
+
else:
|
128 |
+
spec = spectrogram_torch(
|
129 |
+
audio_norm,
|
130 |
+
self.filter_length,
|
131 |
+
self.sampling_rate,
|
132 |
+
self.hop_length,
|
133 |
+
self.win_length,
|
134 |
+
center=False,
|
135 |
+
)
|
136 |
+
spec = torch.squeeze(spec, 0)
|
137 |
+
if config.train_ms_config.spec_cache:
|
138 |
+
torch.save(spec, spec_filename)
|
139 |
+
return spec, audio_norm
|
140 |
+
|
141 |
+
def get_text(self, text, word2ph, phone, tone, language_str, wav_path):
|
142 |
+
phone, tone, language = cleaned_text_to_sequence(
|
143 |
+
phone, tone, language_str)
|
144 |
+
if self.add_blank:
|
145 |
+
phone = commons.intersperse(phone, 0)
|
146 |
+
tone = commons.intersperse(tone, 0)
|
147 |
+
language = commons.intersperse(language, 0)
|
148 |
+
for i in range(len(word2ph)):
|
149 |
+
word2ph[i] = word2ph[i] * 2
|
150 |
+
word2ph[0] += 1
|
151 |
+
|
152 |
+
phone = torch.LongTensor(phone)
|
153 |
+
tone = torch.LongTensor(tone)
|
154 |
+
language = torch.LongTensor(language)
|
155 |
+
return phone, tone, language
|
156 |
+
|
157 |
+
def get_sid(self, sid):
|
158 |
+
sid = torch.LongTensor([int(sid)])
|
159 |
+
return sid
|
160 |
+
|
161 |
+
def __getitem__(self, index):
|
162 |
+
return self.get_audio_text_speaker_pair(self.audiopaths_sid_text[index])
|
163 |
+
|
164 |
+
def __len__(self):
|
165 |
+
return len(self.audiopaths_sid_text)
|
166 |
+
|
167 |
+
|
168 |
+
class TextAudioSpeakerCollate:
|
169 |
+
"""Zero-pads model inputs and targets"""
|
170 |
+
|
171 |
+
def __init__(self, return_ids=False):
|
172 |
+
self.return_ids = return_ids
|
173 |
+
|
174 |
+
def __call__(self, batch):
|
175 |
+
"""Collate's training batch from normalized text, audio and speaker identities
|
176 |
+
PARAMS
|
177 |
+
------
|
178 |
+
batch: [text_normalized, spec_normalized, wav_normalized, sid]
|
179 |
+
"""
|
180 |
+
# Right zero-pad all one-hot text sequences to max input length
|
181 |
+
_, ids_sorted_decreasing = torch.sort(
|
182 |
+
torch.LongTensor([x[1].size(1) for x in batch]), dim=0, descending=True
|
183 |
+
)
|
184 |
+
|
185 |
+
max_text_len = max([len(x[0]) for x in batch])
|
186 |
+
max_spec_len = max([x[1].size(1) for x in batch])
|
187 |
+
max_wav_len = max([x[2].size(1) for x in batch])
|
188 |
+
|
189 |
+
text_lengths = torch.LongTensor(len(batch))
|
190 |
+
spec_lengths = torch.LongTensor(len(batch))
|
191 |
+
wav_lengths = torch.LongTensor(len(batch))
|
192 |
+
sid = torch.LongTensor(len(batch))
|
193 |
+
|
194 |
+
text_padded = torch.LongTensor(len(batch), max_text_len)
|
195 |
+
tone_padded = torch.LongTensor(len(batch), max_text_len)
|
196 |
+
language_padded = torch.LongTensor(len(batch), max_text_len)
|
197 |
+
|
198 |
+
spec_padded = torch.FloatTensor(
|
199 |
+
len(batch), batch[0][1].size(0), max_spec_len)
|
200 |
+
wav_padded = torch.FloatTensor(len(batch), 1, max_wav_len)
|
201 |
+
text_padded.zero_()
|
202 |
+
tone_padded.zero_()
|
203 |
+
language_padded.zero_()
|
204 |
+
spec_padded.zero_()
|
205 |
+
wav_padded.zero_()
|
206 |
+
|
207 |
+
for i in range(len(ids_sorted_decreasing)):
|
208 |
+
row = batch[ids_sorted_decreasing[i]]
|
209 |
+
|
210 |
+
text = row[0]
|
211 |
+
text_padded[i, : text.size(0)] = text
|
212 |
+
text_lengths[i] = text.size(0)
|
213 |
+
|
214 |
+
spec = row[1]
|
215 |
+
spec_padded[i, :, : spec.size(1)] = spec
|
216 |
+
spec_lengths[i] = spec.size(1)
|
217 |
+
|
218 |
+
wav = row[2]
|
219 |
+
wav_padded[i, :, : wav.size(1)] = wav
|
220 |
+
wav_lengths[i] = wav.size(1)
|
221 |
+
|
222 |
+
sid[i] = row[3]
|
223 |
+
|
224 |
+
tone = row[4]
|
225 |
+
tone_padded[i, : tone.size(0)] = tone
|
226 |
+
|
227 |
+
language = row[5]
|
228 |
+
language_padded[i, : language.size(0)] = language
|
229 |
+
|
230 |
+
return (
|
231 |
+
text_padded,
|
232 |
+
text_lengths,
|
233 |
+
spec_padded,
|
234 |
+
spec_lengths,
|
235 |
+
wav_padded,
|
236 |
+
wav_lengths,
|
237 |
+
sid,
|
238 |
+
tone_padded,
|
239 |
+
language_padded,
|
240 |
+
)
|
241 |
+
|
242 |
+
|
243 |
+
class DistributedBucketSampler(torch.utils.data.distributed.DistributedSampler):
|
244 |
+
"""
|
245 |
+
Maintain similar input lengths in a batch.
|
246 |
+
Length groups are specified by boundaries.
|
247 |
+
Ex) boundaries = [b1, b2, b3] -> any batch is included either {x | b1 < length(x) <=b2} or {x | b2 < length(x) <= b3}.
|
248 |
+
|
249 |
+
It removes samples which are not included in the boundaries.
|
250 |
+
Ex) boundaries = [b1, b2, b3] -> any x s.t. length(x) <= b1 or length(x) > b3 are discarded.
|
251 |
+
"""
|
252 |
+
|
253 |
+
def __init__(
|
254 |
+
self,
|
255 |
+
dataset,
|
256 |
+
batch_size,
|
257 |
+
boundaries,
|
258 |
+
num_replicas=None,
|
259 |
+
rank=None,
|
260 |
+
shuffle=True,
|
261 |
+
):
|
262 |
+
super().__init__(dataset, num_replicas=num_replicas, rank=rank, shuffle=shuffle)
|
263 |
+
self.lengths = dataset.lengths
|
264 |
+
self.batch_size = batch_size
|
265 |
+
self.boundaries = boundaries
|
266 |
+
|
267 |
+
self.buckets, self.num_samples_per_bucket = self._create_buckets()
|
268 |
+
self.total_size = sum(self.num_samples_per_bucket)
|
269 |
+
self.num_samples = self.total_size // self.num_replicas
|
270 |
+
|
271 |
+
def _create_buckets(self):
|
272 |
+
buckets = [[] for _ in range(len(self.boundaries) - 1)]
|
273 |
+
for i in range(len(self.lengths)):
|
274 |
+
length = self.lengths[i]
|
275 |
+
idx_bucket = self._bisect(length)
|
276 |
+
if idx_bucket != -1:
|
277 |
+
buckets[idx_bucket].append(i)
|
278 |
+
|
279 |
+
try:
|
280 |
+
for i in range(len(buckets) - 1, 0, -1):
|
281 |
+
if len(buckets[i]) == 0:
|
282 |
+
buckets.pop(i)
|
283 |
+
self.boundaries.pop(i + 1)
|
284 |
+
assert all(len(bucket) > 0 for bucket in buckets)
|
285 |
+
# When one bucket is not traversed
|
286 |
+
except Exception as e:
|
287 |
+
print("Bucket warning ", e)
|
288 |
+
for i in range(len(buckets) - 1, -1, -1):
|
289 |
+
if len(buckets[i]) == 0:
|
290 |
+
buckets.pop(i)
|
291 |
+
self.boundaries.pop(i + 1)
|
292 |
+
|
293 |
+
num_samples_per_bucket = []
|
294 |
+
for i in range(len(buckets)):
|
295 |
+
len_bucket = len(buckets[i])
|
296 |
+
total_batch_size = self.num_replicas * self.batch_size
|
297 |
+
rem = (
|
298 |
+
total_batch_size - (len_bucket % total_batch_size)
|
299 |
+
) % total_batch_size
|
300 |
+
num_samples_per_bucket.append(len_bucket + rem)
|
301 |
+
return buckets, num_samples_per_bucket
|
302 |
+
|
303 |
+
def __iter__(self):
|
304 |
+
# deterministically shuffle based on epoch
|
305 |
+
g = torch.Generator()
|
306 |
+
g.manual_seed(self.epoch)
|
307 |
+
|
308 |
+
indices = []
|
309 |
+
if self.shuffle:
|
310 |
+
for bucket in self.buckets:
|
311 |
+
indices.append(torch.randperm(
|
312 |
+
len(bucket), generator=g).tolist())
|
313 |
+
else:
|
314 |
+
for bucket in self.buckets:
|
315 |
+
indices.append(list(range(len(bucket))))
|
316 |
+
|
317 |
+
batches = []
|
318 |
+
for i in range(len(self.buckets)):
|
319 |
+
bucket = self.buckets[i]
|
320 |
+
len_bucket = len(bucket)
|
321 |
+
if len_bucket == 0:
|
322 |
+
continue
|
323 |
+
ids_bucket = indices[i]
|
324 |
+
num_samples_bucket = self.num_samples_per_bucket[i]
|
325 |
+
|
326 |
+
# add extra samples to make it evenly divisible
|
327 |
+
rem = num_samples_bucket - len_bucket
|
328 |
+
ids_bucket = (
|
329 |
+
ids_bucket
|
330 |
+
+ ids_bucket * (rem // len_bucket)
|
331 |
+
+ ids_bucket[: (rem % len_bucket)]
|
332 |
+
)
|
333 |
+
|
334 |
+
# subsample
|
335 |
+
ids_bucket = ids_bucket[self.rank:: self.num_replicas]
|
336 |
+
|
337 |
+
# batching
|
338 |
+
for j in range(len(ids_bucket) // self.batch_size):
|
339 |
+
batch = [
|
340 |
+
bucket[idx]
|
341 |
+
for idx in ids_bucket[
|
342 |
+
j * self.batch_size: (j + 1) * self.batch_size
|
343 |
+
]
|
344 |
+
]
|
345 |
+
batches.append(batch)
|
346 |
+
|
347 |
+
if self.shuffle:
|
348 |
+
batch_ids = torch.randperm(len(batches), generator=g).tolist()
|
349 |
+
batches = [batches[i] for i in batch_ids]
|
350 |
+
self.batches = batches
|
351 |
+
|
352 |
+
assert len(self.batches) * self.batch_size == self.num_samples
|
353 |
+
return iter(self.batches)
|
354 |
+
|
355 |
+
def _bisect(self, x, lo=0, hi=None):
|
356 |
+
if hi is None:
|
357 |
+
hi = len(self.boundaries) - 1
|
358 |
+
|
359 |
+
if hi > lo:
|
360 |
+
mid = (hi + lo) // 2
|
361 |
+
if self.boundaries[mid] < x and x <= self.boundaries[mid + 1]:
|
362 |
+
return mid
|
363 |
+
elif x <= self.boundaries[mid]:
|
364 |
+
return self._bisect(x, lo, mid)
|
365 |
+
else:
|
366 |
+
return self._bisect(x, mid + 1, hi)
|
367 |
+
else:
|
368 |
+
return -1
|
369 |
+
|
370 |
+
def __len__(self):
|
371 |
+
return self.num_samples // self.batch_size
|
default_config.yml
ADDED
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 全局配置
|
2 |
+
# 对于希望在同一时间使用多个配置文件的情况,例如两个GPU同时跑两个训练集:通过环境变量指定配置文件,不指定则默认为./config.yml
|
3 |
+
|
4 |
+
# 拟提供通用路径配置,统一存放数据,避免数据放得很乱
|
5 |
+
# 每个数据集与其对应的模型存放至统一路径下,后续所有的路径配置均为相对于datasetPath的路径
|
6 |
+
# 不填或者填空则路径为相对于项目根目录的路径
|
7 |
+
dataset_path: "Data/"
|
8 |
+
|
9 |
+
# 模型镜像源,默认huggingface,使用openi镜像源需指定openi_token
|
10 |
+
mirror: ""
|
11 |
+
openi_token: "" # openi token
|
12 |
+
|
13 |
+
# resample 音频重采样配置
|
14 |
+
# 注意, “:” 后需要加空格
|
15 |
+
resample:
|
16 |
+
# 目标重采样率
|
17 |
+
sampling_rate: 44100
|
18 |
+
# 音频文件输入路径,重采样会将该路径下所有.wav音频文件重采样
|
19 |
+
# 请填入相对于datasetPath的相对路径
|
20 |
+
in_dir: "audios/raw" # 相对于根目录的路径为 /datasetPath/in_dir
|
21 |
+
# 音频文件重采样后输出路径
|
22 |
+
out_dir: "audios/wavs"
|
23 |
+
|
24 |
+
|
25 |
+
# preprocess_text 数据集预处理相关配置
|
26 |
+
# 注意, “:” 后需要加空格
|
27 |
+
preprocess_text:
|
28 |
+
# 原始文本文件路径,文本格式应为{wav_path}|{speaker_name}|{language}|{text}。
|
29 |
+
transcription_path: "filelists/你的数据集文本.list"
|
30 |
+
# 数据清洗后文本路径,可以不填。不填则将在原始文本目录生成
|
31 |
+
cleaned_path: ""
|
32 |
+
# 训练集路径
|
33 |
+
train_path: "filelists/train.list"
|
34 |
+
# 验证集路径
|
35 |
+
val_path: "filelists/val.list"
|
36 |
+
# 配置文件路径
|
37 |
+
config_path: "config.json"
|
38 |
+
# 每个语言的验证集条数
|
39 |
+
val_per_lang: 4
|
40 |
+
# 验证集最大条数,多于的会被截断并放到训练集中
|
41 |
+
max_val_total: 12
|
42 |
+
# 是否进行数据清洗
|
43 |
+
clean: true
|
44 |
+
|
45 |
+
|
46 |
+
# bert_gen 相关配置
|
47 |
+
# 注意, “:” 后需要加空格
|
48 |
+
bert_gen:
|
49 |
+
# 训练数据集配置文件路径
|
50 |
+
config_path: "config.json"
|
51 |
+
# 并行数
|
52 |
+
num_processes: 4
|
53 |
+
# 使用设备:可选项 "cuda" 显卡推理,"cpu" cpu推理
|
54 |
+
# 该选项同时决定了get_bert_feature的默认设备
|
55 |
+
device: "cuda"
|
56 |
+
# 使用多卡推理
|
57 |
+
use_multi_device: false
|
58 |
+
|
59 |
+
# emo_gen 相关配置
|
60 |
+
# 注意, “:” 后需要加空格
|
61 |
+
emo_gen:
|
62 |
+
# 训练数据集配置文件路径
|
63 |
+
config_path: "config.json"
|
64 |
+
# 并行数
|
65 |
+
num_processes: 4
|
66 |
+
# 使用设备:可选项 "cuda" 显卡推理,"cpu" cpu推理
|
67 |
+
device: "cuda"
|
68 |
+
# 使用多卡推理
|
69 |
+
use_multi_device: false
|
70 |
+
|
71 |
+
# train 训练配置
|
72 |
+
# 注意, “:” 后需要加空格
|
73 |
+
train_ms:
|
74 |
+
env:
|
75 |
+
MASTER_ADDR: "localhost"
|
76 |
+
MASTER_PORT: 10086
|
77 |
+
WORLD_SIZE: 1
|
78 |
+
LOCAL_RANK: 0
|
79 |
+
RANK: 0
|
80 |
+
# 可以填写任意名的环境变量
|
81 |
+
# THE_ENV_VAR_YOU_NEED_TO_USE: "1234567"
|
82 |
+
# 底模设置
|
83 |
+
base:
|
84 |
+
use_base_model: false
|
85 |
+
repo_id: "Stardust_minus/Bert-VITS2"
|
86 |
+
model_image: "Bert-VITS2_2.3底模" # openi网页的模型名
|
87 |
+
# 训练模型存储目录:与旧版本的区别,原先数据集是存放在logs/model_name下的,现在改为统一存放在Data/你的数据集/models下
|
88 |
+
model: "models"
|
89 |
+
# 配置文件路径
|
90 |
+
config_path: "config.json"
|
91 |
+
# 训练使用的worker,不建议超过CPU核心数
|
92 |
+
num_workers: 16
|
93 |
+
# 关闭此项可以节约接近70%的磁盘空间,但是可能导致实际训练速度变慢和更高的CPU使用率。
|
94 |
+
spec_cache: False
|
95 |
+
# 保存的检查点数量,多于此数目的权重会被删除来节省空间。
|
96 |
+
keep_ckpts: 8
|
97 |
+
|
98 |
+
|
99 |
+
# webui webui配置
|
100 |
+
# 注意, “:” 后需要加空格
|
101 |
+
webui:
|
102 |
+
# 推理设备
|
103 |
+
device: "cuda"
|
104 |
+
# 模型路径
|
105 |
+
model: "models/G_8000.pth"
|
106 |
+
# 配置文件路径
|
107 |
+
config_path: "config.json"
|
108 |
+
# 端口号
|
109 |
+
port: 7860
|
110 |
+
# 是否公开部署,对外网开放
|
111 |
+
share: false
|
112 |
+
# 是否开启debug模式
|
113 |
+
debug: false
|
114 |
+
# 语种识别库,可选langid, fastlid
|
115 |
+
language_identification_library: "langid"
|
116 |
+
|
117 |
+
|
118 |
+
# server-fastapi配置
|
119 |
+
# 注意, “:” 后需要加空格
|
120 |
+
# 注意,本配置下的所有配置均为相对于根目录的路径
|
121 |
+
server:
|
122 |
+
# 端口号
|
123 |
+
port: 5000
|
124 |
+
# 模型默认使用设备:但是当前并没有实现这个配置。
|
125 |
+
device: "cuda"
|
126 |
+
# 需要加载的所有模型的配置,可以填多个模型,也可以不填模型,等网页成功后手动加载模型
|
127 |
+
# 不加载模型的配置格式:删除默认给的两个模型配置,给models赋值 [ ],也就是空列表。参考模型2的speakers 即 models: [ ]
|
128 |
+
# 注意,所有模型都必须正确配置model与config的路径,空路径会导致加载错误。
|
129 |
+
# 也可以不填模型,等网页加载成功后手动填写models。
|
130 |
+
models:
|
131 |
+
- # 模型的路径
|
132 |
+
model: ""
|
133 |
+
# 模型config.json的路径
|
134 |
+
config: ""
|
135 |
+
# 模型使用设备,若填写则会覆盖默认配置
|
136 |
+
device: "cuda"
|
137 |
+
# 模型默认使用的语言
|
138 |
+
language: "HAKKA"
|
139 |
+
# 模型人物默认参数
|
140 |
+
# 不必填写所有人物,不填的使用默认值
|
141 |
+
# 暂时不用填写,当前尚未实现按人区分配置
|
142 |
+
speakers:
|
143 |
+
- speaker: "科比"
|
144 |
+
sdp_ratio: 0.2
|
145 |
+
noise_scale: 0.6
|
146 |
+
noise_scale_w: 0.8
|
147 |
+
length_scale: 1
|
148 |
+
- speaker: "五条悟"
|
149 |
+
sdp_ratio: 0.3
|
150 |
+
noise_scale: 0.7
|
151 |
+
noise_scale_w: 0.8
|
152 |
+
length_scale: 0.5
|
153 |
+
- speaker: "安倍晋三"
|
154 |
+
sdp_ratio: 0.2
|
155 |
+
noise_scale: 0.6
|
156 |
+
noise_scale_w: 0.8
|
157 |
+
length_scale: 1.2
|
158 |
+
- # 模型的路径
|
159 |
+
model: ""
|
160 |
+
# 模型config.json的路径
|
161 |
+
config: ""
|
162 |
+
# 模型使用设备,若填写则会覆盖默认配置
|
163 |
+
device: "cpu"
|
164 |
+
# 模型默认使用的语言
|
165 |
+
language: "JP"
|
166 |
+
# 模型人物默认参数
|
167 |
+
# 不必填写所有人物,不填的使用默认值
|
168 |
+
speakers: [ ] # 也可以不填
|
169 |
+
|
170 |
+
# 百度翻译开放平台 api配置
|
171 |
+
# api接入文档 https://api.fanyi.baidu.com/doc/21
|
172 |
+
# 请不要在github等网站公开分享你的app id 与 key
|
173 |
+
translate:
|
174 |
+
# 你的APPID
|
175 |
+
"app_key": ""
|
176 |
+
# 你的密钥
|
177 |
+
"secret_key": ""
|
emotional/clap-htsat-fused/.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
emotional/clap-htsat-fused/README.md
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
---
|
4 |
+
# Model card for CLAP
|
5 |
+
|
6 |
+
Model card for CLAP: Contrastive Language-Audio Pretraining
|
7 |
+
|
8 |
+
![clap_image](https://s3.amazonaws.com/moonup/production/uploads/1678811100805-62441d1d9fdefb55a0b7d12c.png)
|
9 |
+
|
10 |
+
|
11 |
+
# Table of Contents
|
12 |
+
|
13 |
+
0. [TL;DR](#TL;DR)
|
14 |
+
1. [Model Details](#model-details)
|
15 |
+
2. [Usage](#usage)
|
16 |
+
3. [Uses](#uses)
|
17 |
+
4. [Citation](#citation)
|
18 |
+
|
19 |
+
# TL;DR
|
20 |
+
|
21 |
+
The abstract of the paper states that:
|
22 |
+
|
23 |
+
> Contrastive learning has shown remarkable success in the field of multimodal representation learning. In this paper, we propose a pipeline of contrastive language-audio pretraining to develop an audio representation by combining audio data with natural language descriptions. To accomplish this target, we first release LAION-Audio-630K, a large collection of 633,526 audio-text pairs from different data sources. Second, we construct a contrastive language-audio pretraining model by considering different audio encoders and text encoders. We incorporate the feature fusion mechanism and keyword-to-caption augmentation into the model design to further enable the model to process audio inputs of variable lengths and enhance the performance. Third, we perform comprehensive experiments to evaluate our model across three tasks: text-to-audio retrieval, zero-shot audio classification, and supervised audio classification. The results demonstrate that our model achieves superior performance in text-to-audio retrieval task. In audio classification tasks, the model achieves state-of-the-art performance in the zero-shot setting and is able to obtain performance comparable to models' results in the non-zero-shot setting. LAION-Audio-630K and the proposed model are both available to the public.
|
24 |
+
|
25 |
+
|
26 |
+
# Usage
|
27 |
+
|
28 |
+
You can use this model for zero shot audio classification or extracting audio and/or textual features.
|
29 |
+
|
30 |
+
# Uses
|
31 |
+
|
32 |
+
## Perform zero-shot audio classification
|
33 |
+
|
34 |
+
### Using `pipeline`
|
35 |
+
|
36 |
+
```python
|
37 |
+
from datasets import load_dataset
|
38 |
+
from transformers import pipeline
|
39 |
+
|
40 |
+
dataset = load_dataset("ashraq/esc50")
|
41 |
+
audio = dataset["train"]["audio"][-1]["array"]
|
42 |
+
|
43 |
+
audio_classifier = pipeline(task="zero-shot-audio-classification", model="laion/clap-htsat-fused")
|
44 |
+
output = audio_classifier(audio, candidate_labels=["Sound of a dog", "Sound of vaccum cleaner"])
|
45 |
+
print(output)
|
46 |
+
>>> [{"score": 0.999, "label": "Sound of a dog"}, {"score": 0.001, "label": "Sound of vaccum cleaner"}]
|
47 |
+
```
|
48 |
+
|
49 |
+
## Run the model:
|
50 |
+
|
51 |
+
You can also get the audio and text embeddings using `ClapModel`
|
52 |
+
|
53 |
+
### Run the model on CPU:
|
54 |
+
|
55 |
+
```python
|
56 |
+
from datasets import load_dataset
|
57 |
+
from transformers import ClapModel, ClapProcessor
|
58 |
+
|
59 |
+
librispeech_dummy = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
60 |
+
audio_sample = librispeech_dummy[0]
|
61 |
+
|
62 |
+
model = ClapModel.from_pretrained("laion/clap-htsat-fused")
|
63 |
+
processor = ClapProcessor.from_pretrained("laion/clap-htsat-fused")
|
64 |
+
|
65 |
+
inputs = processor(audios=audio_sample["audio"]["array"], return_tensors="pt")
|
66 |
+
audio_embed = model.get_audio_features(**inputs)
|
67 |
+
```
|
68 |
+
|
69 |
+
### Run the model on GPU:
|
70 |
+
|
71 |
+
```python
|
72 |
+
from datasets import load_dataset
|
73 |
+
from transformers import ClapModel, ClapProcessor
|
74 |
+
|
75 |
+
librispeech_dummy = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
76 |
+
audio_sample = librispeech_dummy[0]
|
77 |
+
|
78 |
+
model = ClapModel.from_pretrained("laion/clap-htsat-fused").to(0)
|
79 |
+
processor = ClapProcessor.from_pretrained("laion/clap-htsat-fused")
|
80 |
+
|
81 |
+
inputs = processor(audios=audio_sample["audio"]["array"], return_tensors="pt").to(0)
|
82 |
+
audio_embed = model.get_audio_features(**inputs)
|
83 |
+
```
|
84 |
+
|
85 |
+
|
86 |
+
# Citation
|
87 |
+
|
88 |
+
If you are using this model for your work, please consider citing the original paper:
|
89 |
+
```
|
90 |
+
@misc{https://doi.org/10.48550/arxiv.2211.06687,
|
91 |
+
doi = {10.48550/ARXIV.2211.06687},
|
92 |
+
|
93 |
+
url = {https://arxiv.org/abs/2211.06687},
|
94 |
+
|
95 |
+
author = {Wu, Yusong and Chen, Ke and Zhang, Tianyu and Hui, Yuchen and Berg-Kirkpatrick, Taylor and Dubnov, Shlomo},
|
96 |
+
|
97 |
+
keywords = {Sound (cs.SD), Audio and Speech Processing (eess.AS), FOS: Computer and information sciences, FOS: Computer and information sciences, FOS: Electrical engineering, electronic engineering, information engineering, FOS: Electrical engineering, electronic engineering, information engineering},
|
98 |
+
|
99 |
+
title = {Large-scale Contrastive Language-Audio Pretraining with Feature Fusion and Keyword-to-Caption Augmentation},
|
100 |
+
|
101 |
+
publisher = {arXiv},
|
102 |
+
|
103 |
+
year = {2022},
|
104 |
+
|
105 |
+
copyright = {Creative Commons Attribution 4.0 International}
|
106 |
+
}
|
107 |
+
```
|
emotional/clap-htsat-fused/config.json
ADDED
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_commit_hash": null,
|
3 |
+
"architectures": [
|
4 |
+
"ClapModel"
|
5 |
+
],
|
6 |
+
"audio_config": {
|
7 |
+
"_name_or_path": "",
|
8 |
+
"add_cross_attention": false,
|
9 |
+
"aff_block_r": 4,
|
10 |
+
"architectures": null,
|
11 |
+
"attention_probs_dropout_prob": 0.0,
|
12 |
+
"bad_words_ids": null,
|
13 |
+
"begin_suppress_tokens": null,
|
14 |
+
"bos_token_id": null,
|
15 |
+
"chunk_size_feed_forward": 0,
|
16 |
+
"cross_attention_hidden_size": null,
|
17 |
+
"decoder_start_token_id": null,
|
18 |
+
"depths": [
|
19 |
+
2,
|
20 |
+
2,
|
21 |
+
6,
|
22 |
+
2
|
23 |
+
],
|
24 |
+
"diversity_penalty": 0.0,
|
25 |
+
"do_sample": false,
|
26 |
+
"drop_path_rate": 0.0,
|
27 |
+
"early_stopping": false,
|
28 |
+
"enable_fusion": true,
|
29 |
+
"enable_patch_fusion": true,
|
30 |
+
"enable_patch_layer_norm": true,
|
31 |
+
"encoder_no_repeat_ngram_size": 0,
|
32 |
+
"eos_token_id": null,
|
33 |
+
"exponential_decay_length_penalty": null,
|
34 |
+
"finetuning_task": null,
|
35 |
+
"flatten_patch_embeds": true,
|
36 |
+
"forced_bos_token_id": null,
|
37 |
+
"forced_eos_token_id": null,
|
38 |
+
"fusion_num_hidden_layers": 2,
|
39 |
+
"fusion_type": null,
|
40 |
+
"hidden_act": "gelu",
|
41 |
+
"hidden_dropout_prob": 0.1,
|
42 |
+
"hidden_size": 768,
|
43 |
+
"id2label": {
|
44 |
+
"0": "LABEL_0",
|
45 |
+
"1": "LABEL_1"
|
46 |
+
},
|
47 |
+
"initializer_factor": 1.0,
|
48 |
+
"is_decoder": false,
|
49 |
+
"is_encoder_decoder": false,
|
50 |
+
"label2id": {
|
51 |
+
"LABEL_0": 0,
|
52 |
+
"LABEL_1": 1
|
53 |
+
},
|
54 |
+
"layer_norm_eps": 1e-05,
|
55 |
+
"length_penalty": 1.0,
|
56 |
+
"max_length": 20,
|
57 |
+
"min_length": 0,
|
58 |
+
"mlp_ratio": 4.0,
|
59 |
+
"model_type": "clap_audio_model",
|
60 |
+
"no_repeat_ngram_size": 0,
|
61 |
+
"num_attention_heads": [
|
62 |
+
4,
|
63 |
+
8,
|
64 |
+
16,
|
65 |
+
32
|
66 |
+
],
|
67 |
+
"num_beam_groups": 1,
|
68 |
+
"num_beams": 1,
|
69 |
+
"num_classes": 527,
|
70 |
+
"num_hidden_layers": 4,
|
71 |
+
"num_mel_bins": 64,
|
72 |
+
"num_return_sequences": 1,
|
73 |
+
"output_attentions": false,
|
74 |
+
"output_hidden_states": false,
|
75 |
+
"output_scores": false,
|
76 |
+
"pad_token_id": null,
|
77 |
+
"patch_embed_input_channels": 1,
|
78 |
+
"patch_embeds_hidden_size": 96,
|
79 |
+
"patch_size": 4,
|
80 |
+
"patch_stride": [
|
81 |
+
4,
|
82 |
+
4
|
83 |
+
],
|
84 |
+
"prefix": null,
|
85 |
+
"problem_type": null,
|
86 |
+
"projection_dim": 512,
|
87 |
+
"projection_hidden_act": "relu",
|
88 |
+
"projection_hidden_size": 768,
|
89 |
+
"pruned_heads": {},
|
90 |
+
"qkv_bias": true,
|
91 |
+
"remove_invalid_values": false,
|
92 |
+
"repetition_penalty": 1.0,
|
93 |
+
"return_dict": true,
|
94 |
+
"return_dict_in_generate": false,
|
95 |
+
"sep_token_id": null,
|
96 |
+
"spec_size": 256,
|
97 |
+
"suppress_tokens": null,
|
98 |
+
"task_specific_params": null,
|
99 |
+
"temperature": 1.0,
|
100 |
+
"tf_legacy_loss": false,
|
101 |
+
"tie_encoder_decoder": false,
|
102 |
+
"tie_word_embeddings": true,
|
103 |
+
"tokenizer_class": null,
|
104 |
+
"top_k": 50,
|
105 |
+
"top_p": 1.0,
|
106 |
+
"torch_dtype": null,
|
107 |
+
"torchscript": false,
|
108 |
+
"transformers_version": "4.27.0.dev0",
|
109 |
+
"typical_p": 1.0,
|
110 |
+
"use_bfloat16": false,
|
111 |
+
"window_size": 8
|
112 |
+
},
|
113 |
+
"hidden_size": 768,
|
114 |
+
"initializer_factor": 1.0,
|
115 |
+
"logit_scale_init_value": 14.285714285714285,
|
116 |
+
"model_type": "clap",
|
117 |
+
"num_hidden_layers": 16,
|
118 |
+
"projection_dim": 512,
|
119 |
+
"projection_hidden_act": "relu",
|
120 |
+
"text_config": {
|
121 |
+
"_name_or_path": "",
|
122 |
+
"add_cross_attention": false,
|
123 |
+
"architectures": null,
|
124 |
+
"attention_probs_dropout_prob": 0.1,
|
125 |
+
"bad_words_ids": null,
|
126 |
+
"begin_suppress_tokens": null,
|
127 |
+
"bos_token_id": 0,
|
128 |
+
"chunk_size_feed_forward": 0,
|
129 |
+
"classifier_dropout": null,
|
130 |
+
"cross_attention_hidden_size": null,
|
131 |
+
"decoder_start_token_id": null,
|
132 |
+
"diversity_penalty": 0.0,
|
133 |
+
"do_sample": false,
|
134 |
+
"early_stopping": false,
|
135 |
+
"encoder_no_repeat_ngram_size": 0,
|
136 |
+
"eos_token_id": 2,
|
137 |
+
"exponential_decay_length_penalty": null,
|
138 |
+
"finetuning_task": null,
|
139 |
+
"forced_bos_token_id": null,
|
140 |
+
"forced_eos_token_id": null,
|
141 |
+
"fusion_hidden_size": 768,
|
142 |
+
"fusion_num_hidden_layers": 2,
|
143 |
+
"hidden_act": "gelu",
|
144 |
+
"hidden_dropout_prob": 0.1,
|
145 |
+
"hidden_size": 768,
|
146 |
+
"id2label": {
|
147 |
+
"0": "LABEL_0",
|
148 |
+
"1": "LABEL_1"
|
149 |
+
},
|
150 |
+
"initializer_factor": 1.0,
|
151 |
+
"initializer_range": 0.02,
|
152 |
+
"intermediate_size": 3072,
|
153 |
+
"is_decoder": false,
|
154 |
+
"is_encoder_decoder": false,
|
155 |
+
"label2id": {
|
156 |
+
"LABEL_0": 0,
|
157 |
+
"LABEL_1": 1
|
158 |
+
},
|
159 |
+
"layer_norm_eps": 1e-12,
|
160 |
+
"length_penalty": 1.0,
|
161 |
+
"max_length": 20,
|
162 |
+
"max_position_embeddings": 514,
|
163 |
+
"min_length": 0,
|
164 |
+
"model_type": "clap_text_model",
|
165 |
+
"no_repeat_ngram_size": 0,
|
166 |
+
"num_attention_heads": 12,
|
167 |
+
"num_beam_groups": 1,
|
168 |
+
"num_beams": 1,
|
169 |
+
"num_hidden_layers": 12,
|
170 |
+
"num_return_sequences": 1,
|
171 |
+
"output_attentions": false,
|
172 |
+
"output_hidden_states": false,
|
173 |
+
"output_scores": false,
|
174 |
+
"pad_token_id": 1,
|
175 |
+
"position_embedding_type": "absolute",
|
176 |
+
"prefix": null,
|
177 |
+
"problem_type": null,
|
178 |
+
"projection_dim": 512,
|
179 |
+
"projection_hidden_act": "relu",
|
180 |
+
"projection_hidden_size": 768,
|
181 |
+
"pruned_heads": {},
|
182 |
+
"remove_invalid_values": false,
|
183 |
+
"repetition_penalty": 1.0,
|
184 |
+
"return_dict": true,
|
185 |
+
"return_dict_in_generate": false,
|
186 |
+
"sep_token_id": null,
|
187 |
+
"suppress_tokens": null,
|
188 |
+
"task_specific_params": null,
|
189 |
+
"temperature": 1.0,
|
190 |
+
"tf_legacy_loss": false,
|
191 |
+
"tie_encoder_decoder": false,
|
192 |
+
"tie_word_embeddings": true,
|
193 |
+
"tokenizer_class": null,
|
194 |
+
"top_k": 50,
|
195 |
+
"top_p": 1.0,
|
196 |
+
"torch_dtype": null,
|
197 |
+
"torchscript": false,
|
198 |
+
"transformers_version": "4.27.0.dev0",
|
199 |
+
"type_vocab_size": 1,
|
200 |
+
"typical_p": 1.0,
|
201 |
+
"use_bfloat16": false,
|
202 |
+
"use_cache": true,
|
203 |
+
"vocab_size": 50265
|
204 |
+
},
|
205 |
+
"torch_dtype": "float32",
|
206 |
+
"transformers_version": null
|
207 |
+
}
|
emotional/clap-htsat-fused/merges.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
emotional/clap-htsat-fused/preprocessor_config.json
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"chunk_length_s": 10,
|
3 |
+
"feature_extractor_type": "ClapFeatureExtractor",
|
4 |
+
"feature_size": 64,
|
5 |
+
"fft_window_size": 1024,
|
6 |
+
"frequency_max": 14000,
|
7 |
+
"frequency_min": 50,
|
8 |
+
"hop_length": 480,
|
9 |
+
"max_length_s": 10,
|
10 |
+
"n_fft": 1024,
|
11 |
+
"nb_frequency_bins": 513,
|
12 |
+
"nb_max_frames": 1000,
|
13 |
+
"nb_max_samples": 480000,
|
14 |
+
"padding": "repeatpad",
|
15 |
+
"padding_side": "right",
|
16 |
+
"padding_value": 0.0,
|
17 |
+
"processor_class": "ClapProcessor",
|
18 |
+
"return_attention_mask": false,
|
19 |
+
"sampling_rate": 48000,
|
20 |
+
"top_db": null,
|
21 |
+
"truncation": "fusion"
|
22 |
+
}
|
emotional/clap-htsat-fused/special_tokens_map.json
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": "<s>",
|
3 |
+
"cls_token": "<s>",
|
4 |
+
"eos_token": "</s>",
|
5 |
+
"mask_token": {
|
6 |
+
"content": "<mask>",
|
7 |
+
"lstrip": true,
|
8 |
+
"normalized": false,
|
9 |
+
"rstrip": false,
|
10 |
+
"single_word": false
|
11 |
+
},
|
12 |
+
"pad_token": "<pad>",
|
13 |
+
"sep_token": "</s>",
|
14 |
+
"unk_token": "<unk>"
|
15 |
+
}
|
emotional/clap-htsat-fused/tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
emotional/clap-htsat-fused/tokenizer_config.json
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_prefix_space": false,
|
3 |
+
"bos_token": "<s>",
|
4 |
+
"cls_token": "<s>",
|
5 |
+
"eos_token": "</s>",
|
6 |
+
"errors": "replace",
|
7 |
+
"mask_token": "<mask>",
|
8 |
+
"model_max_length": 512,
|
9 |
+
"pad_token": "<pad>",
|
10 |
+
"processor_class": "ClapProcessor",
|
11 |
+
"sep_token": "</s>",
|
12 |
+
"special_tokens_map_file": null,
|
13 |
+
"tokenizer_class": "RobertaTokenizer",
|
14 |
+
"trim_offsets": true,
|
15 |
+
"unk_token": "<unk>"
|
16 |
+
}
|
emotional/clap-htsat-fused/vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/.gitattributes
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
20 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/LICENSE
ADDED
@@ -0,0 +1,437 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Attribution-NonCommercial-ShareAlike 4.0 International
|
2 |
+
|
3 |
+
=======================================================================
|
4 |
+
|
5 |
+
Creative Commons Corporation ("Creative Commons") is not a law firm and
|
6 |
+
does not provide legal services or legal advice. Distribution of
|
7 |
+
Creative Commons public licenses does not create a lawyer-client or
|
8 |
+
other relationship. Creative Commons makes its licenses and related
|
9 |
+
information available on an "as-is" basis. Creative Commons gives no
|
10 |
+
warranties regarding its licenses, any material licensed under their
|
11 |
+
terms and conditions, or any related information. Creative Commons
|
12 |
+
disclaims all liability for damages resulting from their use to the
|
13 |
+
fullest extent possible.
|
14 |
+
|
15 |
+
Using Creative Commons Public Licenses
|
16 |
+
|
17 |
+
Creative Commons public licenses provide a standard set of terms and
|
18 |
+
conditions that creators and other rights holders may use to share
|
19 |
+
original works of authorship and other material subject to copyright
|
20 |
+
and certain other rights specified in the public license below. The
|
21 |
+
following considerations are for informational purposes only, are not
|
22 |
+
exhaustive, and do not form part of our licenses.
|
23 |
+
|
24 |
+
Considerations for licensors: Our public licenses are
|
25 |
+
intended for use by those authorized to give the public
|
26 |
+
permission to use material in ways otherwise restricted by
|
27 |
+
copyright and certain other rights. Our licenses are
|
28 |
+
irrevocable. Licensors should read and understand the terms
|
29 |
+
and conditions of the license they choose before applying it.
|
30 |
+
Licensors should also secure all rights necessary before
|
31 |
+
applying our licenses so that the public can reuse the
|
32 |
+
material as expected. Licensors should clearly mark any
|
33 |
+
material not subject to the license. This includes other CC-
|
34 |
+
licensed material, or material used under an exception or
|
35 |
+
limitation to copyright. More considerations for licensors:
|
36 |
+
wiki.creativecommons.org/Considerations_for_licensors
|
37 |
+
|
38 |
+
Considerations for the public: By using one of our public
|
39 |
+
licenses, a licensor grants the public permission to use the
|
40 |
+
licensed material under specified terms and conditions. If
|
41 |
+
the licensor's permission is not necessary for any reason--for
|
42 |
+
example, because of any applicable exception or limitation to
|
43 |
+
copyright--then that use is not regulated by the license. Our
|
44 |
+
licenses grant only permissions under copyright and certain
|
45 |
+
other rights that a licensor has authority to grant. Use of
|
46 |
+
the licensed material may still be restricted for other
|
47 |
+
reasons, including because others have copyright or other
|
48 |
+
rights in the material. A licensor may make special requests,
|
49 |
+
such as asking that all changes be marked or described.
|
50 |
+
Although not required by our licenses, you are encouraged to
|
51 |
+
respect those requests where reasonable. More considerations
|
52 |
+
for the public:
|
53 |
+
wiki.creativecommons.org/Considerations_for_licensees
|
54 |
+
|
55 |
+
=======================================================================
|
56 |
+
|
57 |
+
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
|
58 |
+
Public License
|
59 |
+
|
60 |
+
By exercising the Licensed Rights (defined below), You accept and agree
|
61 |
+
to be bound by the terms and conditions of this Creative Commons
|
62 |
+
Attribution-NonCommercial-ShareAlike 4.0 International Public License
|
63 |
+
("Public License"). To the extent this Public License may be
|
64 |
+
interpreted as a contract, You are granted the Licensed Rights in
|
65 |
+
consideration of Your acceptance of these terms and conditions, and the
|
66 |
+
Licensor grants You such rights in consideration of benefits the
|
67 |
+
Licensor receives from making the Licensed Material available under
|
68 |
+
these terms and conditions.
|
69 |
+
|
70 |
+
|
71 |
+
Section 1 -- Definitions.
|
72 |
+
|
73 |
+
a. Adapted Material means material subject to Copyright and Similar
|
74 |
+
Rights that is derived from or based upon the Licensed Material
|
75 |
+
and in which the Licensed Material is translated, altered,
|
76 |
+
arranged, transformed, or otherwise modified in a manner requiring
|
77 |
+
permission under the Copyright and Similar Rights held by the
|
78 |
+
Licensor. For purposes of this Public License, where the Licensed
|
79 |
+
Material is a musical work, performance, or sound recording,
|
80 |
+
Adapted Material is always produced where the Licensed Material is
|
81 |
+
synched in timed relation with a moving image.
|
82 |
+
|
83 |
+
b. Adapter's License means the license You apply to Your Copyright
|
84 |
+
and Similar Rights in Your contributions to Adapted Material in
|
85 |
+
accordance with the terms and conditions of this Public License.
|
86 |
+
|
87 |
+
c. BY-NC-SA Compatible License means a license listed at
|
88 |
+
creativecommons.org/compatiblelicenses, approved by Creative
|
89 |
+
Commons as essentially the equivalent of this Public License.
|
90 |
+
|
91 |
+
d. Copyright and Similar Rights means copyright and/or similar rights
|
92 |
+
closely related to copyright including, without limitation,
|
93 |
+
performance, broadcast, sound recording, and Sui Generis Database
|
94 |
+
Rights, without regard to how the rights are labeled or
|
95 |
+
categorized. For purposes of this Public License, the rights
|
96 |
+
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
97 |
+
Rights.
|
98 |
+
|
99 |
+
e. Effective Technological Measures means those measures that, in the
|
100 |
+
absence of proper authority, may not be circumvented under laws
|
101 |
+
fulfilling obligations under Article 11 of the WIPO Copyright
|
102 |
+
Treaty adopted on December 20, 1996, and/or similar international
|
103 |
+
agreements.
|
104 |
+
|
105 |
+
f. Exceptions and Limitations means fair use, fair dealing, and/or
|
106 |
+
any other exception or limitation to Copyright and Similar Rights
|
107 |
+
that applies to Your use of the Licensed Material.
|
108 |
+
|
109 |
+
g. License Elements means the license attributes listed in the name
|
110 |
+
of a Creative Commons Public License. The License Elements of this
|
111 |
+
Public License are Attribution, NonCommercial, and ShareAlike.
|
112 |
+
|
113 |
+
h. Licensed Material means the artistic or literary work, database,
|
114 |
+
or other material to which the Licensor applied this Public
|
115 |
+
License.
|
116 |
+
|
117 |
+
i. Licensed Rights means the rights granted to You subject to the
|
118 |
+
terms and conditions of this Public License, which are limited to
|
119 |
+
all Copyright and Similar Rights that apply to Your use of the
|
120 |
+
Licensed Material and that the Licensor has authority to license.
|
121 |
+
|
122 |
+
j. Licensor means the individual(s) or entity(ies) granting rights
|
123 |
+
under this Public License.
|
124 |
+
|
125 |
+
k. NonCommercial means not primarily intended for or directed towards
|
126 |
+
commercial advantage or monetary compensation. For purposes of
|
127 |
+
this Public License, the exchange of the Licensed Material for
|
128 |
+
other material subject to Copyright and Similar Rights by digital
|
129 |
+
file-sharing or similar means is NonCommercial provided there is
|
130 |
+
no payment of monetary compensation in connection with the
|
131 |
+
exchange.
|
132 |
+
|
133 |
+
l. Share means to provide material to the public by any means or
|
134 |
+
process that requires permission under the Licensed Rights, such
|
135 |
+
as reproduction, public display, public performance, distribution,
|
136 |
+
dissemination, communication, or importation, and to make material
|
137 |
+
available to the public including in ways that members of the
|
138 |
+
public may access the material from a place and at a time
|
139 |
+
individually chosen by them.
|
140 |
+
|
141 |
+
m. Sui Generis Database Rights means rights other than copyright
|
142 |
+
resulting from Directive 96/9/EC of the European Parliament and of
|
143 |
+
the Council of 11 March 1996 on the legal protection of databases,
|
144 |
+
as amended and/or succeeded, as well as other essentially
|
145 |
+
equivalent rights anywhere in the world.
|
146 |
+
|
147 |
+
n. You means the individual or entity exercising the Licensed Rights
|
148 |
+
under this Public License. Your has a corresponding meaning.
|
149 |
+
|
150 |
+
|
151 |
+
Section 2 -- Scope.
|
152 |
+
|
153 |
+
a. License grant.
|
154 |
+
|
155 |
+
1. Subject to the terms and conditions of this Public License,
|
156 |
+
the Licensor hereby grants You a worldwide, royalty-free,
|
157 |
+
non-sublicensable, non-exclusive, irrevocable license to
|
158 |
+
exercise the Licensed Rights in the Licensed Material to:
|
159 |
+
|
160 |
+
a. reproduce and Share the Licensed Material, in whole or
|
161 |
+
in part, for NonCommercial purposes only; and
|
162 |
+
|
163 |
+
b. produce, reproduce, and Share Adapted Material for
|
164 |
+
NonCommercial purposes only.
|
165 |
+
|
166 |
+
2. Exceptions and Limitations. For the avoidance of doubt, where
|
167 |
+
Exceptions and Limitations apply to Your use, this Public
|
168 |
+
License does not apply, and You do not need to comply with
|
169 |
+
its terms and conditions.
|
170 |
+
|
171 |
+
3. Term. The term of this Public License is specified in Section
|
172 |
+
6(a).
|
173 |
+
|
174 |
+
4. Media and formats; technical modifications allowed. The
|
175 |
+
Licensor authorizes You to exercise the Licensed Rights in
|
176 |
+
all media and formats whether now known or hereafter created,
|
177 |
+
and to make technical modifications necessary to do so. The
|
178 |
+
Licensor waives and/or agrees not to assert any right or
|
179 |
+
authority to forbid You from making technical modifications
|
180 |
+
necessary to exercise the Licensed Rights, including
|
181 |
+
technical modifications necessary to circumvent Effective
|
182 |
+
Technological Measures. For purposes of this Public License,
|
183 |
+
simply making modifications authorized by this Section 2(a)
|
184 |
+
(4) never produces Adapted Material.
|
185 |
+
|
186 |
+
5. Downstream recipients.
|
187 |
+
|
188 |
+
a. Offer from the Licensor -- Licensed Material. Every
|
189 |
+
recipient of the Licensed Material automatically
|
190 |
+
receives an offer from the Licensor to exercise the
|
191 |
+
Licensed Rights under the terms and conditions of this
|
192 |
+
Public License.
|
193 |
+
|
194 |
+
b. Additional offer from the Licensor -- Adapted Material.
|
195 |
+
Every recipient of Adapted Material from You
|
196 |
+
automatically receives an offer from the Licensor to
|
197 |
+
exercise the Licensed Rights in the Adapted Material
|
198 |
+
under the conditions of the Adapter's License You apply.
|
199 |
+
|
200 |
+
c. No downstream restrictions. You may not offer or impose
|
201 |
+
any additional or different terms or conditions on, or
|
202 |
+
apply any Effective Technological Measures to, the
|
203 |
+
Licensed Material if doing so restricts exercise of the
|
204 |
+
Licensed Rights by any recipient of the Licensed
|
205 |
+
Material.
|
206 |
+
|
207 |
+
6. No endorsement. Nothing in this Public License constitutes or
|
208 |
+
may be construed as permission to assert or imply that You
|
209 |
+
are, or that Your use of the Licensed Material is, connected
|
210 |
+
with, or sponsored, endorsed, or granted official status by,
|
211 |
+
the Licensor or others designated to receive attribution as
|
212 |
+
provided in Section 3(a)(1)(A)(i).
|
213 |
+
|
214 |
+
b. Other rights.
|
215 |
+
|
216 |
+
1. Moral rights, such as the right of integrity, are not
|
217 |
+
licensed under this Public License, nor are publicity,
|
218 |
+
privacy, and/or other similar personality rights; however, to
|
219 |
+
the extent possible, the Licensor waives and/or agrees not to
|
220 |
+
assert any such rights held by the Licensor to the limited
|
221 |
+
extent necessary to allow You to exercise the Licensed
|
222 |
+
Rights, but not otherwise.
|
223 |
+
|
224 |
+
2. Patent and trademark rights are not licensed under this
|
225 |
+
Public License.
|
226 |
+
|
227 |
+
3. To the extent possible, the Licensor waives any right to
|
228 |
+
collect royalties from You for the exercise of the Licensed
|
229 |
+
Rights, whether directly or through a collecting society
|
230 |
+
under any voluntary or waivable statutory or compulsory
|
231 |
+
licensing scheme. In all other cases the Licensor expressly
|
232 |
+
reserves any right to collect such royalties, including when
|
233 |
+
the Licensed Material is used other than for NonCommercial
|
234 |
+
purposes.
|
235 |
+
|
236 |
+
|
237 |
+
Section 3 -- License Conditions.
|
238 |
+
|
239 |
+
Your exercise of the Licensed Rights is expressly made subject to the
|
240 |
+
following conditions.
|
241 |
+
|
242 |
+
a. Attribution.
|
243 |
+
|
244 |
+
1. If You Share the Licensed Material (including in modified
|
245 |
+
form), You must:
|
246 |
+
|
247 |
+
a. retain the following if it is supplied by the Licensor
|
248 |
+
with the Licensed Material:
|
249 |
+
|
250 |
+
i. identification of the creator(s) of the Licensed
|
251 |
+
Material and any others designated to receive
|
252 |
+
attribution, in any reasonable manner requested by
|
253 |
+
the Licensor (including by pseudonym if
|
254 |
+
designated);
|
255 |
+
|
256 |
+
ii. a copyright notice;
|
257 |
+
|
258 |
+
iii. a notice that refers to this Public License;
|
259 |
+
|
260 |
+
iv. a notice that refers to the disclaimer of
|
261 |
+
warranties;
|
262 |
+
|
263 |
+
v. a URI or hyperlink to the Licensed Material to the
|
264 |
+
extent reasonably practicable;
|
265 |
+
|
266 |
+
b. indicate if You modified the Licensed Material and
|
267 |
+
retain an indication of any previous modifications; and
|
268 |
+
|
269 |
+
c. indicate the Licensed Material is licensed under this
|
270 |
+
Public License, and include the text of, or the URI or
|
271 |
+
hyperlink to, this Public License.
|
272 |
+
|
273 |
+
2. You may satisfy the conditions in Section 3(a)(1) in any
|
274 |
+
reasonable manner based on the medium, means, and context in
|
275 |
+
which You Share the Licensed Material. For example, it may be
|
276 |
+
reasonable to satisfy the conditions by providing a URI or
|
277 |
+
hyperlink to a resource that includes the required
|
278 |
+
information.
|
279 |
+
3. If requested by the Licensor, You must remove any of the
|
280 |
+
information required by Section 3(a)(1)(A) to the extent
|
281 |
+
reasonably practicable.
|
282 |
+
|
283 |
+
b. ShareAlike.
|
284 |
+
|
285 |
+
In addition to the conditions in Section 3(a), if You Share
|
286 |
+
Adapted Material You produce, the following conditions also apply.
|
287 |
+
|
288 |
+
1. The Adapter's License You apply must be a Creative Commons
|
289 |
+
license with the same License Elements, this version or
|
290 |
+
later, or a BY-NC-SA Compatible License.
|
291 |
+
|
292 |
+
2. You must include the text of, or the URI or hyperlink to, the
|
293 |
+
Adapter's License You apply. You may satisfy this condition
|
294 |
+
in any reasonable manner based on the medium, means, and
|
295 |
+
context in which You Share Adapted Material.
|
296 |
+
|
297 |
+
3. You may not offer or impose any additional or different terms
|
298 |
+
or conditions on, or apply any Effective Technological
|
299 |
+
Measures to, Adapted Material that restrict exercise of the
|
300 |
+
rights granted under the Adapter's License You apply.
|
301 |
+
|
302 |
+
|
303 |
+
Section 4 -- Sui Generis Database Rights.
|
304 |
+
|
305 |
+
Where the Licensed Rights include Sui Generis Database Rights that
|
306 |
+
apply to Your use of the Licensed Material:
|
307 |
+
|
308 |
+
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
309 |
+
to extract, reuse, reproduce, and Share all or a substantial
|
310 |
+
portion of the contents of the database for NonCommercial purposes
|
311 |
+
only;
|
312 |
+
|
313 |
+
b. if You include all or a substantial portion of the database
|
314 |
+
contents in a database in which You have Sui Generis Database
|
315 |
+
Rights, then the database in which You have Sui Generis Database
|
316 |
+
Rights (but not its individual contents) is Adapted Material,
|
317 |
+
including for purposes of Section 3(b); and
|
318 |
+
|
319 |
+
c. You must comply with the conditions in Section 3(a) if You Share
|
320 |
+
all or a substantial portion of the contents of the database.
|
321 |
+
|
322 |
+
For the avoidance of doubt, this Section 4 supplements and does not
|
323 |
+
replace Your obligations under this Public License where the Licensed
|
324 |
+
Rights include other Copyright and Similar Rights.
|
325 |
+
|
326 |
+
|
327 |
+
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
328 |
+
|
329 |
+
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
330 |
+
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
331 |
+
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
332 |
+
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
333 |
+
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
334 |
+
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
335 |
+
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
336 |
+
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
337 |
+
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
338 |
+
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
339 |
+
|
340 |
+
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
341 |
+
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
342 |
+
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
343 |
+
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
344 |
+
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
345 |
+
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
346 |
+
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
347 |
+
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
348 |
+
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
349 |
+
|
350 |
+
c. The disclaimer of warranties and limitation of liability provided
|
351 |
+
above shall be interpreted in a manner that, to the extent
|
352 |
+
possible, most closely approximates an absolute disclaimer and
|
353 |
+
waiver of all liability.
|
354 |
+
|
355 |
+
|
356 |
+
Section 6 -- Term and Termination.
|
357 |
+
|
358 |
+
a. This Public License applies for the term of the Copyright and
|
359 |
+
Similar Rights licensed here. However, if You fail to comply with
|
360 |
+
this Public License, then Your rights under this Public License
|
361 |
+
terminate automatically.
|
362 |
+
|
363 |
+
b. Where Your right to use the Licensed Material has terminated under
|
364 |
+
Section 6(a), it reinstates:
|
365 |
+
|
366 |
+
1. automatically as of the date the violation is cured, provided
|
367 |
+
it is cured within 30 days of Your discovery of the
|
368 |
+
violation; or
|
369 |
+
|
370 |
+
2. upon express reinstatement by the Licensor.
|
371 |
+
|
372 |
+
For the avoidance of doubt, this Section 6(b) does not affect any
|
373 |
+
right the Licensor may have to seek remedies for Your violations
|
374 |
+
of this Public License.
|
375 |
+
|
376 |
+
c. For the avoidance of doubt, the Licensor may also offer the
|
377 |
+
Licensed Material under separate terms or conditions or stop
|
378 |
+
distributing the Licensed Material at any time; however, doing so
|
379 |
+
will not terminate this Public License.
|
380 |
+
|
381 |
+
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
382 |
+
License.
|
383 |
+
|
384 |
+
|
385 |
+
Section 7 -- Other Terms and Conditions.
|
386 |
+
|
387 |
+
a. The Licensor shall not be bound by any additional or different
|
388 |
+
terms or conditions communicated by You unless expressly agreed.
|
389 |
+
|
390 |
+
b. Any arrangements, understandings, or agreements regarding the
|
391 |
+
Licensed Material not stated herein are separate from and
|
392 |
+
independent of the terms and conditions of this Public License.
|
393 |
+
|
394 |
+
|
395 |
+
Section 8 -- Interpretation.
|
396 |
+
|
397 |
+
a. For the avoidance of doubt, this Public License does not, and
|
398 |
+
shall not be interpreted to, reduce, limit, restrict, or impose
|
399 |
+
conditions on any use of the Licensed Material that could lawfully
|
400 |
+
be made without permission under this Public License.
|
401 |
+
|
402 |
+
b. To the extent possible, if any provision of this Public License is
|
403 |
+
deemed unenforceable, it shall be automatically reformed to the
|
404 |
+
minimum extent necessary to make it enforceable. If the provision
|
405 |
+
cannot be reformed, it shall be severed from this Public License
|
406 |
+
without affecting the enforceability of the remaining terms and
|
407 |
+
conditions.
|
408 |
+
|
409 |
+
c. No term or condition of this Public License will be waived and no
|
410 |
+
failure to comply consented to unless expressly agreed to by the
|
411 |
+
Licensor.
|
412 |
+
|
413 |
+
d. Nothing in this Public License constitutes or may be interpreted
|
414 |
+
as a limitation upon, or waiver of, any privileges and immunities
|
415 |
+
that apply to the Licensor or You, including from the legal
|
416 |
+
processes of any jurisdiction or authority.
|
417 |
+
|
418 |
+
=======================================================================
|
419 |
+
|
420 |
+
Creative Commons is not a party to its public
|
421 |
+
licenses. Notwithstanding, Creative Commons may elect to apply one of
|
422 |
+
its public licenses to material it publishes and in those instances
|
423 |
+
will be considered the “Licensor.” The text of the Creative Commons
|
424 |
+
public licenses is dedicated to the public domain under the CC0 Public
|
425 |
+
Domain Dedication. Except for the limited purpose of indicating that
|
426 |
+
material is shared under a Creative Commons public license or as
|
427 |
+
otherwise permitted by the Creative Commons policies published at
|
428 |
+
creativecommons.org/policies, Creative Commons does not authorize the
|
429 |
+
use of the trademark "Creative Commons" or any other trademark or logo
|
430 |
+
of Creative Commons without its prior written consent including,
|
431 |
+
without limitation, in connection with any unauthorized modifications
|
432 |
+
to any of its public licenses or any other arrangements,
|
433 |
+
understandings, or agreements concerning use of licensed material. For
|
434 |
+
the avoidance of doubt, this paragraph does not form part of the
|
435 |
+
public licenses.
|
436 |
+
|
437 |
+
Creative Commons may be contacted at creativecommons.org.
|
emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/README.md
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: en
|
3 |
+
datasets:
|
4 |
+
- msp-podcast
|
5 |
+
inference: true
|
6 |
+
tags:
|
7 |
+
- speech
|
8 |
+
- audio
|
9 |
+
- wav2vec2
|
10 |
+
- audio-classification
|
11 |
+
- emotion-recognition
|
12 |
+
license: cc-by-nc-sa-4.0
|
13 |
+
pipeline_tag: audio-classification
|
14 |
+
---
|
15 |
+
|
16 |
+
# Model for Dimensional Speech Emotion Recognition based on Wav2vec 2.0
|
17 |
+
|
18 |
+
The model expects a raw audio signal as input and outputs predictions for arousal, dominance and valence in a range of approximately 0...1. In addition, it also provides the pooled states of the last transformer layer. The model was created by fine-tuning [
|
19 |
+
Wav2Vec2-Large-Robust](https://huggingface.co/facebook/wav2vec2-large-robust) on [MSP-Podcast](https://ecs.utdallas.edu/research/researchlabs/msp-lab/MSP-Podcast.html) (v1.7). The model was pruned from 24 to 12 transformer layers before fine-tuning. An [ONNX](https://onnx.ai/") export of the model is available from [doi:10.5281/zenodo.6221127](https://zenodo.org/record/6221127). Further details are given in the associated [paper](https://arxiv.org/abs/2203.07378) and [tutorial](https://github.com/audeering/w2v2-how-to).
|
20 |
+
|
21 |
+
# Usage
|
22 |
+
|
23 |
+
```python
|
24 |
+
import numpy as np
|
25 |
+
import torch
|
26 |
+
import torch.nn as nn
|
27 |
+
from transformers import Wav2Vec2Processor
|
28 |
+
from transformers.models.wav2vec2.modeling_wav2vec2 import (
|
29 |
+
Wav2Vec2Model,
|
30 |
+
Wav2Vec2PreTrainedModel,
|
31 |
+
)
|
32 |
+
|
33 |
+
|
34 |
+
class RegressionHead(nn.Module):
|
35 |
+
r"""Classification head."""
|
36 |
+
|
37 |
+
def __init__(self, config):
|
38 |
+
|
39 |
+
super().__init__()
|
40 |
+
|
41 |
+
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
|
42 |
+
self.dropout = nn.Dropout(config.final_dropout)
|
43 |
+
self.out_proj = nn.Linear(config.hidden_size, config.num_labels)
|
44 |
+
|
45 |
+
def forward(self, features, **kwargs):
|
46 |
+
|
47 |
+
x = features
|
48 |
+
x = self.dropout(x)
|
49 |
+
x = self.dense(x)
|
50 |
+
x = torch.tanh(x)
|
51 |
+
x = self.dropout(x)
|
52 |
+
x = self.out_proj(x)
|
53 |
+
|
54 |
+
return x
|
55 |
+
|
56 |
+
|
57 |
+
class EmotionModel(Wav2Vec2PreTrainedModel):
|
58 |
+
r"""Speech emotion classifier."""
|
59 |
+
|
60 |
+
def __init__(self, config):
|
61 |
+
|
62 |
+
super().__init__(config)
|
63 |
+
|
64 |
+
self.config = config
|
65 |
+
self.wav2vec2 = Wav2Vec2Model(config)
|
66 |
+
self.classifier = RegressionHead(config)
|
67 |
+
self.init_weights()
|
68 |
+
|
69 |
+
def forward(
|
70 |
+
self,
|
71 |
+
input_values,
|
72 |
+
):
|
73 |
+
|
74 |
+
outputs = self.wav2vec2(input_values)
|
75 |
+
hidden_states = outputs[0]
|
76 |
+
hidden_states = torch.mean(hidden_states, dim=1)
|
77 |
+
logits = self.classifier(hidden_states)
|
78 |
+
|
79 |
+
return hidden_states, logits
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
+
# load model from hub
|
84 |
+
device = 'cpu'
|
85 |
+
model_name = 'audeering/wav2vec2-large-robust-12-ft-emotion-msp-dim'
|
86 |
+
processor = Wav2Vec2Processor.from_pretrained(model_name)
|
87 |
+
model = EmotionModel.from_pretrained(model_name)
|
88 |
+
|
89 |
+
# dummy signal
|
90 |
+
sampling_rate = 16000
|
91 |
+
signal = np.zeros((1, sampling_rate), dtype=np.float32)
|
92 |
+
|
93 |
+
|
94 |
+
def process_func(
|
95 |
+
x: np.ndarray,
|
96 |
+
sampling_rate: int,
|
97 |
+
embeddings: bool = False,
|
98 |
+
) -> np.ndarray:
|
99 |
+
r"""Predict emotions or extract embeddings from raw audio signal."""
|
100 |
+
|
101 |
+
# run through processor to normalize signal
|
102 |
+
# always returns a batch, so we just get the first entry
|
103 |
+
# then we put it on the device
|
104 |
+
y = processor(x, sampling_rate=sampling_rate)
|
105 |
+
y = y['input_values'][0]
|
106 |
+
y = y.reshape(1, -1)
|
107 |
+
y = torch.from_numpy(y).to(device)
|
108 |
+
|
109 |
+
# run through model
|
110 |
+
with torch.no_grad():
|
111 |
+
y = model(y)[0 if embeddings else 1]
|
112 |
+
|
113 |
+
# convert to numpy
|
114 |
+
y = y.detach().cpu().numpy()
|
115 |
+
|
116 |
+
return y
|
117 |
+
|
118 |
+
|
119 |
+
print(process_func(signal, sampling_rate))
|
120 |
+
# Arousal dominance valence
|
121 |
+
# [[0.5460754 0.6062266 0.40431657]]
|
122 |
+
|
123 |
+
print(process_func(signal, sampling_rate, embeddings=True))
|
124 |
+
# Pooled hidden states of last transformer layer
|
125 |
+
# [[-0.00752167 0.0065819 -0.00746342 ... 0.00663632 0.00848748
|
126 |
+
# 0.00599211]]
|
127 |
+
```
|
emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/config.json
ADDED
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "torch",
|
3 |
+
"activation_dropout": 0.1,
|
4 |
+
"adapter_kernel_size": 3,
|
5 |
+
"adapter_stride": 2,
|
6 |
+
"add_adapter": false,
|
7 |
+
"apply_spec_augment": true,
|
8 |
+
"architectures": [
|
9 |
+
"Wav2Vec2ForSpeechClassification"
|
10 |
+
],
|
11 |
+
"attention_dropout": 0.1,
|
12 |
+
"bos_token_id": 1,
|
13 |
+
"classifier_proj_size": 256,
|
14 |
+
"codevector_dim": 768,
|
15 |
+
"contrastive_logits_temperature": 0.1,
|
16 |
+
"conv_bias": true,
|
17 |
+
"conv_dim": [
|
18 |
+
512,
|
19 |
+
512,
|
20 |
+
512,
|
21 |
+
512,
|
22 |
+
512,
|
23 |
+
512,
|
24 |
+
512
|
25 |
+
],
|
26 |
+
"conv_kernel": [
|
27 |
+
10,
|
28 |
+
3,
|
29 |
+
3,
|
30 |
+
3,
|
31 |
+
3,
|
32 |
+
2,
|
33 |
+
2
|
34 |
+
],
|
35 |
+
"conv_stride": [
|
36 |
+
5,
|
37 |
+
2,
|
38 |
+
2,
|
39 |
+
2,
|
40 |
+
2,
|
41 |
+
2,
|
42 |
+
2
|
43 |
+
],
|
44 |
+
"ctc_loss_reduction": "sum",
|
45 |
+
"ctc_zero_infinity": false,
|
46 |
+
"diversity_loss_weight": 0.1,
|
47 |
+
"do_stable_layer_norm": true,
|
48 |
+
"eos_token_id": 2,
|
49 |
+
"feat_extract_activation": "gelu",
|
50 |
+
"feat_extract_dropout": 0.0,
|
51 |
+
"feat_extract_norm": "layer",
|
52 |
+
"feat_proj_dropout": 0.1,
|
53 |
+
"feat_quantizer_dropout": 0.0,
|
54 |
+
"final_dropout": 0.1,
|
55 |
+
"finetuning_task": "wav2vec2_reg",
|
56 |
+
"gradient_checkpointing": false,
|
57 |
+
"hidden_act": "gelu",
|
58 |
+
"hidden_dropout": 0.1,
|
59 |
+
"hidden_dropout_prob": 0.1,
|
60 |
+
"hidden_size": 1024,
|
61 |
+
"id2label": {
|
62 |
+
"0": "arousal",
|
63 |
+
"1": "dominance",
|
64 |
+
"2": "valence"
|
65 |
+
},
|
66 |
+
"initializer_range": 0.02,
|
67 |
+
"intermediate_size": 4096,
|
68 |
+
"label2id": {
|
69 |
+
"arousal": 0,
|
70 |
+
"dominance": 1,
|
71 |
+
"valence": 2
|
72 |
+
},
|
73 |
+
"layer_norm_eps": 1e-05,
|
74 |
+
"layerdrop": 0.1,
|
75 |
+
"mask_feature_length": 10,
|
76 |
+
"mask_feature_min_masks": 0,
|
77 |
+
"mask_feature_prob": 0.0,
|
78 |
+
"mask_time_length": 10,
|
79 |
+
"mask_time_min_masks": 2,
|
80 |
+
"mask_time_prob": 0.05,
|
81 |
+
"model_type": "wav2vec2",
|
82 |
+
"num_adapter_layers": 3,
|
83 |
+
"num_attention_heads": 16,
|
84 |
+
"num_codevector_groups": 2,
|
85 |
+
"num_codevectors_per_group": 320,
|
86 |
+
"num_conv_pos_embedding_groups": 16,
|
87 |
+
"num_conv_pos_embeddings": 128,
|
88 |
+
"num_feat_extract_layers": 7,
|
89 |
+
"num_hidden_layers": 12,
|
90 |
+
"num_negatives": 100,
|
91 |
+
"output_hidden_size": 1024,
|
92 |
+
"pad_token_id": 0,
|
93 |
+
"pooling_mode": "mean",
|
94 |
+
"problem_type": "regression",
|
95 |
+
"proj_codevector_dim": 768,
|
96 |
+
"tdnn_dilation": [
|
97 |
+
1,
|
98 |
+
2,
|
99 |
+
3,
|
100 |
+
1,
|
101 |
+
1
|
102 |
+
],
|
103 |
+
"tdnn_dim": [
|
104 |
+
512,
|
105 |
+
512,
|
106 |
+
512,
|
107 |
+
512,
|
108 |
+
1500
|
109 |
+
],
|
110 |
+
"tdnn_kernel": [
|
111 |
+
5,
|
112 |
+
3,
|
113 |
+
3,
|
114 |
+
1,
|
115 |
+
1
|
116 |
+
],
|
117 |
+
"torch_dtype": "float32",
|
118 |
+
"transformers_version": "4.17.0.dev0",
|
119 |
+
"use_weighted_layer_sum": false,
|
120 |
+
"vocab_size": null,
|
121 |
+
"xvector_output_dim": 512
|
122 |
+
}
|
emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/preprocessor_config.json
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"do_normalize": true,
|
3 |
+
"feature_extractor_type": "Wav2Vec2FeatureExtractor",
|
4 |
+
"feature_size": 1,
|
5 |
+
"padding_side": "right",
|
6 |
+
"padding_value": 0.0,
|
7 |
+
"return_attention_mask": true,
|
8 |
+
"sampling_rate": 16000
|
9 |
+
}
|
emotional/wav2vec2-large-robust-12-ft-emotion-msp-dim/vocab.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{}
|
export_onnx.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from onnx_modules import export_onnx
|
2 |
+
import os
|
3 |
+
|
4 |
+
if __name__ == "__main__":
|
5 |
+
export_path = "BertVits2.2PT"
|
6 |
+
model_path = "model\\G_0.pth"
|
7 |
+
config_path = "model\\config.json"
|
8 |
+
novq = False
|
9 |
+
dev = False
|
10 |
+
Extra = "chinese" # japanese or chinese
|
11 |
+
if not os.path.exists("onnx"):
|
12 |
+
os.makedirs("onnx")
|
13 |
+
if not os.path.exists(f"onnx/{export_path}"):
|
14 |
+
os.makedirs(f"onnx/{export_path}")
|
15 |
+
export_onnx(export_path, model_path, config_path, novq, dev, Extra)
|
img/yuyu.png
ADDED
img//345/217/202/346/225/260/350/257/264/346/230/216.png
ADDED
img//345/256/265/345/256/253.png
ADDED
img//345/276/256/344/277/241/345/233/276/347/211/207_20231010105112.png
ADDED
img//347/245/236/351/207/214/347/273/253/345/215/216.png
ADDED
img//347/272/263/350/245/277/345/246/262.png
ADDED
infer.py
ADDED
@@ -0,0 +1,366 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
版本管理、兼容推理及模型加载实现。
|
3 |
+
版本说明:
|
4 |
+
1. 版本号与github的release版本号对应,使用哪个release版本训练的模型即对应其版本号
|
5 |
+
2. 请在模型的config.json中显示声明版本号,添加一个字段"version" : "你的版本号"
|
6 |
+
特殊版本说明:
|
7 |
+
1.1.1-fix: 1.1.1版本训练的模型,但是在推理时使用dev的日语修复
|
8 |
+
2.3:当前版本
|
9 |
+
"""
|
10 |
+
|
11 |
+
import torch
|
12 |
+
import commons
|
13 |
+
from text import cleaned_text_to_sequence
|
14 |
+
|
15 |
+
# from clap_wrapper import get_clap_audio_feature, get_clap_text_feature
|
16 |
+
from typing import Union
|
17 |
+
from text.cleaner import clean_text
|
18 |
+
import utils
|
19 |
+
|
20 |
+
from models import SynthesizerTrn
|
21 |
+
from text.symbols import symbols
|
22 |
+
|
23 |
+
# from oldVersion.V220.models import SynthesizerTrn as V220SynthesizerTrn
|
24 |
+
# from oldVersion.V220.text import symbols as V220symbols
|
25 |
+
# from oldVersion.V210.models import SynthesizerTrn as V210SynthesizerTrn
|
26 |
+
# from oldVersion.V210.text import symbols as V210symbols
|
27 |
+
# from oldVersion.V200.models import SynthesizerTrn as V200SynthesizerTrn
|
28 |
+
# from oldVersion.V200.text import symbols as V200symbols
|
29 |
+
# from oldVersion.V111.models import SynthesizerTrn as V111SynthesizerTrn
|
30 |
+
# from oldVersion.V111.text import symbols as V111symbols
|
31 |
+
# from oldVersion.V110.models import SynthesizerTrn as V110SynthesizerTrn
|
32 |
+
# from oldVersion.V110.text import symbols as V110symbols
|
33 |
+
# from oldVersion.V101.models import SynthesizerTrn as V101SynthesizerTrn
|
34 |
+
# from oldVersion.V101.text import symbols as V101symbols
|
35 |
+
#
|
36 |
+
# from oldVersion import V111, V110, V101, V200, V210, V220
|
37 |
+
|
38 |
+
# 当前版本信息
|
39 |
+
latest_version = "2.3"
|
40 |
+
|
41 |
+
# # 版本兼容
|
42 |
+
# SynthesizerTrnMap = {
|
43 |
+
# "2.2": V220SynthesizerTrn,
|
44 |
+
# "2.1": V210SynthesizerTrn,
|
45 |
+
# "2.0.2-fix": V200SynthesizerTrn,
|
46 |
+
# "2.0.1": V200SynthesizerTrn,
|
47 |
+
# "2.0": V200SynthesizerTrn,
|
48 |
+
# "1.1.1-fix": V111SynthesizerTrn,
|
49 |
+
# "1.1.1": V111SynthesizerTrn,
|
50 |
+
# "1.1": V110SynthesizerTrn,
|
51 |
+
# "1.1.0": V110SynthesizerTrn,
|
52 |
+
# "1.0.1": V101SynthesizerTrn,
|
53 |
+
# "1.0": V101SynthesizerTrn,
|
54 |
+
# "1.0.0": V101SynthesizerTrn,
|
55 |
+
# }
|
56 |
+
#
|
57 |
+
# symbolsMap = {
|
58 |
+
# "2.2": V220symbols,
|
59 |
+
# "2.1": V210symbols,
|
60 |
+
# "2.0.2-fix": V200symbols,
|
61 |
+
# "2.0.1": V200symbols,
|
62 |
+
# "2.0": V200symbols,
|
63 |
+
# "1.1.1-fix": V111symbols,
|
64 |
+
# "1.1.1": V111symbols,
|
65 |
+
# "1.1": V110symbols,
|
66 |
+
# "1.1.0": V110symbols,
|
67 |
+
# "1.0.1": V101symbols,
|
68 |
+
# "1.0": V101symbols,
|
69 |
+
# "1.0.0": V101symbols,
|
70 |
+
# }
|
71 |
+
|
72 |
+
|
73 |
+
# def get_emo_(reference_audio, emotion, sid):
|
74 |
+
# emo = (
|
75 |
+
# torch.from_numpy(get_emo(reference_audio))
|
76 |
+
# if reference_audio and emotion == -1
|
77 |
+
# else torch.FloatTensor(
|
78 |
+
# np.load(f"emo_clustering/{sid}/cluster_center_{emotion}.npy")
|
79 |
+
# )
|
80 |
+
# )
|
81 |
+
# return emo
|
82 |
+
|
83 |
+
|
84 |
+
def get_net_g(model_path: str, device: str, hps):
|
85 |
+
# 当前版本模型 net_g
|
86 |
+
net_g = SynthesizerTrn(
|
87 |
+
len(symbols),
|
88 |
+
hps.data.filter_length // 2 + 1,
|
89 |
+
hps.train.segment_size // hps.data.hop_length,
|
90 |
+
n_speakers=hps.data.n_speakers,
|
91 |
+
**hps.model,
|
92 |
+
).to(device)
|
93 |
+
_ = net_g.eval()
|
94 |
+
_ = utils.load_checkpoint(model_path, net_g, None, skip_optimizer=True)
|
95 |
+
return net_g
|
96 |
+
|
97 |
+
|
98 |
+
def get_text(text, language_str, hps, device, style_text=None, style_weight=0.7):
|
99 |
+
style_text = None if style_text == "" else style_text
|
100 |
+
# 在此处实现当前版本的get_text
|
101 |
+
norm_text, phone, tone, word2ph = clean_text(text, language_str)
|
102 |
+
phone, tone, language = cleaned_text_to_sequence(phone, tone, language_str)
|
103 |
+
|
104 |
+
if hps.data.add_blank:
|
105 |
+
phone = commons.intersperse(phone, 0)
|
106 |
+
tone = commons.intersperse(tone, 0)
|
107 |
+
language = commons.intersperse(language, 0)
|
108 |
+
for i in range(len(word2ph)):
|
109 |
+
word2ph[i] = word2ph[i] * 2
|
110 |
+
word2ph[0] += 1
|
111 |
+
del word2ph
|
112 |
+
|
113 |
+
phone = torch.LongTensor(phone)
|
114 |
+
tone = torch.LongTensor(tone)
|
115 |
+
language = torch.LongTensor(language)
|
116 |
+
return phone, tone, language
|
117 |
+
|
118 |
+
|
119 |
+
def infer(
|
120 |
+
text,
|
121 |
+
emotion: Union[int, str],
|
122 |
+
sdp_ratio,
|
123 |
+
noise_scale,
|
124 |
+
noise_scale_w,
|
125 |
+
length_scale,
|
126 |
+
sid,
|
127 |
+
language,
|
128 |
+
hps,
|
129 |
+
net_g,
|
130 |
+
device,
|
131 |
+
reference_audio=None,
|
132 |
+
skip_start=False,
|
133 |
+
skip_end=False,
|
134 |
+
style_text=None,
|
135 |
+
style_weight=0.7,
|
136 |
+
):
|
137 |
+
# 2.2版本参数位置变了
|
138 |
+
# inferMap_V4 = {
|
139 |
+
# "2.2": V220.infer,
|
140 |
+
# }
|
141 |
+
# # 2.1 参数新增 emotion reference_audio skip_start skip_end
|
142 |
+
# inferMap_V3 = {
|
143 |
+
# "2.1": V210.infer,
|
144 |
+
# }
|
145 |
+
# # 支持中日英三语版本
|
146 |
+
# inferMap_V2 = {
|
147 |
+
# "2.0.2-fix": V200.infer,
|
148 |
+
# "2.0.1": V200.infer,
|
149 |
+
# "2.0": V200.infer,
|
150 |
+
# "1.1.1-fix": V111.infer_fix,
|
151 |
+
# "1.1.1": V111.infer,
|
152 |
+
# "1.1": V110.infer,
|
153 |
+
# "1.1.0": V110.infer,
|
154 |
+
# }
|
155 |
+
# # 仅支持中文版本
|
156 |
+
# # 在测试中,并未发现两个版本的模型不能互相通用
|
157 |
+
# inferMap_V1 = {
|
158 |
+
# "1.0.1": V101.infer,
|
159 |
+
# "1.0": V101.infer,
|
160 |
+
# "1.0.0": V101.infer,
|
161 |
+
# }
|
162 |
+
# version = hps.version if hasattr(hps, "version") else latest_version
|
163 |
+
# 非当前版本,根据版本号选择合适的infer
|
164 |
+
# if version != latest_version:
|
165 |
+
# if version in inferMap_V4.keys():
|
166 |
+
# return inferMap_V4[version](
|
167 |
+
# text,
|
168 |
+
# emotion,
|
169 |
+
# sdp_ratio,
|
170 |
+
# noise_scale,
|
171 |
+
# noise_scale_w,
|
172 |
+
# length_scale,
|
173 |
+
# sid,
|
174 |
+
# language,
|
175 |
+
# hps,
|
176 |
+
# net_g,
|
177 |
+
# device,
|
178 |
+
# reference_audio,
|
179 |
+
# skip_start,
|
180 |
+
# skip_end,
|
181 |
+
# style_text,
|
182 |
+
# style_weight,
|
183 |
+
# )
|
184 |
+
# if version in inferMap_V3.keys():
|
185 |
+
# return inferMap_V3[version](
|
186 |
+
# text,
|
187 |
+
# sdp_ratio,
|
188 |
+
# noise_scale,
|
189 |
+
# noise_scale_w,
|
190 |
+
# length_scale,
|
191 |
+
# sid,
|
192 |
+
# language,
|
193 |
+
# hps,
|
194 |
+
# net_g,
|
195 |
+
# device,
|
196 |
+
# reference_audio,
|
197 |
+
# emotion,
|
198 |
+
# skip_start,
|
199 |
+
# skip_end,
|
200 |
+
# style_text,
|
201 |
+
# style_weight,
|
202 |
+
# )
|
203 |
+
# if version in inferMap_V2.keys():
|
204 |
+
# return inferMap_V2[version](
|
205 |
+
# text,
|
206 |
+
# sdp_ratio,
|
207 |
+
# noise_scale,
|
208 |
+
# noise_scale_w,
|
209 |
+
# length_scale,
|
210 |
+
# sid,
|
211 |
+
# language,
|
212 |
+
# hps,
|
213 |
+
# net_g,
|
214 |
+
# device,
|
215 |
+
# )
|
216 |
+
# if version in inferMap_V1.keys():
|
217 |
+
# return inferMap_V1[version](
|
218 |
+
# text,
|
219 |
+
# sdp_ratio,
|
220 |
+
# noise_scale,
|
221 |
+
# noise_scale_w,
|
222 |
+
# length_scale,
|
223 |
+
# sid,
|
224 |
+
# hps,
|
225 |
+
# net_g,
|
226 |
+
# device,
|
227 |
+
# )
|
228 |
+
# 在此处实现当前版本的推理
|
229 |
+
# emo = get_emo_(reference_audio, emotion, sid)
|
230 |
+
# if isinstance(reference_audio, np.ndarray):
|
231 |
+
# emo = get_clap_audio_feature(reference_audio, device)
|
232 |
+
# else:
|
233 |
+
# emo = get_clap_text_feature(emotion, device)
|
234 |
+
# emo = torch.squeeze(emo, dim=1)
|
235 |
+
|
236 |
+
phones, tones, lang_ids = get_text(
|
237 |
+
text,
|
238 |
+
language,
|
239 |
+
hps,
|
240 |
+
device,
|
241 |
+
style_text=style_text,
|
242 |
+
style_weight=style_weight,
|
243 |
+
)
|
244 |
+
if skip_start:
|
245 |
+
phones = phones[3:]
|
246 |
+
tones = tones[3:]
|
247 |
+
lang_ids = lang_ids[3:]
|
248 |
+
if skip_end:
|
249 |
+
phones = phones[:-2]
|
250 |
+
tones = tones[:-2]
|
251 |
+
lang_ids = lang_ids[:-2]
|
252 |
+
with torch.no_grad():
|
253 |
+
x_tst = phones.to(device).unsqueeze(0)
|
254 |
+
tones = tones.to(device).unsqueeze(0)
|
255 |
+
lang_ids = lang_ids.to(device).unsqueeze(0)
|
256 |
+
x_tst_lengths = torch.LongTensor([phones.size(0)]).to(device)
|
257 |
+
# emo = emo.to(device).unsqueeze(0)
|
258 |
+
del phones
|
259 |
+
speakers = torch.LongTensor([hps.data.spk2id[sid]]).to(device)
|
260 |
+
audio = (
|
261 |
+
net_g.infer(
|
262 |
+
x_tst,
|
263 |
+
x_tst_lengths,
|
264 |
+
speakers,
|
265 |
+
tones,
|
266 |
+
lang_ids,
|
267 |
+
sdp_ratio=sdp_ratio,
|
268 |
+
noise_scale=noise_scale,
|
269 |
+
noise_scale_w=noise_scale_w,
|
270 |
+
length_scale=length_scale,
|
271 |
+
)[0][0, 0]
|
272 |
+
.data.cpu()
|
273 |
+
.float()
|
274 |
+
.numpy()
|
275 |
+
)
|
276 |
+
del (
|
277 |
+
x_tst,
|
278 |
+
tones,
|
279 |
+
lang_ids,
|
280 |
+
x_tst_lengths,
|
281 |
+
speakers,
|
282 |
+
) # , emo
|
283 |
+
if torch.cuda.is_available():
|
284 |
+
torch.cuda.empty_cache()
|
285 |
+
return audio
|
286 |
+
|
287 |
+
|
288 |
+
def infer_multilang(
|
289 |
+
text,
|
290 |
+
sdp_ratio,
|
291 |
+
noise_scale,
|
292 |
+
noise_scale_w,
|
293 |
+
length_scale,
|
294 |
+
sid,
|
295 |
+
language,
|
296 |
+
hps,
|
297 |
+
net_g,
|
298 |
+
device,
|
299 |
+
reference_audio=None,
|
300 |
+
emotion=None,
|
301 |
+
skip_start=False,
|
302 |
+
skip_end=False,
|
303 |
+
):
|
304 |
+
phones, tones, lang_ids = [], [], [], [], [], [], []
|
305 |
+
# emo = get_emo_(reference_audio, emotion, sid)
|
306 |
+
# if isinstance(reference_audio, np.ndarray):
|
307 |
+
# emo = get_clap_audio_feature(reference_audio, device)
|
308 |
+
# else:
|
309 |
+
# emo = get_clap_text_feature(emotion, device)
|
310 |
+
# emo = torch.squeeze(emo, dim=1)
|
311 |
+
for idx, (txt, lang) in enumerate(zip(text, language)):
|
312 |
+
_skip_start = (idx != 0) or (skip_start and idx == 0)
|
313 |
+
_skip_end = (idx != len(language) - 1) or skip_end
|
314 |
+
(
|
315 |
+
temp_phones,
|
316 |
+
temp_tones,
|
317 |
+
temp_lang_ids,
|
318 |
+
) = get_text(txt, lang, hps, device)
|
319 |
+
if _skip_start:
|
320 |
+
temp_phones = temp_phones[3:]
|
321 |
+
temp_tones = temp_tones[3:]
|
322 |
+
temp_lang_ids = temp_lang_ids[3:]
|
323 |
+
if _skip_end:
|
324 |
+
temp_phones = temp_phones[:-2]
|
325 |
+
temp_tones = temp_tones[:-2]
|
326 |
+
temp_lang_ids = temp_lang_ids[:-2]
|
327 |
+
phones.append(temp_phones)
|
328 |
+
tones.append(temp_tones)
|
329 |
+
lang_ids.append(temp_lang_ids)
|
330 |
+
phones = torch.concatenate(phones, dim=0)
|
331 |
+
tones = torch.concatenate(tones, dim=0)
|
332 |
+
lang_ids = torch.concatenate(lang_ids, dim=0)
|
333 |
+
with torch.no_grad():
|
334 |
+
x_tst = phones.to(device).unsqueeze(0)
|
335 |
+
tones = tones.to(device).unsqueeze(0)
|
336 |
+
lang_ids = lang_ids.to(device).unsqueeze(0)
|
337 |
+
# emo = emo.to(device).unsqueeze(0)
|
338 |
+
x_tst_lengths = torch.LongTensor([phones.size(0)]).to(device)
|
339 |
+
del phones
|
340 |
+
speakers = torch.LongTensor([hps.data.spk2id[sid]]).to(device)
|
341 |
+
audio = (
|
342 |
+
net_g.infer(
|
343 |
+
x_tst,
|
344 |
+
x_tst_lengths,
|
345 |
+
speakers,
|
346 |
+
tones,
|
347 |
+
lang_ids,
|
348 |
+
sdp_ratio=sdp_ratio,
|
349 |
+
noise_scale=noise_scale,
|
350 |
+
noise_scale_w=noise_scale_w,
|
351 |
+
length_scale=length_scale,
|
352 |
+
)[0][0, 0]
|
353 |
+
.data.cpu()
|
354 |
+
.float()
|
355 |
+
.numpy()
|
356 |
+
)
|
357 |
+
del (
|
358 |
+
x_tst,
|
359 |
+
tones,
|
360 |
+
lang_ids,
|
361 |
+
x_tst_lengths,
|
362 |
+
speakers,
|
363 |
+
) # , emo
|
364 |
+
if torch.cuda.is_available():
|
365 |
+
torch.cuda.empty_cache()
|
366 |
+
return audio
|
losses.py
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torchaudio
|
3 |
+
from transformers import AutoModel
|
4 |
+
|
5 |
+
|
6 |
+
def feature_loss(fmap_r, fmap_g):
|
7 |
+
loss = 0
|
8 |
+
for dr, dg in zip(fmap_r, fmap_g):
|
9 |
+
for rl, gl in zip(dr, dg):
|
10 |
+
rl = rl.float().detach()
|
11 |
+
gl = gl.float()
|
12 |
+
loss += torch.mean(torch.abs(rl - gl))
|
13 |
+
|
14 |
+
return loss * 2
|
15 |
+
|
16 |
+
|
17 |
+
def discriminator_loss(disc_real_outputs, disc_generated_outputs):
|
18 |
+
loss = 0
|
19 |
+
r_losses = []
|
20 |
+
g_losses = []
|
21 |
+
for dr, dg in zip(disc_real_outputs, disc_generated_outputs):
|
22 |
+
dr = dr.float()
|
23 |
+
dg = dg.float()
|
24 |
+
r_loss = torch.mean((1 - dr) ** 2)
|
25 |
+
g_loss = torch.mean(dg**2)
|
26 |
+
loss += r_loss + g_loss
|
27 |
+
r_losses.append(r_loss.item())
|
28 |
+
g_losses.append(g_loss.item())
|
29 |
+
|
30 |
+
return loss, r_losses, g_losses
|
31 |
+
|
32 |
+
|
33 |
+
def generator_loss(disc_outputs):
|
34 |
+
loss = 0
|
35 |
+
gen_losses = []
|
36 |
+
for dg in disc_outputs:
|
37 |
+
dg = dg.float()
|
38 |
+
l = torch.mean((1 - dg) ** 2)
|
39 |
+
gen_losses.append(l)
|
40 |
+
loss += l
|
41 |
+
|
42 |
+
return loss, gen_losses
|
43 |
+
|
44 |
+
|
45 |
+
def kl_loss(z_p, logs_q, m_p, logs_p, z_mask):
|
46 |
+
"""
|
47 |
+
z_p, logs_q: [b, h, t_t]
|
48 |
+
m_p, logs_p: [b, h, t_t]
|
49 |
+
"""
|
50 |
+
z_p = z_p.float()
|
51 |
+
logs_q = logs_q.float()
|
52 |
+
m_p = m_p.float()
|
53 |
+
logs_p = logs_p.float()
|
54 |
+
z_mask = z_mask.float()
|
55 |
+
|
56 |
+
kl = logs_p - logs_q - 0.5
|
57 |
+
kl += 0.5 * ((z_p - m_p) ** 2) * torch.exp(-2.0 * logs_p)
|
58 |
+
kl = torch.sum(kl * z_mask)
|
59 |
+
l = kl / torch.sum(z_mask)
|
60 |
+
return l
|
61 |
+
|
62 |
+
|
63 |
+
class WavLMLoss(torch.nn.Module):
|
64 |
+
def __init__(self, model, wd, model_sr, slm_sr=16000):
|
65 |
+
super(WavLMLoss, self).__init__()
|
66 |
+
self.wavlm = AutoModel.from_pretrained(model)
|
67 |
+
self.wd = wd
|
68 |
+
self.resample = torchaudio.transforms.Resample(model_sr, slm_sr)
|
69 |
+
self.wavlm.eval()
|
70 |
+
for param in self.wavlm.parameters():
|
71 |
+
param.requires_grad = False
|
72 |
+
|
73 |
+
def forward(self, wav, y_rec):
|
74 |
+
with torch.no_grad():
|
75 |
+
wav_16 = self.resample(wav)
|
76 |
+
wav_embeddings = self.wavlm(
|
77 |
+
input_values=wav_16, output_hidden_states=True
|
78 |
+
).hidden_states
|
79 |
+
y_rec_16 = self.resample(y_rec)
|
80 |
+
y_rec_embeddings = self.wavlm(
|
81 |
+
input_values=y_rec_16.squeeze(), output_hidden_states=True
|
82 |
+
).hidden_states
|
83 |
+
|
84 |
+
floss = 0
|
85 |
+
for er, eg in zip(wav_embeddings, y_rec_embeddings):
|
86 |
+
floss += torch.mean(torch.abs(er - eg))
|
87 |
+
|
88 |
+
return floss.mean()
|
89 |
+
|
90 |
+
def generator(self, y_rec):
|
91 |
+
y_rec_16 = self.resample(y_rec)
|
92 |
+
y_rec_embeddings = self.wavlm(
|
93 |
+
input_values=y_rec_16, output_hidden_states=True
|
94 |
+
).hidden_states
|
95 |
+
y_rec_embeddings = (
|
96 |
+
torch.stack(y_rec_embeddings, dim=1)
|
97 |
+
.transpose(-1, -2)
|
98 |
+
.flatten(start_dim=1, end_dim=2)
|
99 |
+
)
|
100 |
+
y_df_hat_g = self.wd(y_rec_embeddings)
|
101 |
+
loss_gen = torch.mean((1 - y_df_hat_g) ** 2)
|
102 |
+
|
103 |
+
return loss_gen
|
104 |
+
|
105 |
+
def discriminator(self, wav, y_rec):
|
106 |
+
with torch.no_grad():
|
107 |
+
wav_16 = self.resample(wav)
|
108 |
+
wav_embeddings = self.wavlm(
|
109 |
+
input_values=wav_16, output_hidden_states=True
|
110 |
+
).hidden_states
|
111 |
+
y_rec_16 = self.resample(y_rec)
|
112 |
+
y_rec_embeddings = self.wavlm(
|
113 |
+
input_values=y_rec_16, output_hidden_states=True
|
114 |
+
).hidden_states
|
115 |
+
|
116 |
+
y_embeddings = (
|
117 |
+
torch.stack(wav_embeddings, dim=1)
|
118 |
+
.transpose(-1, -2)
|
119 |
+
.flatten(start_dim=1, end_dim=2)
|
120 |
+
)
|
121 |
+
y_rec_embeddings = (
|
122 |
+
torch.stack(y_rec_embeddings, dim=1)
|
123 |
+
.transpose(-1, -2)
|
124 |
+
.flatten(start_dim=1, end_dim=2)
|
125 |
+
)
|
126 |
+
|
127 |
+
y_d_rs = self.wd(y_embeddings)
|
128 |
+
y_d_gs = self.wd(y_rec_embeddings)
|
129 |
+
|
130 |
+
y_df_hat_r, y_df_hat_g = y_d_rs, y_d_gs
|
131 |
+
|
132 |
+
r_loss = torch.mean((1 - y_df_hat_r) ** 2)
|
133 |
+
g_loss = torch.mean((y_df_hat_g) ** 2)
|
134 |
+
|
135 |
+
loss_disc_f = r_loss + g_loss
|
136 |
+
|
137 |
+
return loss_disc_f.mean()
|
138 |
+
|
139 |
+
def discriminator_forward(self, wav):
|
140 |
+
with torch.no_grad():
|
141 |
+
wav_16 = self.resample(wav)
|
142 |
+
wav_embeddings = self.wavlm(
|
143 |
+
input_values=wav_16, output_hidden_states=True
|
144 |
+
).hidden_states
|
145 |
+
y_embeddings = (
|
146 |
+
torch.stack(wav_embeddings, dim=1)
|
147 |
+
.transpose(-1, -2)
|
148 |
+
.flatten(start_dim=1, end_dim=2)
|
149 |
+
)
|
150 |
+
|
151 |
+
y_d_rs = self.wd(y_embeddings)
|
152 |
+
|
153 |
+
return y_d_rs
|
mel_processing.py
ADDED
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torch.utils.data
|
3 |
+
from librosa.filters import mel as librosa_mel_fn
|
4 |
+
import warnings
|
5 |
+
|
6 |
+
# warnings.simplefilter(action='ignore', category=FutureWarning)
|
7 |
+
warnings.filterwarnings(action="ignore")
|
8 |
+
MAX_WAV_VALUE = 32768.0
|
9 |
+
|
10 |
+
|
11 |
+
def dynamic_range_compression_torch(x, C=1, clip_val=1e-5):
|
12 |
+
"""
|
13 |
+
PARAMS
|
14 |
+
------
|
15 |
+
C: compression factor
|
16 |
+
"""
|
17 |
+
return torch.log(torch.clamp(x, min=clip_val) * C)
|
18 |
+
|
19 |
+
|
20 |
+
def dynamic_range_decompression_torch(x, C=1):
|
21 |
+
"""
|
22 |
+
PARAMS
|
23 |
+
------
|
24 |
+
C: compression factor used to compress
|
25 |
+
"""
|
26 |
+
return torch.exp(x) / C
|
27 |
+
|
28 |
+
|
29 |
+
def spectral_normalize_torch(magnitudes):
|
30 |
+
output = dynamic_range_compression_torch(magnitudes)
|
31 |
+
return output
|
32 |
+
|
33 |
+
|
34 |
+
def spectral_de_normalize_torch(magnitudes):
|
35 |
+
output = dynamic_range_decompression_torch(magnitudes)
|
36 |
+
return output
|
37 |
+
|
38 |
+
|
39 |
+
mel_basis = {}
|
40 |
+
hann_window = {}
|
41 |
+
|
42 |
+
|
43 |
+
def spectrogram_torch(y, n_fft, sampling_rate, hop_size, win_size, center=False):
|
44 |
+
if torch.min(y) < -1.0:
|
45 |
+
print("min value is ", torch.min(y))
|
46 |
+
if torch.max(y) > 1.0:
|
47 |
+
print("max value is ", torch.max(y))
|
48 |
+
|
49 |
+
global hann_window
|
50 |
+
dtype_device = str(y.dtype) + "_" + str(y.device)
|
51 |
+
wnsize_dtype_device = str(win_size) + "_" + dtype_device
|
52 |
+
if wnsize_dtype_device not in hann_window:
|
53 |
+
hann_window[wnsize_dtype_device] = torch.hann_window(win_size).to(
|
54 |
+
dtype=y.dtype, device=y.device
|
55 |
+
)
|
56 |
+
|
57 |
+
y = torch.nn.functional.pad(
|
58 |
+
y.unsqueeze(1),
|
59 |
+
(int((n_fft - hop_size) / 2), int((n_fft - hop_size) / 2)),
|
60 |
+
mode="reflect",
|
61 |
+
)
|
62 |
+
y = y.squeeze(1)
|
63 |
+
|
64 |
+
spec = torch.stft(
|
65 |
+
y,
|
66 |
+
n_fft,
|
67 |
+
hop_length=hop_size,
|
68 |
+
win_length=win_size,
|
69 |
+
window=hann_window[wnsize_dtype_device],
|
70 |
+
center=center,
|
71 |
+
pad_mode="reflect",
|
72 |
+
normalized=False,
|
73 |
+
onesided=True,
|
74 |
+
return_complex=False,
|
75 |
+
)
|
76 |
+
|
77 |
+
spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6)
|
78 |
+
return spec
|
79 |
+
|
80 |
+
|
81 |
+
def spec_to_mel_torch(spec, n_fft, num_mels, sampling_rate, fmin, fmax):
|
82 |
+
global mel_basis
|
83 |
+
dtype_device = str(spec.dtype) + "_" + str(spec.device)
|
84 |
+
fmax_dtype_device = str(fmax) + "_" + dtype_device
|
85 |
+
if fmax_dtype_device not in mel_basis:
|
86 |
+
mel = librosa_mel_fn(sr=sampling_rate, n_fft=n_fft, n_mels=num_mels, fmin=fmin, fmax=fmax)
|
87 |
+
mel_basis[fmax_dtype_device] = torch.from_numpy(mel).to(
|
88 |
+
dtype=spec.dtype, device=spec.device
|
89 |
+
)
|
90 |
+
spec = torch.matmul(mel_basis[fmax_dtype_device], spec)
|
91 |
+
spec = spectral_normalize_torch(spec)
|
92 |
+
return spec
|
93 |
+
|
94 |
+
|
95 |
+
def mel_spectrogram_torch(
|
96 |
+
y, n_fft, num_mels, sampling_rate, hop_size, win_size, fmin, fmax, center=False
|
97 |
+
):
|
98 |
+
if torch.min(y) < -1.0:
|
99 |
+
print("min value is ", torch.min(y))
|
100 |
+
if torch.max(y) > 1.0:
|
101 |
+
print("max value is ", torch.max(y))
|
102 |
+
|
103 |
+
global mel_basis, hann_window
|
104 |
+
dtype_device = str(y.dtype) + "_" + str(y.device)
|
105 |
+
fmax_dtype_device = str(fmax) + "_" + dtype_device
|
106 |
+
wnsize_dtype_device = str(win_size) + "_" + dtype_device
|
107 |
+
if fmax_dtype_device not in mel_basis:
|
108 |
+
mel = librosa_mel_fn(sampling_rate, n_fft, num_mels, fmin, fmax)
|
109 |
+
mel_basis[fmax_dtype_device] = torch.from_numpy(mel).to(
|
110 |
+
dtype=y.dtype, device=y.device
|
111 |
+
)
|
112 |
+
if wnsize_dtype_device not in hann_window:
|
113 |
+
hann_window[wnsize_dtype_device] = torch.hann_window(win_size).to(
|
114 |
+
dtype=y.dtype, device=y.device
|
115 |
+
)
|
116 |
+
|
117 |
+
y = torch.nn.functional.pad(
|
118 |
+
y.unsqueeze(1),
|
119 |
+
(int((n_fft - hop_size) / 2), int((n_fft - hop_size) / 2)),
|
120 |
+
mode="reflect",
|
121 |
+
)
|
122 |
+
y = y.squeeze(1)
|
123 |
+
|
124 |
+
spec = torch.stft(
|
125 |
+
y,
|
126 |
+
n_fft,
|
127 |
+
hop_length=hop_size,
|
128 |
+
win_length=win_size,
|
129 |
+
window=hann_window[wnsize_dtype_device],
|
130 |
+
center=center,
|
131 |
+
pad_mode="reflect",
|
132 |
+
normalized=False,
|
133 |
+
onesided=True,
|
134 |
+
return_complex=False,
|
135 |
+
)
|
136 |
+
|
137 |
+
spec = torch.sqrt(spec.pow(2).sum(-1) + 1e-6)
|
138 |
+
|
139 |
+
spec = torch.matmul(mel_basis[fmax_dtype_device], spec)
|
140 |
+
spec = spectral_normalize_torch(spec)
|
141 |
+
|
142 |
+
return spec
|
models.py
ADDED
@@ -0,0 +1,1071 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import torch
|
3 |
+
from torch import nn
|
4 |
+
from torch.nn import functional as F
|
5 |
+
|
6 |
+
import commons
|
7 |
+
import modules
|
8 |
+
import attentions
|
9 |
+
import monotonic_align
|
10 |
+
|
11 |
+
from torch.nn import Conv1d, ConvTranspose1d, Conv2d
|
12 |
+
from torch.nn.utils import weight_norm, remove_weight_norm, spectral_norm
|
13 |
+
|
14 |
+
from commons import init_weights, get_padding
|
15 |
+
from text import symbols, num_tones, num_languages
|
16 |
+
|
17 |
+
|
18 |
+
class DurationDiscriminator(nn.Module): # vits2
|
19 |
+
def __init__(
|
20 |
+
self, in_channels, filter_channels, kernel_size, p_dropout, gin_channels=0
|
21 |
+
):
|
22 |
+
super().__init__()
|
23 |
+
|
24 |
+
self.in_channels = in_channels
|
25 |
+
self.filter_channels = filter_channels
|
26 |
+
self.kernel_size = kernel_size
|
27 |
+
self.p_dropout = p_dropout
|
28 |
+
self.gin_channels = gin_channels
|
29 |
+
|
30 |
+
self.drop = nn.Dropout(p_dropout)
|
31 |
+
self.conv_1 = nn.Conv1d(
|
32 |
+
in_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
33 |
+
)
|
34 |
+
self.norm_1 = modules.LayerNorm(filter_channels)
|
35 |
+
self.conv_2 = nn.Conv1d(
|
36 |
+
filter_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
37 |
+
)
|
38 |
+
self.norm_2 = modules.LayerNorm(filter_channels)
|
39 |
+
self.dur_proj = nn.Conv1d(1, filter_channels, 1)
|
40 |
+
|
41 |
+
self.LSTM = nn.LSTM(
|
42 |
+
2 * filter_channels, filter_channels, batch_first=True, bidirectional=True
|
43 |
+
)
|
44 |
+
|
45 |
+
if gin_channels != 0:
|
46 |
+
self.cond = nn.Conv1d(gin_channels, in_channels, 1)
|
47 |
+
|
48 |
+
self.output_layer = nn.Sequential(
|
49 |
+
nn.Linear(2 * filter_channels, 1), nn.Sigmoid()
|
50 |
+
)
|
51 |
+
|
52 |
+
def forward_probability(self, x, dur):
|
53 |
+
dur = self.dur_proj(dur)
|
54 |
+
x = torch.cat([x, dur], dim=1)
|
55 |
+
x = x.transpose(1, 2)
|
56 |
+
x, _ = self.LSTM(x)
|
57 |
+
output_prob = self.output_layer(x)
|
58 |
+
return output_prob
|
59 |
+
|
60 |
+
def forward(self, x, x_mask, dur_r, dur_hat, g=None):
|
61 |
+
x = torch.detach(x)
|
62 |
+
if g is not None:
|
63 |
+
g = torch.detach(g)
|
64 |
+
x = x + self.cond(g)
|
65 |
+
x = self.conv_1(x * x_mask)
|
66 |
+
x = torch.relu(x)
|
67 |
+
x = self.norm_1(x)
|
68 |
+
x = self.drop(x)
|
69 |
+
x = self.conv_2(x * x_mask)
|
70 |
+
x = torch.relu(x)
|
71 |
+
x = self.norm_2(x)
|
72 |
+
x = self.drop(x)
|
73 |
+
|
74 |
+
output_probs = []
|
75 |
+
for dur in [dur_r, dur_hat]:
|
76 |
+
output_prob = self.forward_probability(x, dur)
|
77 |
+
output_probs.append(output_prob)
|
78 |
+
|
79 |
+
return output_probs
|
80 |
+
|
81 |
+
|
82 |
+
class TransformerCouplingBlock(nn.Module):
|
83 |
+
def __init__(
|
84 |
+
self,
|
85 |
+
channels,
|
86 |
+
hidden_channels,
|
87 |
+
filter_channels,
|
88 |
+
n_heads,
|
89 |
+
n_layers,
|
90 |
+
kernel_size,
|
91 |
+
p_dropout,
|
92 |
+
n_flows=4,
|
93 |
+
gin_channels=0,
|
94 |
+
share_parameter=False,
|
95 |
+
):
|
96 |
+
super().__init__()
|
97 |
+
self.channels = channels
|
98 |
+
self.hidden_channels = hidden_channels
|
99 |
+
self.kernel_size = kernel_size
|
100 |
+
self.n_layers = n_layers
|
101 |
+
self.n_flows = n_flows
|
102 |
+
self.gin_channels = gin_channels
|
103 |
+
|
104 |
+
self.flows = nn.ModuleList()
|
105 |
+
|
106 |
+
self.wn = (
|
107 |
+
attentions.FFT(
|
108 |
+
hidden_channels,
|
109 |
+
filter_channels,
|
110 |
+
n_heads,
|
111 |
+
n_layers,
|
112 |
+
kernel_size,
|
113 |
+
p_dropout,
|
114 |
+
isflow=True,
|
115 |
+
gin_channels=self.gin_channels,
|
116 |
+
)
|
117 |
+
if share_parameter
|
118 |
+
else None
|
119 |
+
)
|
120 |
+
|
121 |
+
for i in range(n_flows):
|
122 |
+
self.flows.append(
|
123 |
+
modules.TransformerCouplingLayer(
|
124 |
+
channels,
|
125 |
+
hidden_channels,
|
126 |
+
kernel_size,
|
127 |
+
n_layers,
|
128 |
+
n_heads,
|
129 |
+
p_dropout,
|
130 |
+
filter_channels,
|
131 |
+
mean_only=True,
|
132 |
+
wn_sharing_parameter=self.wn,
|
133 |
+
gin_channels=self.gin_channels,
|
134 |
+
)
|
135 |
+
)
|
136 |
+
self.flows.append(modules.Flip())
|
137 |
+
|
138 |
+
def forward(self, x, x_mask, g=None, reverse=False):
|
139 |
+
if not reverse:
|
140 |
+
for flow in self.flows:
|
141 |
+
x, _ = flow(x, x_mask, g=g, reverse=reverse)
|
142 |
+
else:
|
143 |
+
for flow in reversed(self.flows):
|
144 |
+
x = flow(x, x_mask, g=g, reverse=reverse)
|
145 |
+
return x
|
146 |
+
|
147 |
+
|
148 |
+
class StochasticDurationPredictor(nn.Module):
|
149 |
+
def __init__(
|
150 |
+
self,
|
151 |
+
in_channels,
|
152 |
+
filter_channels,
|
153 |
+
kernel_size,
|
154 |
+
p_dropout,
|
155 |
+
n_flows=4,
|
156 |
+
gin_channels=0,
|
157 |
+
):
|
158 |
+
super().__init__()
|
159 |
+
# it needs to be removed from future version.
|
160 |
+
filter_channels = in_channels
|
161 |
+
self.in_channels = in_channels
|
162 |
+
self.filter_channels = filter_channels
|
163 |
+
self.kernel_size = kernel_size
|
164 |
+
self.p_dropout = p_dropout
|
165 |
+
self.n_flows = n_flows
|
166 |
+
self.gin_channels = gin_channels
|
167 |
+
|
168 |
+
self.log_flow = modules.Log()
|
169 |
+
self.flows = nn.ModuleList()
|
170 |
+
self.flows.append(modules.ElementwiseAffine(2))
|
171 |
+
for i in range(n_flows):
|
172 |
+
self.flows.append(
|
173 |
+
modules.ConvFlow(2, filter_channels, kernel_size, n_layers=3)
|
174 |
+
)
|
175 |
+
self.flows.append(modules.Flip())
|
176 |
+
|
177 |
+
self.post_pre = nn.Conv1d(1, filter_channels, 1)
|
178 |
+
self.post_proj = nn.Conv1d(filter_channels, filter_channels, 1)
|
179 |
+
self.post_convs = modules.DDSConv(
|
180 |
+
filter_channels, kernel_size, n_layers=3, p_dropout=p_dropout
|
181 |
+
)
|
182 |
+
self.post_flows = nn.ModuleList()
|
183 |
+
self.post_flows.append(modules.ElementwiseAffine(2))
|
184 |
+
for i in range(4):
|
185 |
+
self.post_flows.append(
|
186 |
+
modules.ConvFlow(2, filter_channels, kernel_size, n_layers=3)
|
187 |
+
)
|
188 |
+
self.post_flows.append(modules.Flip())
|
189 |
+
|
190 |
+
self.pre = nn.Conv1d(in_channels, filter_channels, 1)
|
191 |
+
self.proj = nn.Conv1d(filter_channels, filter_channels, 1)
|
192 |
+
self.convs = modules.DDSConv(
|
193 |
+
filter_channels, kernel_size, n_layers=3, p_dropout=p_dropout
|
194 |
+
)
|
195 |
+
if gin_channels != 0:
|
196 |
+
self.cond = nn.Conv1d(gin_channels, filter_channels, 1)
|
197 |
+
|
198 |
+
def forward(self, x, x_mask, w=None, g=None, reverse=False, noise_scale=1.0):
|
199 |
+
x = torch.detach(x)
|
200 |
+
x = self.pre(x)
|
201 |
+
if g is not None:
|
202 |
+
g = torch.detach(g)
|
203 |
+
x = x + self.cond(g)
|
204 |
+
x = self.convs(x, x_mask)
|
205 |
+
x = self.proj(x) * x_mask
|
206 |
+
|
207 |
+
if not reverse:
|
208 |
+
flows = self.flows
|
209 |
+
assert w is not None
|
210 |
+
|
211 |
+
logdet_tot_q = 0
|
212 |
+
h_w = self.post_pre(w)
|
213 |
+
h_w = self.post_convs(h_w, x_mask)
|
214 |
+
h_w = self.post_proj(h_w) * x_mask
|
215 |
+
e_q = (
|
216 |
+
torch.randn(w.size(0), 2, w.size(2)).to(
|
217 |
+
device=x.device, dtype=x.dtype)
|
218 |
+
* x_mask
|
219 |
+
)
|
220 |
+
z_q = e_q
|
221 |
+
for flow in self.post_flows:
|
222 |
+
z_q, logdet_q = flow(z_q, x_mask, g=(x + h_w))
|
223 |
+
logdet_tot_q += logdet_q
|
224 |
+
z_u, z1 = torch.split(z_q, [1, 1], 1)
|
225 |
+
u = torch.sigmoid(z_u) * x_mask
|
226 |
+
z0 = (w - u) * x_mask
|
227 |
+
logdet_tot_q += torch.sum(
|
228 |
+
(F.logsigmoid(z_u) + F.logsigmoid(-z_u)) * x_mask, [1, 2]
|
229 |
+
)
|
230 |
+
logq = (
|
231 |
+
torch.sum(-0.5 * (math.log(2 * math.pi) + (e_q**2))
|
232 |
+
* x_mask, [1, 2])
|
233 |
+
- logdet_tot_q
|
234 |
+
)
|
235 |
+
|
236 |
+
logdet_tot = 0
|
237 |
+
z0, logdet = self.log_flow(z0, x_mask)
|
238 |
+
logdet_tot += logdet
|
239 |
+
z = torch.cat([z0, z1], 1)
|
240 |
+
for flow in flows:
|
241 |
+
z, logdet = flow(z, x_mask, g=x, reverse=reverse)
|
242 |
+
logdet_tot = logdet_tot + logdet
|
243 |
+
nll = (
|
244 |
+
torch.sum(0.5 * (math.log(2 * math.pi) + (z**2))
|
245 |
+
* x_mask, [1, 2])
|
246 |
+
- logdet_tot
|
247 |
+
)
|
248 |
+
return nll + logq # [b]
|
249 |
+
else:
|
250 |
+
flows = list(reversed(self.flows))
|
251 |
+
flows = flows[:-2] + [flows[-1]] # remove a useless vflow
|
252 |
+
z = (
|
253 |
+
torch.randn(x.size(0), 2, x.size(2)).to(
|
254 |
+
device=x.device, dtype=x.dtype)
|
255 |
+
* noise_scale
|
256 |
+
)
|
257 |
+
for flow in flows:
|
258 |
+
z = flow(z, x_mask, g=x, reverse=reverse)
|
259 |
+
z0, z1 = torch.split(z, [1, 1], 1)
|
260 |
+
logw = z0
|
261 |
+
return logw
|
262 |
+
|
263 |
+
|
264 |
+
class DurationPredictor(nn.Module):
|
265 |
+
def __init__(
|
266 |
+
self, in_channels, filter_channels, kernel_size, p_dropout, gin_channels=0
|
267 |
+
):
|
268 |
+
super().__init__()
|
269 |
+
|
270 |
+
self.in_channels = in_channels
|
271 |
+
self.filter_channels = filter_channels
|
272 |
+
self.kernel_size = kernel_size
|
273 |
+
self.p_dropout = p_dropout
|
274 |
+
self.gin_channels = gin_channels
|
275 |
+
|
276 |
+
self.drop = nn.Dropout(p_dropout)
|
277 |
+
self.conv_1 = nn.Conv1d(
|
278 |
+
in_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
279 |
+
)
|
280 |
+
self.norm_1 = modules.LayerNorm(filter_channels)
|
281 |
+
self.conv_2 = nn.Conv1d(
|
282 |
+
filter_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
283 |
+
)
|
284 |
+
self.norm_2 = modules.LayerNorm(filter_channels)
|
285 |
+
self.proj = nn.Conv1d(filter_channels, 1, 1)
|
286 |
+
|
287 |
+
if gin_channels != 0:
|
288 |
+
self.cond = nn.Conv1d(gin_channels, in_channels, 1)
|
289 |
+
|
290 |
+
def forward(self, x, x_mask, g=None):
|
291 |
+
x = torch.detach(x)
|
292 |
+
if g is not None:
|
293 |
+
g = torch.detach(g)
|
294 |
+
x = x + self.cond(g)
|
295 |
+
x = self.conv_1(x * x_mask)
|
296 |
+
x = torch.relu(x)
|
297 |
+
x = self.norm_1(x)
|
298 |
+
x = self.drop(x)
|
299 |
+
x = self.conv_2(x * x_mask)
|
300 |
+
x = torch.relu(x)
|
301 |
+
x = self.norm_2(x)
|
302 |
+
x = self.drop(x)
|
303 |
+
x = self.proj(x * x_mask)
|
304 |
+
return x * x_mask
|
305 |
+
|
306 |
+
|
307 |
+
class Bottleneck(nn.Sequential):
|
308 |
+
def __init__(self, in_dim, hidden_dim):
|
309 |
+
c_fc1 = nn.Linear(in_dim, hidden_dim, bias=False)
|
310 |
+
c_fc2 = nn.Linear(in_dim, hidden_dim, bias=False)
|
311 |
+
super().__init__(*[c_fc1, c_fc2])
|
312 |
+
|
313 |
+
|
314 |
+
class Block(nn.Module):
|
315 |
+
def __init__(self, in_dim, hidden_dim) -> None:
|
316 |
+
super().__init__()
|
317 |
+
self.norm = nn.LayerNorm(in_dim)
|
318 |
+
self.mlp = MLP(in_dim, hidden_dim)
|
319 |
+
|
320 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
321 |
+
x = x + self.mlp(self.norm(x))
|
322 |
+
return x
|
323 |
+
|
324 |
+
|
325 |
+
class MLP(nn.Module):
|
326 |
+
def __init__(self, in_dim, hidden_dim):
|
327 |
+
super().__init__()
|
328 |
+
self.c_fc1 = nn.Linear(in_dim, hidden_dim, bias=False)
|
329 |
+
self.c_fc2 = nn.Linear(in_dim, hidden_dim, bias=False)
|
330 |
+
self.c_proj = nn.Linear(hidden_dim, in_dim, bias=False)
|
331 |
+
|
332 |
+
def forward(self, x: torch.Tensor):
|
333 |
+
x = F.silu(self.c_fc1(x)) * self.c_fc2(x)
|
334 |
+
x = self.c_proj(x)
|
335 |
+
return x
|
336 |
+
|
337 |
+
|
338 |
+
class TextEncoder(nn.Module):
|
339 |
+
def __init__(
|
340 |
+
self,
|
341 |
+
n_vocab,
|
342 |
+
out_channels,
|
343 |
+
hidden_channels,
|
344 |
+
filter_channels,
|
345 |
+
n_heads,
|
346 |
+
n_layers,
|
347 |
+
kernel_size,
|
348 |
+
p_dropout,
|
349 |
+
gin_channels=0,
|
350 |
+
):
|
351 |
+
super().__init__()
|
352 |
+
self.n_vocab = n_vocab
|
353 |
+
self.out_channels = out_channels
|
354 |
+
self.hidden_channels = hidden_channels
|
355 |
+
self.filter_channels = filter_channels
|
356 |
+
self.n_heads = n_heads
|
357 |
+
self.n_layers = n_layers
|
358 |
+
self.kernel_size = kernel_size
|
359 |
+
self.p_dropout = p_dropout
|
360 |
+
self.gin_channels = gin_channels
|
361 |
+
self.emb = nn.Embedding(len(symbols), hidden_channels)
|
362 |
+
nn.init.normal_(self.emb.weight, 0.0, hidden_channels**-0.5)
|
363 |
+
self.tone_emb = nn.Embedding(num_tones, hidden_channels)
|
364 |
+
nn.init.normal_(self.tone_emb.weight, 0.0, hidden_channels**-0.5)
|
365 |
+
self.language_emb = nn.Embedding(num_languages, hidden_channels)
|
366 |
+
nn.init.normal_(self.language_emb.weight, 0.0, hidden_channels**-0.5)
|
367 |
+
|
368 |
+
self.encoder = attentions.Encoder(
|
369 |
+
hidden_channels,
|
370 |
+
filter_channels,
|
371 |
+
n_heads,
|
372 |
+
n_layers,
|
373 |
+
kernel_size,
|
374 |
+
p_dropout,
|
375 |
+
gin_channels=self.gin_channels,
|
376 |
+
)
|
377 |
+
self.proj = nn.Conv1d(hidden_channels, out_channels * 2, 1)
|
378 |
+
|
379 |
+
def forward(self, x, x_lengths, tone, language, g=None):
|
380 |
+
x = (
|
381 |
+
self.emb(x)
|
382 |
+
+ self.tone_emb(tone)
|
383 |
+
+ self.language_emb(language)
|
384 |
+
) * math.sqrt(
|
385 |
+
self.hidden_channels
|
386 |
+
) # [b, t, h]
|
387 |
+
x = torch.transpose(x, 1, -1) # [b, h, t]
|
388 |
+
x_mask = torch.unsqueeze(commons.sequence_mask(x_lengths, x.size(2)), 1).to(
|
389 |
+
x.dtype
|
390 |
+
)
|
391 |
+
|
392 |
+
x = self.encoder(x * x_mask, x_mask, g=g)
|
393 |
+
stats = self.proj(x) * x_mask
|
394 |
+
|
395 |
+
m, logs = torch.split(stats, self.out_channels, dim=1)
|
396 |
+
return x, m, logs, x_mask
|
397 |
+
|
398 |
+
|
399 |
+
class ResidualCouplingBlock(nn.Module):
|
400 |
+
def __init__(
|
401 |
+
self,
|
402 |
+
channels,
|
403 |
+
hidden_channels,
|
404 |
+
kernel_size,
|
405 |
+
dilation_rate,
|
406 |
+
n_layers,
|
407 |
+
n_flows=4,
|
408 |
+
gin_channels=0,
|
409 |
+
):
|
410 |
+
super().__init__()
|
411 |
+
self.channels = channels
|
412 |
+
self.hidden_channels = hidden_channels
|
413 |
+
self.kernel_size = kernel_size
|
414 |
+
self.dilation_rate = dilation_rate
|
415 |
+
self.n_layers = n_layers
|
416 |
+
self.n_flows = n_flows
|
417 |
+
self.gin_channels = gin_channels
|
418 |
+
|
419 |
+
self.flows = nn.ModuleList()
|
420 |
+
for i in range(n_flows):
|
421 |
+
self.flows.append(
|
422 |
+
modules.ResidualCouplingLayer(
|
423 |
+
channels,
|
424 |
+
hidden_channels,
|
425 |
+
kernel_size,
|
426 |
+
dilation_rate,
|
427 |
+
n_layers,
|
428 |
+
gin_channels=gin_channels,
|
429 |
+
mean_only=True,
|
430 |
+
)
|
431 |
+
)
|
432 |
+
self.flows.append(modules.Flip())
|
433 |
+
|
434 |
+
def forward(self, x, x_mask, g=None, reverse=False):
|
435 |
+
if not reverse:
|
436 |
+
for flow in self.flows:
|
437 |
+
x, _ = flow(x, x_mask, g=g, reverse=reverse)
|
438 |
+
else:
|
439 |
+
for flow in reversed(self.flows):
|
440 |
+
x = flow(x, x_mask, g=g, reverse=reverse)
|
441 |
+
return x
|
442 |
+
|
443 |
+
|
444 |
+
class PosteriorEncoder(nn.Module):
|
445 |
+
def __init__(
|
446 |
+
self,
|
447 |
+
in_channels,
|
448 |
+
out_channels,
|
449 |
+
hidden_channels,
|
450 |
+
kernel_size,
|
451 |
+
dilation_rate,
|
452 |
+
n_layers,
|
453 |
+
gin_channels=0,
|
454 |
+
):
|
455 |
+
super().__init__()
|
456 |
+
self.in_channels = in_channels
|
457 |
+
self.out_channels = out_channels
|
458 |
+
self.hidden_channels = hidden_channels
|
459 |
+
self.kernel_size = kernel_size
|
460 |
+
self.dilation_rate = dilation_rate
|
461 |
+
self.n_layers = n_layers
|
462 |
+
self.gin_channels = gin_channels
|
463 |
+
|
464 |
+
self.pre = nn.Conv1d(in_channels, hidden_channels, 1)
|
465 |
+
self.enc = modules.WN(
|
466 |
+
hidden_channels,
|
467 |
+
kernel_size,
|
468 |
+
dilation_rate,
|
469 |
+
n_layers,
|
470 |
+
gin_channels=gin_channels,
|
471 |
+
)
|
472 |
+
self.proj = nn.Conv1d(hidden_channels, out_channels * 2, 1)
|
473 |
+
|
474 |
+
def forward(self, x, x_lengths, g=None):
|
475 |
+
x_mask = torch.unsqueeze(commons.sequence_mask(x_lengths, x.size(2)), 1).to(
|
476 |
+
x.dtype
|
477 |
+
)
|
478 |
+
x = self.pre(x) * x_mask
|
479 |
+
x = self.enc(x, x_mask, g=g)
|
480 |
+
stats = self.proj(x) * x_mask
|
481 |
+
m, logs = torch.split(stats, self.out_channels, dim=1)
|
482 |
+
z = (m + torch.randn_like(m) * torch.exp(logs)) * x_mask
|
483 |
+
return z, m, logs, x_mask
|
484 |
+
|
485 |
+
|
486 |
+
class Generator(torch.nn.Module):
|
487 |
+
def __init__(
|
488 |
+
self,
|
489 |
+
initial_channel,
|
490 |
+
resblock,
|
491 |
+
resblock_kernel_sizes,
|
492 |
+
resblock_dilation_sizes,
|
493 |
+
upsample_rates,
|
494 |
+
upsample_initial_channel,
|
495 |
+
upsample_kernel_sizes,
|
496 |
+
gin_channels=0,
|
497 |
+
):
|
498 |
+
super(Generator, self).__init__()
|
499 |
+
self.num_kernels = len(resblock_kernel_sizes)
|
500 |
+
self.num_upsamples = len(upsample_rates)
|
501 |
+
self.conv_pre = Conv1d(
|
502 |
+
initial_channel, upsample_initial_channel, 7, 1, padding=3
|
503 |
+
)
|
504 |
+
resblock = modules.ResBlock1 if resblock == "1" else modules.ResBlock2
|
505 |
+
|
506 |
+
self.ups = nn.ModuleList()
|
507 |
+
for i, (u, k) in enumerate(zip(upsample_rates, upsample_kernel_sizes)):
|
508 |
+
self.ups.append(
|
509 |
+
weight_norm(
|
510 |
+
ConvTranspose1d(
|
511 |
+
upsample_initial_channel // (2**i),
|
512 |
+
upsample_initial_channel // (2 ** (i + 1)),
|
513 |
+
k,
|
514 |
+
u,
|
515 |
+
padding=(k - u) // 2,
|
516 |
+
)
|
517 |
+
)
|
518 |
+
)
|
519 |
+
|
520 |
+
self.resblocks = nn.ModuleList()
|
521 |
+
for i in range(len(self.ups)):
|
522 |
+
ch = upsample_initial_channel // (2 ** (i + 1))
|
523 |
+
for j, (k, d) in enumerate(
|
524 |
+
zip(resblock_kernel_sizes, resblock_dilation_sizes)
|
525 |
+
):
|
526 |
+
self.resblocks.append(resblock(ch, k, d))
|
527 |
+
|
528 |
+
self.conv_post = Conv1d(ch, 1, 7, 1, padding=3, bias=False)
|
529 |
+
self.ups.apply(init_weights)
|
530 |
+
|
531 |
+
if gin_channels != 0:
|
532 |
+
self.cond = nn.Conv1d(gin_channels, upsample_initial_channel, 1)
|
533 |
+
|
534 |
+
def forward(self, x, g=None):
|
535 |
+
x = self.conv_pre(x)
|
536 |
+
if g is not None:
|
537 |
+
x = x + self.cond(g)
|
538 |
+
|
539 |
+
for i in range(self.num_upsamples):
|
540 |
+
x = F.leaky_relu(x, modules.LRELU_SLOPE)
|
541 |
+
x = self.ups[i](x)
|
542 |
+
xs = None
|
543 |
+
for j in range(self.num_kernels):
|
544 |
+
if xs is None:
|
545 |
+
xs = self.resblocks[i * self.num_kernels + j](x)
|
546 |
+
else:
|
547 |
+
xs += self.resblocks[i * self.num_kernels + j](x)
|
548 |
+
x = xs / self.num_kernels
|
549 |
+
x = F.leaky_relu(x)
|
550 |
+
x = self.conv_post(x)
|
551 |
+
x = torch.tanh(x)
|
552 |
+
|
553 |
+
return x
|
554 |
+
|
555 |
+
def remove_weight_norm(self):
|
556 |
+
print("Removing weight norm...")
|
557 |
+
for layer in self.ups:
|
558 |
+
remove_weight_norm(layer)
|
559 |
+
for layer in self.resblocks:
|
560 |
+
layer.remove_weight_norm()
|
561 |
+
|
562 |
+
|
563 |
+
class DiscriminatorP(torch.nn.Module):
|
564 |
+
def __init__(self, period, kernel_size=5, stride=3, use_spectral_norm=False):
|
565 |
+
super(DiscriminatorP, self).__init__()
|
566 |
+
self.period = period
|
567 |
+
self.use_spectral_norm = use_spectral_norm
|
568 |
+
norm_f = weight_norm if use_spectral_norm is False else spectral_norm
|
569 |
+
self.convs = nn.ModuleList(
|
570 |
+
[
|
571 |
+
norm_f(
|
572 |
+
Conv2d(
|
573 |
+
1,
|
574 |
+
32,
|
575 |
+
(kernel_size, 1),
|
576 |
+
(stride, 1),
|
577 |
+
padding=(get_padding(kernel_size, 1), 0),
|
578 |
+
)
|
579 |
+
),
|
580 |
+
norm_f(
|
581 |
+
Conv2d(
|
582 |
+
32,
|
583 |
+
128,
|
584 |
+
(kernel_size, 1),
|
585 |
+
(stride, 1),
|
586 |
+
padding=(get_padding(kernel_size, 1), 0),
|
587 |
+
)
|
588 |
+
),
|
589 |
+
norm_f(
|
590 |
+
Conv2d(
|
591 |
+
128,
|
592 |
+
512,
|
593 |
+
(kernel_size, 1),
|
594 |
+
(stride, 1),
|
595 |
+
padding=(get_padding(kernel_size, 1), 0),
|
596 |
+
)
|
597 |
+
),
|
598 |
+
norm_f(
|
599 |
+
Conv2d(
|
600 |
+
512,
|
601 |
+
1024,
|
602 |
+
(kernel_size, 1),
|
603 |
+
(stride, 1),
|
604 |
+
padding=(get_padding(kernel_size, 1), 0),
|
605 |
+
)
|
606 |
+
),
|
607 |
+
norm_f(
|
608 |
+
Conv2d(
|
609 |
+
1024,
|
610 |
+
1024,
|
611 |
+
(kernel_size, 1),
|
612 |
+
1,
|
613 |
+
padding=(get_padding(kernel_size, 1), 0),
|
614 |
+
)
|
615 |
+
),
|
616 |
+
]
|
617 |
+
)
|
618 |
+
self.conv_post = norm_f(Conv2d(1024, 1, (3, 1), 1, padding=(1, 0)))
|
619 |
+
|
620 |
+
def forward(self, x):
|
621 |
+
fmap = []
|
622 |
+
|
623 |
+
# 1d to 2d
|
624 |
+
b, c, t = x.shape
|
625 |
+
if t % self.period != 0: # pad first
|
626 |
+
n_pad = self.period - (t % self.period)
|
627 |
+
x = F.pad(x, (0, n_pad), "reflect")
|
628 |
+
t = t + n_pad
|
629 |
+
x = x.view(b, c, t // self.period, self.period)
|
630 |
+
|
631 |
+
for layer in self.convs:
|
632 |
+
x = layer(x)
|
633 |
+
x = F.leaky_relu(x, modules.LRELU_SLOPE)
|
634 |
+
fmap.append(x)
|
635 |
+
x = self.conv_post(x)
|
636 |
+
fmap.append(x)
|
637 |
+
x = torch.flatten(x, 1, -1)
|
638 |
+
|
639 |
+
return x, fmap
|
640 |
+
|
641 |
+
|
642 |
+
class DiscriminatorS(torch.nn.Module):
|
643 |
+
def __init__(self, use_spectral_norm=False):
|
644 |
+
super(DiscriminatorS, self).__init__()
|
645 |
+
norm_f = weight_norm if use_spectral_norm is False else spectral_norm
|
646 |
+
self.convs = nn.ModuleList(
|
647 |
+
[
|
648 |
+
norm_f(Conv1d(1, 16, 15, 1, padding=7)),
|
649 |
+
norm_f(Conv1d(16, 64, 41, 4, groups=4, padding=20)),
|
650 |
+
norm_f(Conv1d(64, 256, 41, 4, groups=16, padding=20)),
|
651 |
+
norm_f(Conv1d(256, 1024, 41, 4, groups=64, padding=20)),
|
652 |
+
norm_f(Conv1d(1024, 1024, 41, 4, groups=256, padding=20)),
|
653 |
+
norm_f(Conv1d(1024, 1024, 5, 1, padding=2)),
|
654 |
+
]
|
655 |
+
)
|
656 |
+
self.conv_post = norm_f(Conv1d(1024, 1, 3, 1, padding=1))
|
657 |
+
|
658 |
+
def forward(self, x):
|
659 |
+
fmap = []
|
660 |
+
|
661 |
+
for layer in self.convs:
|
662 |
+
x = layer(x)
|
663 |
+
x = F.leaky_relu(x, modules.LRELU_SLOPE)
|
664 |
+
fmap.append(x)
|
665 |
+
x = self.conv_post(x)
|
666 |
+
fmap.append(x)
|
667 |
+
x = torch.flatten(x, 1, -1)
|
668 |
+
|
669 |
+
return x, fmap
|
670 |
+
|
671 |
+
|
672 |
+
class MultiPeriodDiscriminator(torch.nn.Module):
|
673 |
+
def __init__(self, use_spectral_norm=False):
|
674 |
+
super(MultiPeriodDiscriminator, self).__init__()
|
675 |
+
periods = [2, 3, 5, 7, 11]
|
676 |
+
|
677 |
+
discs = [DiscriminatorS(use_spectral_norm=use_spectral_norm)]
|
678 |
+
discs = discs + [
|
679 |
+
DiscriminatorP(i, use_spectral_norm=use_spectral_norm) for i in periods
|
680 |
+
]
|
681 |
+
self.discriminators = nn.ModuleList(discs)
|
682 |
+
|
683 |
+
def forward(self, y, y_hat):
|
684 |
+
y_d_rs = []
|
685 |
+
y_d_gs = []
|
686 |
+
fmap_rs = []
|
687 |
+
fmap_gs = []
|
688 |
+
for i, d in enumerate(self.discriminators):
|
689 |
+
y_d_r, fmap_r = d(y)
|
690 |
+
y_d_g, fmap_g = d(y_hat)
|
691 |
+
y_d_rs.append(y_d_r)
|
692 |
+
y_d_gs.append(y_d_g)
|
693 |
+
fmap_rs.append(fmap_r)
|
694 |
+
fmap_gs.append(fmap_g)
|
695 |
+
|
696 |
+
return y_d_rs, y_d_gs, fmap_rs, fmap_gs
|
697 |
+
|
698 |
+
|
699 |
+
class WavLMDiscriminator(nn.Module):
|
700 |
+
"""docstring for Discriminator."""
|
701 |
+
|
702 |
+
def __init__(
|
703 |
+
self, slm_hidden=768, slm_layers=13, initial_channel=64, use_spectral_norm=False
|
704 |
+
):
|
705 |
+
super(WavLMDiscriminator, self).__init__()
|
706 |
+
norm_f = weight_norm if use_spectral_norm == False else spectral_norm
|
707 |
+
self.pre = norm_f(
|
708 |
+
Conv1d(slm_hidden * slm_layers, initial_channel, 1, 1, padding=0)
|
709 |
+
)
|
710 |
+
|
711 |
+
self.convs = nn.ModuleList(
|
712 |
+
[
|
713 |
+
norm_f(
|
714 |
+
nn.Conv1d(
|
715 |
+
initial_channel, initial_channel * 2, kernel_size=5, padding=2
|
716 |
+
)
|
717 |
+
),
|
718 |
+
norm_f(
|
719 |
+
nn.Conv1d(
|
720 |
+
initial_channel * 2,
|
721 |
+
initial_channel * 4,
|
722 |
+
kernel_size=5,
|
723 |
+
padding=2,
|
724 |
+
)
|
725 |
+
),
|
726 |
+
norm_f(
|
727 |
+
nn.Conv1d(initial_channel * 4,
|
728 |
+
initial_channel * 4, 5, 1, padding=2)
|
729 |
+
),
|
730 |
+
]
|
731 |
+
)
|
732 |
+
|
733 |
+
self.conv_post = norm_f(
|
734 |
+
Conv1d(initial_channel * 4, 1, 3, 1, padding=1))
|
735 |
+
|
736 |
+
def forward(self, x):
|
737 |
+
x = self.pre(x)
|
738 |
+
|
739 |
+
fmap = []
|
740 |
+
for l in self.convs:
|
741 |
+
x = l(x)
|
742 |
+
x = F.leaky_relu(x, modules.LRELU_SLOPE)
|
743 |
+
fmap.append(x)
|
744 |
+
x = self.conv_post(x)
|
745 |
+
x = torch.flatten(x, 1, -1)
|
746 |
+
|
747 |
+
return x
|
748 |
+
|
749 |
+
|
750 |
+
class ReferenceEncoder(nn.Module):
|
751 |
+
"""
|
752 |
+
inputs --- [N, Ty/r, n_mels*r] mels
|
753 |
+
outputs --- [N, ref_enc_gru_size]
|
754 |
+
"""
|
755 |
+
|
756 |
+
def __init__(self, spec_channels, gin_channels=0):
|
757 |
+
super().__init__()
|
758 |
+
self.spec_channels = spec_channels
|
759 |
+
ref_enc_filters = [32, 32, 64, 64, 128, 128]
|
760 |
+
K = len(ref_enc_filters)
|
761 |
+
filters = [1] + ref_enc_filters
|
762 |
+
convs = [
|
763 |
+
weight_norm(
|
764 |
+
nn.Conv2d(
|
765 |
+
in_channels=filters[i],
|
766 |
+
out_channels=filters[i + 1],
|
767 |
+
kernel_size=(3, 3),
|
768 |
+
stride=(2, 2),
|
769 |
+
padding=(1, 1),
|
770 |
+
)
|
771 |
+
)
|
772 |
+
for i in range(K)
|
773 |
+
]
|
774 |
+
self.convs = nn.ModuleList(convs)
|
775 |
+
# self.wns = nn.ModuleList([weight_norm(num_features=ref_enc_filters[i]) for i in range(K)]) # noqa: E501
|
776 |
+
|
777 |
+
out_channels = self.calculate_channels(spec_channels, 3, 2, 1, K)
|
778 |
+
self.gru = nn.GRU(
|
779 |
+
input_size=ref_enc_filters[-1] * out_channels,
|
780 |
+
hidden_size=256 // 2,
|
781 |
+
batch_first=True,
|
782 |
+
)
|
783 |
+
self.proj = nn.Linear(128, gin_channels)
|
784 |
+
|
785 |
+
def forward(self, inputs, mask=None):
|
786 |
+
N = inputs.size(0)
|
787 |
+
out = inputs.view(N, 1, -1, self.spec_channels) # [N, 1, Ty, n_freqs]
|
788 |
+
for conv in self.convs:
|
789 |
+
out = conv(out)
|
790 |
+
# out = wn(out)
|
791 |
+
out = F.relu(out) # [N, 128, Ty//2^K, n_mels//2^K]
|
792 |
+
|
793 |
+
out = out.transpose(1, 2) # [N, Ty//2^K, 128, n_mels//2^K]
|
794 |
+
T = out.size(1)
|
795 |
+
N = out.size(0)
|
796 |
+
out = out.contiguous().view(N, T, -1) # [N, Ty//2^K, 128*n_mels//2^K]
|
797 |
+
|
798 |
+
self.gru.flatten_parameters()
|
799 |
+
memory, out = self.gru(out) # out --- [1, N, 128]
|
800 |
+
|
801 |
+
return self.proj(out.squeeze(0))
|
802 |
+
|
803 |
+
def calculate_channels(self, L, kernel_size, stride, pad, n_convs):
|
804 |
+
for i in range(n_convs):
|
805 |
+
L = (L - kernel_size + 2 * pad) // stride + 1
|
806 |
+
return L
|
807 |
+
|
808 |
+
|
809 |
+
class SynthesizerTrn(nn.Module):
|
810 |
+
"""
|
811 |
+
Synthesizer for Training
|
812 |
+
"""
|
813 |
+
|
814 |
+
def __init__(
|
815 |
+
self,
|
816 |
+
n_vocab,
|
817 |
+
spec_channels,
|
818 |
+
segment_size,
|
819 |
+
inter_channels,
|
820 |
+
hidden_channels,
|
821 |
+
filter_channels,
|
822 |
+
n_heads,
|
823 |
+
n_layers,
|
824 |
+
kernel_size,
|
825 |
+
p_dropout,
|
826 |
+
resblock,
|
827 |
+
resblock_kernel_sizes,
|
828 |
+
resblock_dilation_sizes,
|
829 |
+
upsample_rates,
|
830 |
+
upsample_initial_channel,
|
831 |
+
upsample_kernel_sizes,
|
832 |
+
n_speakers=256,
|
833 |
+
gin_channels=256,
|
834 |
+
use_sdp=True,
|
835 |
+
n_flow_layer=4,
|
836 |
+
n_layers_trans_flow=4,
|
837 |
+
flow_share_parameter=False,
|
838 |
+
use_transformer_flow=True,
|
839 |
+
**kwargs
|
840 |
+
):
|
841 |
+
super().__init__()
|
842 |
+
self.n_vocab = n_vocab
|
843 |
+
self.spec_channels = spec_channels
|
844 |
+
self.inter_channels = inter_channels
|
845 |
+
self.hidden_channels = hidden_channels
|
846 |
+
self.filter_channels = filter_channels
|
847 |
+
self.n_heads = n_heads
|
848 |
+
self.n_layers = n_layers
|
849 |
+
self.kernel_size = kernel_size
|
850 |
+
self.p_dropout = p_dropout
|
851 |
+
self.resblock = resblock
|
852 |
+
self.resblock_kernel_sizes = resblock_kernel_sizes
|
853 |
+
self.resblock_dilation_sizes = resblock_dilation_sizes
|
854 |
+
self.upsample_rates = upsample_rates
|
855 |
+
self.upsample_initial_channel = upsample_initial_channel
|
856 |
+
self.upsample_kernel_sizes = upsample_kernel_sizes
|
857 |
+
self.segment_size = segment_size
|
858 |
+
self.n_speakers = n_speakers
|
859 |
+
self.gin_channels = gin_channels
|
860 |
+
self.n_layers_trans_flow = n_layers_trans_flow
|
861 |
+
self.use_spk_conditioned_encoder = kwargs.get(
|
862 |
+
"use_spk_conditioned_encoder", True
|
863 |
+
)
|
864 |
+
self.use_sdp = use_sdp
|
865 |
+
self.use_noise_scaled_mas = kwargs.get("use_noise_scaled_mas", False)
|
866 |
+
self.mas_noise_scale_initial = kwargs.get(
|
867 |
+
"mas_noise_scale_initial", 0.01)
|
868 |
+
self.noise_scale_delta = kwargs.get("noise_scale_delta", 2e-6)
|
869 |
+
self.current_mas_noise_scale = self.mas_noise_scale_initial
|
870 |
+
if self.use_spk_conditioned_encoder and gin_channels > 0:
|
871 |
+
self.enc_gin_channels = gin_channels
|
872 |
+
self.enc_p = TextEncoder(
|
873 |
+
n_vocab,
|
874 |
+
inter_channels,
|
875 |
+
hidden_channels,
|
876 |
+
filter_channels,
|
877 |
+
n_heads,
|
878 |
+
n_layers,
|
879 |
+
kernel_size,
|
880 |
+
p_dropout,
|
881 |
+
gin_channels=self.enc_gin_channels,
|
882 |
+
)
|
883 |
+
self.dec = Generator(
|
884 |
+
inter_channels,
|
885 |
+
resblock,
|
886 |
+
resblock_kernel_sizes,
|
887 |
+
resblock_dilation_sizes,
|
888 |
+
upsample_rates,
|
889 |
+
upsample_initial_channel,
|
890 |
+
upsample_kernel_sizes,
|
891 |
+
gin_channels=gin_channels,
|
892 |
+
)
|
893 |
+
self.enc_q = PosteriorEncoder(
|
894 |
+
spec_channels,
|
895 |
+
inter_channels,
|
896 |
+
hidden_channels,
|
897 |
+
5,
|
898 |
+
1,
|
899 |
+
16,
|
900 |
+
gin_channels=gin_channels,
|
901 |
+
)
|
902 |
+
if use_transformer_flow:
|
903 |
+
self.flow = TransformerCouplingBlock(
|
904 |
+
inter_channels,
|
905 |
+
hidden_channels,
|
906 |
+
filter_channels,
|
907 |
+
n_heads,
|
908 |
+
n_layers_trans_flow,
|
909 |
+
5,
|
910 |
+
p_dropout,
|
911 |
+
n_flow_layer,
|
912 |
+
gin_channels=gin_channels,
|
913 |
+
share_parameter=flow_share_parameter,
|
914 |
+
)
|
915 |
+
else:
|
916 |
+
self.flow = ResidualCouplingBlock(
|
917 |
+
inter_channels,
|
918 |
+
hidden_channels,
|
919 |
+
5,
|
920 |
+
1,
|
921 |
+
n_flow_layer,
|
922 |
+
gin_channels=gin_channels,
|
923 |
+
)
|
924 |
+
self.sdp = StochasticDurationPredictor(
|
925 |
+
hidden_channels, 192, 3, 0.5, 4, gin_channels=gin_channels
|
926 |
+
)
|
927 |
+
self.dp = DurationPredictor(
|
928 |
+
hidden_channels, 256, 3, 0.5, gin_channels=gin_channels
|
929 |
+
)
|
930 |
+
|
931 |
+
if n_speakers >= 1:
|
932 |
+
self.emb_g = nn.Embedding(n_speakers, gin_channels)
|
933 |
+
else:
|
934 |
+
self.ref_enc = ReferenceEncoder(spec_channels, gin_channels)
|
935 |
+
|
936 |
+
def forward(
|
937 |
+
self,
|
938 |
+
x,
|
939 |
+
x_lengths,
|
940 |
+
y,
|
941 |
+
y_lengths,
|
942 |
+
sid,
|
943 |
+
tone,
|
944 |
+
language,
|
945 |
+
):
|
946 |
+
if self.n_speakers > 0:
|
947 |
+
g = self.emb_g(sid).unsqueeze(-1) # [b, h, 1]
|
948 |
+
else:
|
949 |
+
g = self.ref_enc(y.transpose(1, 2)).unsqueeze(-1)
|
950 |
+
x, m_p, logs_p, x_mask = self.enc_p(
|
951 |
+
x, x_lengths, tone, language, g=g
|
952 |
+
)
|
953 |
+
z, m_q, logs_q, y_mask = self.enc_q(y, y_lengths, g=g)
|
954 |
+
z_p = self.flow(z, y_mask, g=g)
|
955 |
+
|
956 |
+
with torch.no_grad():
|
957 |
+
# negative cross-entropy
|
958 |
+
s_p_sq_r = torch.exp(-2 * logs_p) # [b, d, t]
|
959 |
+
neg_cent1 = torch.sum(
|
960 |
+
-0.5 * math.log(2 * math.pi) - logs_p, [1], keepdim=True
|
961 |
+
) # [b, 1, t_s]
|
962 |
+
neg_cent2 = torch.matmul(
|
963 |
+
-0.5 * (z_p**2).transpose(1, 2), s_p_sq_r
|
964 |
+
) # [b, t_t, d] x [b, d, t_s] = [b, t_t, t_s]
|
965 |
+
neg_cent3 = torch.matmul(
|
966 |
+
z_p.transpose(1, 2), (m_p * s_p_sq_r)
|
967 |
+
) # [b, t_t, d] x [b, d, t_s] = [b, t_t, t_s]
|
968 |
+
neg_cent4 = torch.sum(
|
969 |
+
-0.5 * (m_p**2) * s_p_sq_r, [1], keepdim=True
|
970 |
+
) # [b, 1, t_s]
|
971 |
+
neg_cent = neg_cent1 + neg_cent2 + neg_cent3 + neg_cent4
|
972 |
+
if self.use_noise_scaled_mas:
|
973 |
+
epsilon = (
|
974 |
+
torch.std(neg_cent)
|
975 |
+
* torch.randn_like(neg_cent)
|
976 |
+
* self.current_mas_noise_scale
|
977 |
+
)
|
978 |
+
neg_cent = neg_cent + epsilon
|
979 |
+
|
980 |
+
attn_mask = torch.unsqueeze(
|
981 |
+
x_mask, 2) * torch.unsqueeze(y_mask, -1)
|
982 |
+
attn = (
|
983 |
+
monotonic_align.maximum_path(neg_cent, attn_mask.squeeze(1))
|
984 |
+
.unsqueeze(1)
|
985 |
+
.detach()
|
986 |
+
)
|
987 |
+
|
988 |
+
w = attn.sum(2)
|
989 |
+
|
990 |
+
l_length_sdp = self.sdp(x, x_mask, w, g=g)
|
991 |
+
l_length_sdp = l_length_sdp / torch.sum(x_mask)
|
992 |
+
|
993 |
+
logw_ = torch.log(w + 1e-6) * x_mask
|
994 |
+
logw = self.dp(x, x_mask, g=g)
|
995 |
+
logw_sdp = self.sdp(x, x_mask, g=g, reverse=True, noise_scale=1.0)
|
996 |
+
l_length_dp = torch.sum((logw - logw_) ** 2, [1, 2]) / torch.sum(
|
997 |
+
x_mask
|
998 |
+
) # for averaging
|
999 |
+
l_length_sdp += torch.sum((logw_sdp - logw_)
|
1000 |
+
** 2, [1, 2]) / torch.sum(x_mask)
|
1001 |
+
|
1002 |
+
l_length = l_length_dp + l_length_sdp
|
1003 |
+
|
1004 |
+
# expand prior
|
1005 |
+
m_p = torch.matmul(attn.squeeze(
|
1006 |
+
1), m_p.transpose(1, 2)).transpose(1, 2)
|
1007 |
+
logs_p = torch.matmul(attn.squeeze(
|
1008 |
+
1), logs_p.transpose(1, 2)).transpose(1, 2)
|
1009 |
+
|
1010 |
+
z_slice, ids_slice = commons.rand_slice_segments(
|
1011 |
+
z, y_lengths, self.segment_size
|
1012 |
+
)
|
1013 |
+
o = self.dec(z_slice, g=g)
|
1014 |
+
return (
|
1015 |
+
o,
|
1016 |
+
l_length,
|
1017 |
+
attn,
|
1018 |
+
ids_slice,
|
1019 |
+
x_mask,
|
1020 |
+
y_mask,
|
1021 |
+
(z, z_p, m_p, logs_p, m_q, logs_q),
|
1022 |
+
(x, logw, logw_, logw_sdp),
|
1023 |
+
g,
|
1024 |
+
)
|
1025 |
+
|
1026 |
+
def infer(
|
1027 |
+
self,
|
1028 |
+
x,
|
1029 |
+
x_lengths,
|
1030 |
+
sid,
|
1031 |
+
tone,
|
1032 |
+
language,
|
1033 |
+
noise_scale=0.667,
|
1034 |
+
length_scale=1,
|
1035 |
+
noise_scale_w=0.8,
|
1036 |
+
max_len=None,
|
1037 |
+
sdp_ratio=0,
|
1038 |
+
y=None,
|
1039 |
+
):
|
1040 |
+
# x, m_p, logs_p, x_mask = self.enc_p(x, x_lengths, tone, language, bert)
|
1041 |
+
# g = self.gst(y)
|
1042 |
+
if self.n_speakers > 0:
|
1043 |
+
g = self.emb_g(sid).unsqueeze(-1) # [b, h, 1]
|
1044 |
+
else:
|
1045 |
+
g = self.ref_enc(y.transpose(1, 2)).unsqueeze(-1)
|
1046 |
+
x, m_p, logs_p, x_mask = self.enc_p(
|
1047 |
+
x, x_lengths, tone, language, g=g
|
1048 |
+
)
|
1049 |
+
logw = self.sdp(x, x_mask, g=g, reverse=True, noise_scale=noise_scale_w) * (
|
1050 |
+
sdp_ratio
|
1051 |
+
) + self.dp(x, x_mask, g=g) * (1 - sdp_ratio)
|
1052 |
+
w = torch.exp(logw) * x_mask * length_scale
|
1053 |
+
w_ceil = torch.ceil(w)
|
1054 |
+
y_lengths = torch.clamp_min(torch.sum(w_ceil, [1, 2]), 1).long()
|
1055 |
+
y_mask = torch.unsqueeze(commons.sequence_mask(y_lengths, None), 1).to(
|
1056 |
+
x_mask.dtype
|
1057 |
+
)
|
1058 |
+
attn_mask = torch.unsqueeze(x_mask, 2) * torch.unsqueeze(y_mask, -1)
|
1059 |
+
attn = commons.generate_path(w_ceil, attn_mask)
|
1060 |
+
|
1061 |
+
m_p = torch.matmul(attn.squeeze(1), m_p.transpose(1, 2)).transpose(
|
1062 |
+
1, 2
|
1063 |
+
) # [b, t', t], [b, t, d] -> [b, d, t']
|
1064 |
+
logs_p = torch.matmul(attn.squeeze(1), logs_p.transpose(1, 2)).transpose(
|
1065 |
+
1, 2
|
1066 |
+
) # [b, t', t], [b, t, d] -> [b, d, t']
|
1067 |
+
|
1068 |
+
z_p = m_p + torch.randn_like(m_p) * torch.exp(logs_p) * noise_scale
|
1069 |
+
z = self.flow(z_p, y_mask, g=g, reverse=True)
|
1070 |
+
o = self.dec((z * y_mask)[:, :, :max_len], g=g)
|
1071 |
+
return o, attn, y_mask, (z, z_p, m_p, logs_p)
|
modules.py
ADDED
@@ -0,0 +1,580 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import torch
|
3 |
+
from torch import nn
|
4 |
+
from torch.nn import functional as F
|
5 |
+
|
6 |
+
from torch.nn import Conv1d
|
7 |
+
from torch.nn.utils import weight_norm, remove_weight_norm
|
8 |
+
|
9 |
+
import commons
|
10 |
+
from commons import init_weights, get_padding
|
11 |
+
from transforms import piecewise_rational_quadratic_transform
|
12 |
+
from attentions import Encoder
|
13 |
+
|
14 |
+
LRELU_SLOPE = 0.1
|
15 |
+
|
16 |
+
|
17 |
+
class LayerNorm(nn.Module):
|
18 |
+
def __init__(self, channels, eps=1e-5):
|
19 |
+
super().__init__()
|
20 |
+
self.channels = channels
|
21 |
+
self.eps = eps
|
22 |
+
|
23 |
+
self.gamma = nn.Parameter(torch.ones(channels))
|
24 |
+
self.beta = nn.Parameter(torch.zeros(channels))
|
25 |
+
|
26 |
+
def forward(self, x):
|
27 |
+
x = x.transpose(1, -1)
|
28 |
+
x = F.layer_norm(x, (self.channels,), self.gamma, self.beta, self.eps)
|
29 |
+
return x.transpose(1, -1)
|
30 |
+
|
31 |
+
|
32 |
+
class ConvReluNorm(nn.Module):
|
33 |
+
def __init__(
|
34 |
+
self,
|
35 |
+
in_channels,
|
36 |
+
hidden_channels,
|
37 |
+
out_channels,
|
38 |
+
kernel_size,
|
39 |
+
n_layers,
|
40 |
+
p_dropout,
|
41 |
+
):
|
42 |
+
super().__init__()
|
43 |
+
self.in_channels = in_channels
|
44 |
+
self.hidden_channels = hidden_channels
|
45 |
+
self.out_channels = out_channels
|
46 |
+
self.kernel_size = kernel_size
|
47 |
+
self.n_layers = n_layers
|
48 |
+
self.p_dropout = p_dropout
|
49 |
+
assert n_layers > 1, "Number of layers should be larger than 0."
|
50 |
+
|
51 |
+
self.conv_layers = nn.ModuleList()
|
52 |
+
self.norm_layers = nn.ModuleList()
|
53 |
+
self.conv_layers.append(
|
54 |
+
nn.Conv1d(
|
55 |
+
in_channels, hidden_channels, kernel_size, padding=kernel_size // 2
|
56 |
+
)
|
57 |
+
)
|
58 |
+
self.norm_layers.append(LayerNorm(hidden_channels))
|
59 |
+
self.relu_drop = nn.Sequential(nn.ReLU(), nn.Dropout(p_dropout))
|
60 |
+
for _ in range(n_layers - 1):
|
61 |
+
self.conv_layers.append(
|
62 |
+
nn.Conv1d(
|
63 |
+
hidden_channels,
|
64 |
+
hidden_channels,
|
65 |
+
kernel_size,
|
66 |
+
padding=kernel_size // 2,
|
67 |
+
)
|
68 |
+
)
|
69 |
+
self.norm_layers.append(LayerNorm(hidden_channels))
|
70 |
+
self.proj = nn.Conv1d(hidden_channels, out_channels, 1)
|
71 |
+
self.proj.weight.data.zero_()
|
72 |
+
self.proj.bias.data.zero_()
|
73 |
+
|
74 |
+
def forward(self, x, x_mask):
|
75 |
+
x_org = x
|
76 |
+
for i in range(self.n_layers):
|
77 |
+
x = self.conv_layers[i](x * x_mask)
|
78 |
+
x = self.norm_layers[i](x)
|
79 |
+
x = self.relu_drop(x)
|
80 |
+
x = x_org + self.proj(x)
|
81 |
+
return x * x_mask
|
82 |
+
|
83 |
+
|
84 |
+
class DDSConv(nn.Module):
|
85 |
+
"""
|
86 |
+
Dilated and Depth-Separable Convolution
|
87 |
+
"""
|
88 |
+
|
89 |
+
def __init__(self, channels, kernel_size, n_layers, p_dropout=0.0):
|
90 |
+
super().__init__()
|
91 |
+
self.channels = channels
|
92 |
+
self.kernel_size = kernel_size
|
93 |
+
self.n_layers = n_layers
|
94 |
+
self.p_dropout = p_dropout
|
95 |
+
|
96 |
+
self.drop = nn.Dropout(p_dropout)
|
97 |
+
self.convs_sep = nn.ModuleList()
|
98 |
+
self.convs_1x1 = nn.ModuleList()
|
99 |
+
self.norms_1 = nn.ModuleList()
|
100 |
+
self.norms_2 = nn.ModuleList()
|
101 |
+
for i in range(n_layers):
|
102 |
+
dilation = kernel_size**i
|
103 |
+
padding = (kernel_size * dilation - dilation) // 2
|
104 |
+
self.convs_sep.append(
|
105 |
+
nn.Conv1d(
|
106 |
+
channels,
|
107 |
+
channels,
|
108 |
+
kernel_size,
|
109 |
+
groups=channels,
|
110 |
+
dilation=dilation,
|
111 |
+
padding=padding,
|
112 |
+
)
|
113 |
+
)
|
114 |
+
self.convs_1x1.append(nn.Conv1d(channels, channels, 1))
|
115 |
+
self.norms_1.append(LayerNorm(channels))
|
116 |
+
self.norms_2.append(LayerNorm(channels))
|
117 |
+
|
118 |
+
def forward(self, x, x_mask, g=None):
|
119 |
+
if g is not None:
|
120 |
+
x = x + g
|
121 |
+
for i in range(self.n_layers):
|
122 |
+
y = self.convs_sep[i](x * x_mask)
|
123 |
+
y = self.norms_1[i](y)
|
124 |
+
y = F.gelu(y)
|
125 |
+
y = self.convs_1x1[i](y)
|
126 |
+
y = self.norms_2[i](y)
|
127 |
+
y = F.gelu(y)
|
128 |
+
y = self.drop(y)
|
129 |
+
x = x + y
|
130 |
+
return x * x_mask
|
131 |
+
|
132 |
+
|
133 |
+
class WN(torch.nn.Module):
|
134 |
+
def __init__(
|
135 |
+
self,
|
136 |
+
hidden_channels,
|
137 |
+
kernel_size,
|
138 |
+
dilation_rate,
|
139 |
+
n_layers,
|
140 |
+
gin_channels=0,
|
141 |
+
p_dropout=0,
|
142 |
+
):
|
143 |
+
super(WN, self).__init__()
|
144 |
+
assert kernel_size % 2 == 1
|
145 |
+
self.hidden_channels = hidden_channels
|
146 |
+
self.kernel_size = (kernel_size,)
|
147 |
+
self.dilation_rate = dilation_rate
|
148 |
+
self.n_layers = n_layers
|
149 |
+
self.gin_channels = gin_channels
|
150 |
+
self.p_dropout = p_dropout
|
151 |
+
|
152 |
+
self.in_layers = torch.nn.ModuleList()
|
153 |
+
self.res_skip_layers = torch.nn.ModuleList()
|
154 |
+
self.drop = nn.Dropout(p_dropout)
|
155 |
+
|
156 |
+
if gin_channels != 0:
|
157 |
+
cond_layer = torch.nn.Conv1d(
|
158 |
+
gin_channels, 2 * hidden_channels * n_layers, 1
|
159 |
+
)
|
160 |
+
self.cond_layer = torch.nn.utils.weight_norm(cond_layer, name="weight")
|
161 |
+
|
162 |
+
for i in range(n_layers):
|
163 |
+
dilation = dilation_rate**i
|
164 |
+
padding = int((kernel_size * dilation - dilation) / 2)
|
165 |
+
in_layer = torch.nn.Conv1d(
|
166 |
+
hidden_channels,
|
167 |
+
2 * hidden_channels,
|
168 |
+
kernel_size,
|
169 |
+
dilation=dilation,
|
170 |
+
padding=padding,
|
171 |
+
)
|
172 |
+
in_layer = torch.nn.utils.weight_norm(in_layer, name="weight")
|
173 |
+
self.in_layers.append(in_layer)
|
174 |
+
|
175 |
+
# last one is not necessary
|
176 |
+
if i < n_layers - 1:
|
177 |
+
res_skip_channels = 2 * hidden_channels
|
178 |
+
else:
|
179 |
+
res_skip_channels = hidden_channels
|
180 |
+
|
181 |
+
res_skip_layer = torch.nn.Conv1d(hidden_channels, res_skip_channels, 1)
|
182 |
+
res_skip_layer = torch.nn.utils.weight_norm(res_skip_layer, name="weight")
|
183 |
+
self.res_skip_layers.append(res_skip_layer)
|
184 |
+
|
185 |
+
def forward(self, x, x_mask, g=None, **kwargs):
|
186 |
+
output = torch.zeros_like(x)
|
187 |
+
n_channels_tensor = torch.IntTensor([self.hidden_channels])
|
188 |
+
|
189 |
+
if g is not None:
|
190 |
+
g = self.cond_layer(g)
|
191 |
+
|
192 |
+
for i in range(self.n_layers):
|
193 |
+
x_in = self.in_layers[i](x)
|
194 |
+
if g is not None:
|
195 |
+
cond_offset = i * 2 * self.hidden_channels
|
196 |
+
g_l = g[:, cond_offset : cond_offset + 2 * self.hidden_channels, :]
|
197 |
+
else:
|
198 |
+
g_l = torch.zeros_like(x_in)
|
199 |
+
|
200 |
+
acts = commons.fused_add_tanh_sigmoid_multiply(x_in, g_l, n_channels_tensor)
|
201 |
+
acts = self.drop(acts)
|
202 |
+
|
203 |
+
res_skip_acts = self.res_skip_layers[i](acts)
|
204 |
+
if i < self.n_layers - 1:
|
205 |
+
res_acts = res_skip_acts[:, : self.hidden_channels, :]
|
206 |
+
x = (x + res_acts) * x_mask
|
207 |
+
output = output + res_skip_acts[:, self.hidden_channels :, :]
|
208 |
+
else:
|
209 |
+
output = output + res_skip_acts
|
210 |
+
return output * x_mask
|
211 |
+
|
212 |
+
def remove_weight_norm(self):
|
213 |
+
if self.gin_channels != 0:
|
214 |
+
torch.nn.utils.remove_weight_norm(self.cond_layer)
|
215 |
+
for l in self.in_layers:
|
216 |
+
torch.nn.utils.remove_weight_norm(l)
|
217 |
+
for l in self.res_skip_layers:
|
218 |
+
torch.nn.utils.remove_weight_norm(l)
|
219 |
+
|
220 |
+
|
221 |
+
class ResBlock1(torch.nn.Module):
|
222 |
+
def __init__(self, channels, kernel_size=3, dilation=(1, 3, 5)):
|
223 |
+
super(ResBlock1, self).__init__()
|
224 |
+
self.convs1 = nn.ModuleList(
|
225 |
+
[
|
226 |
+
weight_norm(
|
227 |
+
Conv1d(
|
228 |
+
channels,
|
229 |
+
channels,
|
230 |
+
kernel_size,
|
231 |
+
1,
|
232 |
+
dilation=dilation[0],
|
233 |
+
padding=get_padding(kernel_size, dilation[0]),
|
234 |
+
)
|
235 |
+
),
|
236 |
+
weight_norm(
|
237 |
+
Conv1d(
|
238 |
+
channels,
|
239 |
+
channels,
|
240 |
+
kernel_size,
|
241 |
+
1,
|
242 |
+
dilation=dilation[1],
|
243 |
+
padding=get_padding(kernel_size, dilation[1]),
|
244 |
+
)
|
245 |
+
),
|
246 |
+
weight_norm(
|
247 |
+
Conv1d(
|
248 |
+
channels,
|
249 |
+
channels,
|
250 |
+
kernel_size,
|
251 |
+
1,
|
252 |
+
dilation=dilation[2],
|
253 |
+
padding=get_padding(kernel_size, dilation[2]),
|
254 |
+
)
|
255 |
+
),
|
256 |
+
]
|
257 |
+
)
|
258 |
+
self.convs1.apply(init_weights)
|
259 |
+
|
260 |
+
self.convs2 = nn.ModuleList(
|
261 |
+
[
|
262 |
+
weight_norm(
|
263 |
+
Conv1d(
|
264 |
+
channels,
|
265 |
+
channels,
|
266 |
+
kernel_size,
|
267 |
+
1,
|
268 |
+
dilation=1,
|
269 |
+
padding=get_padding(kernel_size, 1),
|
270 |
+
)
|
271 |
+
),
|
272 |
+
weight_norm(
|
273 |
+
Conv1d(
|
274 |
+
channels,
|
275 |
+
channels,
|
276 |
+
kernel_size,
|
277 |
+
1,
|
278 |
+
dilation=1,
|
279 |
+
padding=get_padding(kernel_size, 1),
|
280 |
+
)
|
281 |
+
),
|
282 |
+
weight_norm(
|
283 |
+
Conv1d(
|
284 |
+
channels,
|
285 |
+
channels,
|
286 |
+
kernel_size,
|
287 |
+
1,
|
288 |
+
dilation=1,
|
289 |
+
padding=get_padding(kernel_size, 1),
|
290 |
+
)
|
291 |
+
),
|
292 |
+
]
|
293 |
+
)
|
294 |
+
self.convs2.apply(init_weights)
|
295 |
+
|
296 |
+
def forward(self, x, x_mask=None):
|
297 |
+
for c1, c2 in zip(self.convs1, self.convs2):
|
298 |
+
xt = F.leaky_relu(x, LRELU_SLOPE)
|
299 |
+
if x_mask is not None:
|
300 |
+
xt = xt * x_mask
|
301 |
+
xt = c1(xt)
|
302 |
+
xt = F.leaky_relu(xt, LRELU_SLOPE)
|
303 |
+
if x_mask is not None:
|
304 |
+
xt = xt * x_mask
|
305 |
+
xt = c2(xt)
|
306 |
+
x = xt + x
|
307 |
+
if x_mask is not None:
|
308 |
+
x = x * x_mask
|
309 |
+
return x
|
310 |
+
|
311 |
+
def remove_weight_norm(self):
|
312 |
+
for l in self.convs1:
|
313 |
+
remove_weight_norm(l)
|
314 |
+
for l in self.convs2:
|
315 |
+
remove_weight_norm(l)
|
316 |
+
|
317 |
+
|
318 |
+
class ResBlock2(torch.nn.Module):
|
319 |
+
def __init__(self, channels, kernel_size=3, dilation=(1, 3)):
|
320 |
+
super(ResBlock2, self).__init__()
|
321 |
+
self.convs = nn.ModuleList(
|
322 |
+
[
|
323 |
+
weight_norm(
|
324 |
+
Conv1d(
|
325 |
+
channels,
|
326 |
+
channels,
|
327 |
+
kernel_size,
|
328 |
+
1,
|
329 |
+
dilation=dilation[0],
|
330 |
+
padding=get_padding(kernel_size, dilation[0]),
|
331 |
+
)
|
332 |
+
),
|
333 |
+
weight_norm(
|
334 |
+
Conv1d(
|
335 |
+
channels,
|
336 |
+
channels,
|
337 |
+
kernel_size,
|
338 |
+
1,
|
339 |
+
dilation=dilation[1],
|
340 |
+
padding=get_padding(kernel_size, dilation[1]),
|
341 |
+
)
|
342 |
+
),
|
343 |
+
]
|
344 |
+
)
|
345 |
+
self.convs.apply(init_weights)
|
346 |
+
|
347 |
+
def forward(self, x, x_mask=None):
|
348 |
+
for c in self.convs:
|
349 |
+
xt = F.leaky_relu(x, LRELU_SLOPE)
|
350 |
+
if x_mask is not None:
|
351 |
+
xt = xt * x_mask
|
352 |
+
xt = c(xt)
|
353 |
+
x = xt + x
|
354 |
+
if x_mask is not None:
|
355 |
+
x = x * x_mask
|
356 |
+
return x
|
357 |
+
|
358 |
+
def remove_weight_norm(self):
|
359 |
+
for l in self.convs:
|
360 |
+
remove_weight_norm(l)
|
361 |
+
|
362 |
+
|
363 |
+
class Log(nn.Module):
|
364 |
+
def forward(self, x, x_mask, reverse=False, **kwargs):
|
365 |
+
if not reverse:
|
366 |
+
y = torch.log(torch.clamp_min(x, 1e-5)) * x_mask
|
367 |
+
logdet = torch.sum(-y, [1, 2])
|
368 |
+
return y, logdet
|
369 |
+
else:
|
370 |
+
x = torch.exp(x) * x_mask
|
371 |
+
return x
|
372 |
+
|
373 |
+
|
374 |
+
class Flip(nn.Module):
|
375 |
+
def forward(self, x, *args, reverse=False, **kwargs):
|
376 |
+
x = torch.flip(x, [1])
|
377 |
+
if not reverse:
|
378 |
+
logdet = torch.zeros(x.size(0)).to(dtype=x.dtype, device=x.device)
|
379 |
+
return x, logdet
|
380 |
+
else:
|
381 |
+
return x
|
382 |
+
|
383 |
+
|
384 |
+
class ElementwiseAffine(nn.Module):
|
385 |
+
def __init__(self, channels):
|
386 |
+
super().__init__()
|
387 |
+
self.channels = channels
|
388 |
+
self.m = nn.Parameter(torch.zeros(channels, 1))
|
389 |
+
self.logs = nn.Parameter(torch.zeros(channels, 1))
|
390 |
+
|
391 |
+
def forward(self, x, x_mask, reverse=False, **kwargs):
|
392 |
+
if not reverse:
|
393 |
+
y = self.m + torch.exp(self.logs) * x
|
394 |
+
y = y * x_mask
|
395 |
+
logdet = torch.sum(self.logs * x_mask, [1, 2])
|
396 |
+
return y, logdet
|
397 |
+
else:
|
398 |
+
x = (x - self.m) * torch.exp(-self.logs) * x_mask
|
399 |
+
return x
|
400 |
+
|
401 |
+
|
402 |
+
class ResidualCouplingLayer(nn.Module):
|
403 |
+
def __init__(
|
404 |
+
self,
|
405 |
+
channels,
|
406 |
+
hidden_channels,
|
407 |
+
kernel_size,
|
408 |
+
dilation_rate,
|
409 |
+
n_layers,
|
410 |
+
p_dropout=0,
|
411 |
+
gin_channels=0,
|
412 |
+
mean_only=False,
|
413 |
+
):
|
414 |
+
assert channels % 2 == 0, "channels should be divisible by 2"
|
415 |
+
super().__init__()
|
416 |
+
self.channels = channels
|
417 |
+
self.hidden_channels = hidden_channels
|
418 |
+
self.kernel_size = kernel_size
|
419 |
+
self.dilation_rate = dilation_rate
|
420 |
+
self.n_layers = n_layers
|
421 |
+
self.half_channels = channels // 2
|
422 |
+
self.mean_only = mean_only
|
423 |
+
|
424 |
+
self.pre = nn.Conv1d(self.half_channels, hidden_channels, 1)
|
425 |
+
self.enc = WN(
|
426 |
+
hidden_channels,
|
427 |
+
kernel_size,
|
428 |
+
dilation_rate,
|
429 |
+
n_layers,
|
430 |
+
p_dropout=p_dropout,
|
431 |
+
gin_channels=gin_channels,
|
432 |
+
)
|
433 |
+
self.post = nn.Conv1d(hidden_channels, self.half_channels * (2 - mean_only), 1)
|
434 |
+
self.post.weight.data.zero_()
|
435 |
+
self.post.bias.data.zero_()
|
436 |
+
|
437 |
+
def forward(self, x, x_mask, g=None, reverse=False):
|
438 |
+
x0, x1 = torch.split(x, [self.half_channels] * 2, 1)
|
439 |
+
h = self.pre(x0) * x_mask
|
440 |
+
h = self.enc(h, x_mask, g=g)
|
441 |
+
stats = self.post(h) * x_mask
|
442 |
+
if not self.mean_only:
|
443 |
+
m, logs = torch.split(stats, [self.half_channels] * 2, 1)
|
444 |
+
else:
|
445 |
+
m = stats
|
446 |
+
logs = torch.zeros_like(m)
|
447 |
+
|
448 |
+
if not reverse:
|
449 |
+
x1 = m + x1 * torch.exp(logs) * x_mask
|
450 |
+
x = torch.cat([x0, x1], 1)
|
451 |
+
logdet = torch.sum(logs, [1, 2])
|
452 |
+
return x, logdet
|
453 |
+
else:
|
454 |
+
x1 = (x1 - m) * torch.exp(-logs) * x_mask
|
455 |
+
x = torch.cat([x0, x1], 1)
|
456 |
+
return x
|
457 |
+
|
458 |
+
|
459 |
+
class ConvFlow(nn.Module):
|
460 |
+
def __init__(
|
461 |
+
self,
|
462 |
+
in_channels,
|
463 |
+
filter_channels,
|
464 |
+
kernel_size,
|
465 |
+
n_layers,
|
466 |
+
num_bins=10,
|
467 |
+
tail_bound=5.0,
|
468 |
+
):
|
469 |
+
super().__init__()
|
470 |
+
self.in_channels = in_channels
|
471 |
+
self.filter_channels = filter_channels
|
472 |
+
self.kernel_size = kernel_size
|
473 |
+
self.n_layers = n_layers
|
474 |
+
self.num_bins = num_bins
|
475 |
+
self.tail_bound = tail_bound
|
476 |
+
self.half_channels = in_channels // 2
|
477 |
+
|
478 |
+
self.pre = nn.Conv1d(self.half_channels, filter_channels, 1)
|
479 |
+
self.convs = DDSConv(filter_channels, kernel_size, n_layers, p_dropout=0.0)
|
480 |
+
self.proj = nn.Conv1d(
|
481 |
+
filter_channels, self.half_channels * (num_bins * 3 - 1), 1
|
482 |
+
)
|
483 |
+
self.proj.weight.data.zero_()
|
484 |
+
self.proj.bias.data.zero_()
|
485 |
+
|
486 |
+
def forward(self, x, x_mask, g=None, reverse=False):
|
487 |
+
x0, x1 = torch.split(x, [self.half_channels] * 2, 1)
|
488 |
+
h = self.pre(x0)
|
489 |
+
h = self.convs(h, x_mask, g=g)
|
490 |
+
h = self.proj(h) * x_mask
|
491 |
+
|
492 |
+
b, c, t = x0.shape
|
493 |
+
h = h.reshape(b, c, -1, t).permute(0, 1, 3, 2) # [b, cx?, t] -> [b, c, t, ?]
|
494 |
+
|
495 |
+
unnormalized_widths = h[..., : self.num_bins] / math.sqrt(self.filter_channels)
|
496 |
+
unnormalized_heights = h[..., self.num_bins : 2 * self.num_bins] / math.sqrt(
|
497 |
+
self.filter_channels
|
498 |
+
)
|
499 |
+
unnormalized_derivatives = h[..., 2 * self.num_bins :]
|
500 |
+
|
501 |
+
x1, logabsdet = piecewise_rational_quadratic_transform(
|
502 |
+
x1,
|
503 |
+
unnormalized_widths,
|
504 |
+
unnormalized_heights,
|
505 |
+
unnormalized_derivatives,
|
506 |
+
inverse=reverse,
|
507 |
+
tails="linear",
|
508 |
+
tail_bound=self.tail_bound,
|
509 |
+
)
|
510 |
+
|
511 |
+
x = torch.cat([x0, x1], 1) * x_mask
|
512 |
+
logdet = torch.sum(logabsdet * x_mask, [1, 2])
|
513 |
+
if not reverse:
|
514 |
+
return x, logdet
|
515 |
+
else:
|
516 |
+
return x
|
517 |
+
|
518 |
+
|
519 |
+
class TransformerCouplingLayer(nn.Module):
|
520 |
+
def __init__(
|
521 |
+
self,
|
522 |
+
channels,
|
523 |
+
hidden_channels,
|
524 |
+
kernel_size,
|
525 |
+
n_layers,
|
526 |
+
n_heads,
|
527 |
+
p_dropout=0,
|
528 |
+
filter_channels=0,
|
529 |
+
mean_only=False,
|
530 |
+
wn_sharing_parameter=None,
|
531 |
+
gin_channels=0,
|
532 |
+
):
|
533 |
+
assert channels % 2 == 0, "channels should be divisible by 2"
|
534 |
+
super().__init__()
|
535 |
+
self.channels = channels
|
536 |
+
self.hidden_channels = hidden_channels
|
537 |
+
self.kernel_size = kernel_size
|
538 |
+
self.n_layers = n_layers
|
539 |
+
self.half_channels = channels // 2
|
540 |
+
self.mean_only = mean_only
|
541 |
+
|
542 |
+
self.pre = nn.Conv1d(self.half_channels, hidden_channels, 1)
|
543 |
+
self.enc = (
|
544 |
+
Encoder(
|
545 |
+
hidden_channels,
|
546 |
+
filter_channels,
|
547 |
+
n_heads,
|
548 |
+
n_layers,
|
549 |
+
kernel_size,
|
550 |
+
p_dropout,
|
551 |
+
isflow=True,
|
552 |
+
gin_channels=gin_channels,
|
553 |
+
)
|
554 |
+
if wn_sharing_parameter is None
|
555 |
+
else wn_sharing_parameter
|
556 |
+
)
|
557 |
+
self.post = nn.Conv1d(hidden_channels, self.half_channels * (2 - mean_only), 1)
|
558 |
+
self.post.weight.data.zero_()
|
559 |
+
self.post.bias.data.zero_()
|
560 |
+
|
561 |
+
def forward(self, x, x_mask, g=None, reverse=False):
|
562 |
+
x0, x1 = torch.split(x, [self.half_channels] * 2, 1)
|
563 |
+
h = self.pre(x0) * x_mask
|
564 |
+
h = self.enc(h, x_mask, g=g)
|
565 |
+
stats = self.post(h) * x_mask
|
566 |
+
if not self.mean_only:
|
567 |
+
m, logs = torch.split(stats, [self.half_channels] * 2, 1)
|
568 |
+
else:
|
569 |
+
m = stats
|
570 |
+
logs = torch.zeros_like(m)
|
571 |
+
|
572 |
+
if not reverse:
|
573 |
+
x1 = m + x1 * torch.exp(logs) * x_mask
|
574 |
+
x = torch.cat([x0, x1], 1)
|
575 |
+
logdet = torch.sum(logs, [1, 2])
|
576 |
+
return x, logdet
|
577 |
+
else:
|
578 |
+
x1 = (x1 - m) * torch.exp(-logs) * x_mask
|
579 |
+
x = torch.cat([x0, x1], 1)
|
580 |
+
return x
|
monotonic_align/__init__.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from numpy import zeros, int32, float32
|
2 |
+
from torch import from_numpy
|
3 |
+
|
4 |
+
from .core import maximum_path_jit
|
5 |
+
|
6 |
+
|
7 |
+
def maximum_path(neg_cent, mask):
|
8 |
+
device = neg_cent.device
|
9 |
+
dtype = neg_cent.dtype
|
10 |
+
neg_cent = neg_cent.data.cpu().numpy().astype(float32)
|
11 |
+
path = zeros(neg_cent.shape, dtype=int32)
|
12 |
+
|
13 |
+
t_t_max = mask.sum(1)[:, 0].data.cpu().numpy().astype(int32)
|
14 |
+
t_s_max = mask.sum(2)[:, 0].data.cpu().numpy().astype(int32)
|
15 |
+
maximum_path_jit(path, neg_cent, t_t_max, t_s_max)
|
16 |
+
return from_numpy(path).to(device=device, dtype=dtype)
|
monotonic_align/core.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numba
|
2 |
+
|
3 |
+
|
4 |
+
@numba.jit(
|
5 |
+
numba.void(
|
6 |
+
numba.int32[:, :, ::1],
|
7 |
+
numba.float32[:, :, ::1],
|
8 |
+
numba.int32[::1],
|
9 |
+
numba.int32[::1],
|
10 |
+
),
|
11 |
+
nopython=True,
|
12 |
+
nogil=True,
|
13 |
+
)
|
14 |
+
def maximum_path_jit(paths, values, t_ys, t_xs):
|
15 |
+
b = paths.shape[0]
|
16 |
+
max_neg_val = -1e9
|
17 |
+
for i in range(int(b)):
|
18 |
+
path = paths[i]
|
19 |
+
value = values[i]
|
20 |
+
t_y = t_ys[i]
|
21 |
+
t_x = t_xs[i]
|
22 |
+
|
23 |
+
v_prev = v_cur = 0.0
|
24 |
+
index = t_x - 1
|
25 |
+
|
26 |
+
for y in range(t_y):
|
27 |
+
for x in range(max(0, t_x + y - t_y), min(t_x, y + 1)):
|
28 |
+
if x == y:
|
29 |
+
v_cur = max_neg_val
|
30 |
+
else:
|
31 |
+
v_cur = value[y - 1, x]
|
32 |
+
if x == 0:
|
33 |
+
if y == 0:
|
34 |
+
v_prev = 0.0
|
35 |
+
else:
|
36 |
+
v_prev = max_neg_val
|
37 |
+
else:
|
38 |
+
v_prev = value[y - 1, x - 1]
|
39 |
+
value[y, x] += max(v_prev, v_cur)
|
40 |
+
|
41 |
+
for y in range(t_y - 1, -1, -1):
|
42 |
+
path[y, index] = 1
|
43 |
+
if index != 0 and (
|
44 |
+
index == y or value[y - 1, index] < value[y - 1, index - 1]
|
45 |
+
):
|
46 |
+
index = index - 1
|
onnx_infer.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from onnx_modules.V220_OnnxInference import OnnxInferenceSession
|
2 |
+
import numpy as np
|
3 |
+
|
4 |
+
Session = OnnxInferenceSession(
|
5 |
+
{
|
6 |
+
"enc": "onnx/BertVits2.2PT/BertVits2.2PT_enc_p.onnx",
|
7 |
+
"emb_g": "onnx/BertVits2.2PT/BertVits2.2PT_emb.onnx",
|
8 |
+
"dp": "onnx/BertVits2.2PT/BertVits2.2PT_dp.onnx",
|
9 |
+
"sdp": "onnx/BertVits2.2PT/BertVits2.2PT_sdp.onnx",
|
10 |
+
"flow": "onnx/BertVits2.2PT/BertVits2.2PT_flow.onnx",
|
11 |
+
"dec": "onnx/BertVits2.2PT/BertVits2.2PT_dec.onnx",
|
12 |
+
},
|
13 |
+
Providers=["CPUExecutionProvider"],
|
14 |
+
)
|
15 |
+
|
16 |
+
# 这里的输入和原版是一样的,只需要在原版预处理结果出来之后加上.numpy()即可
|
17 |
+
x = np.array(
|
18 |
+
[
|
19 |
+
0,
|
20 |
+
97,
|
21 |
+
0,
|
22 |
+
8,
|
23 |
+
0,
|
24 |
+
78,
|
25 |
+
0,
|
26 |
+
8,
|
27 |
+
0,
|
28 |
+
76,
|
29 |
+
0,
|
30 |
+
37,
|
31 |
+
0,
|
32 |
+
40,
|
33 |
+
0,
|
34 |
+
97,
|
35 |
+
0,
|
36 |
+
8,
|
37 |
+
0,
|
38 |
+
23,
|
39 |
+
0,
|
40 |
+
8,
|
41 |
+
0,
|
42 |
+
74,
|
43 |
+
0,
|
44 |
+
26,
|
45 |
+
0,
|
46 |
+
104,
|
47 |
+
0,
|
48 |
+
]
|
49 |
+
)
|
50 |
+
tone = np.zeros_like(x)
|
51 |
+
language = np.zeros_like(x)
|
52 |
+
sid = np.array([0])
|
53 |
+
bert = np.random.randn(x.shape[0], 1024)
|
54 |
+
ja_bert = np.random.randn(x.shape[0], 1024)
|
55 |
+
en_bert = np.random.randn(x.shape[0], 1024)
|
56 |
+
emo = np.random.randn(512, 1)
|
57 |
+
|
58 |
+
audio = Session(x, tone, language, bert, ja_bert, en_bert, emo, sid)
|
59 |
+
|
60 |
+
print(audio)
|
onnx_modules/V200/__init__.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from .text.symbols import symbols
|
2 |
+
from .models_onnx import SynthesizerTrn
|
3 |
+
|
4 |
+
__all__ = ["symbols", "SynthesizerTrn"]
|
onnx_modules/V200/attentions_onnx.py
ADDED
@@ -0,0 +1,378 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import torch
|
3 |
+
from torch import nn
|
4 |
+
from torch.nn import functional as F
|
5 |
+
|
6 |
+
import commons
|
7 |
+
import logging
|
8 |
+
|
9 |
+
logger = logging.getLogger(__name__)
|
10 |
+
|
11 |
+
|
12 |
+
class LayerNorm(nn.Module):
|
13 |
+
def __init__(self, channels, eps=1e-5):
|
14 |
+
super().__init__()
|
15 |
+
self.channels = channels
|
16 |
+
self.eps = eps
|
17 |
+
|
18 |
+
self.gamma = nn.Parameter(torch.ones(channels))
|
19 |
+
self.beta = nn.Parameter(torch.zeros(channels))
|
20 |
+
|
21 |
+
def forward(self, x):
|
22 |
+
x = x.transpose(1, -1)
|
23 |
+
x = F.layer_norm(x, (self.channels,), self.gamma, self.beta, self.eps)
|
24 |
+
return x.transpose(1, -1)
|
25 |
+
|
26 |
+
|
27 |
+
@torch.jit.script
|
28 |
+
def fused_add_tanh_sigmoid_multiply(input_a, input_b, n_channels):
|
29 |
+
n_channels_int = n_channels[0]
|
30 |
+
in_act = input_a + input_b
|
31 |
+
t_act = torch.tanh(in_act[:, :n_channels_int, :])
|
32 |
+
s_act = torch.sigmoid(in_act[:, n_channels_int:, :])
|
33 |
+
acts = t_act * s_act
|
34 |
+
return acts
|
35 |
+
|
36 |
+
|
37 |
+
class Encoder(nn.Module):
|
38 |
+
def __init__(
|
39 |
+
self,
|
40 |
+
hidden_channels,
|
41 |
+
filter_channels,
|
42 |
+
n_heads,
|
43 |
+
n_layers,
|
44 |
+
kernel_size=1,
|
45 |
+
p_dropout=0.0,
|
46 |
+
window_size=4,
|
47 |
+
isflow=True,
|
48 |
+
**kwargs
|
49 |
+
):
|
50 |
+
super().__init__()
|
51 |
+
self.hidden_channels = hidden_channels
|
52 |
+
self.filter_channels = filter_channels
|
53 |
+
self.n_heads = n_heads
|
54 |
+
self.n_layers = n_layers
|
55 |
+
self.kernel_size = kernel_size
|
56 |
+
self.p_dropout = p_dropout
|
57 |
+
self.window_size = window_size
|
58 |
+
# if isflow:
|
59 |
+
# cond_layer = torch.nn.Conv1d(256, 2*hidden_channels*n_layers, 1)
|
60 |
+
# self.cond_pre = torch.nn.Conv1d(hidden_channels, 2*hidden_channels, 1)
|
61 |
+
# self.cond_layer = weight_norm(cond_layer, name='weight')
|
62 |
+
# self.gin_channels = 256
|
63 |
+
self.cond_layer_idx = self.n_layers
|
64 |
+
if "gin_channels" in kwargs:
|
65 |
+
self.gin_channels = kwargs["gin_channels"]
|
66 |
+
if self.gin_channels != 0:
|
67 |
+
self.spk_emb_linear = nn.Linear(self.gin_channels, self.hidden_channels)
|
68 |
+
# vits2 says 3rd block, so idx is 2 by default
|
69 |
+
self.cond_layer_idx = (
|
70 |
+
kwargs["cond_layer_idx"] if "cond_layer_idx" in kwargs else 2
|
71 |
+
)
|
72 |
+
logging.debug(self.gin_channels, self.cond_layer_idx)
|
73 |
+
assert (
|
74 |
+
self.cond_layer_idx < self.n_layers
|
75 |
+
), "cond_layer_idx should be less than n_layers"
|
76 |
+
self.drop = nn.Dropout(p_dropout)
|
77 |
+
self.attn_layers = nn.ModuleList()
|
78 |
+
self.norm_layers_1 = nn.ModuleList()
|
79 |
+
self.ffn_layers = nn.ModuleList()
|
80 |
+
self.norm_layers_2 = nn.ModuleList()
|
81 |
+
for i in range(self.n_layers):
|
82 |
+
self.attn_layers.append(
|
83 |
+
MultiHeadAttention(
|
84 |
+
hidden_channels,
|
85 |
+
hidden_channels,
|
86 |
+
n_heads,
|
87 |
+
p_dropout=p_dropout,
|
88 |
+
window_size=window_size,
|
89 |
+
)
|
90 |
+
)
|
91 |
+
self.norm_layers_1.append(LayerNorm(hidden_channels))
|
92 |
+
self.ffn_layers.append(
|
93 |
+
FFN(
|
94 |
+
hidden_channels,
|
95 |
+
hidden_channels,
|
96 |
+
filter_channels,
|
97 |
+
kernel_size,
|
98 |
+
p_dropout=p_dropout,
|
99 |
+
)
|
100 |
+
)
|
101 |
+
self.norm_layers_2.append(LayerNorm(hidden_channels))
|
102 |
+
|
103 |
+
def forward(self, x, x_mask, g=None):
|
104 |
+
attn_mask = x_mask.unsqueeze(2) * x_mask.unsqueeze(-1)
|
105 |
+
x = x * x_mask
|
106 |
+
for i in range(self.n_layers):
|
107 |
+
if i == self.cond_layer_idx and g is not None:
|
108 |
+
g = self.spk_emb_linear(g.transpose(1, 2))
|
109 |
+
g = g.transpose(1, 2)
|
110 |
+
x = x + g
|
111 |
+
x = x * x_mask
|
112 |
+
y = self.attn_layers[i](x, x, attn_mask)
|
113 |
+
y = self.drop(y)
|
114 |
+
x = self.norm_layers_1[i](x + y)
|
115 |
+
|
116 |
+
y = self.ffn_layers[i](x, x_mask)
|
117 |
+
y = self.drop(y)
|
118 |
+
x = self.norm_layers_2[i](x + y)
|
119 |
+
x = x * x_mask
|
120 |
+
return x
|
121 |
+
|
122 |
+
|
123 |
+
class MultiHeadAttention(nn.Module):
|
124 |
+
def __init__(
|
125 |
+
self,
|
126 |
+
channels,
|
127 |
+
out_channels,
|
128 |
+
n_heads,
|
129 |
+
p_dropout=0.0,
|
130 |
+
window_size=None,
|
131 |
+
heads_share=True,
|
132 |
+
block_length=None,
|
133 |
+
proximal_bias=False,
|
134 |
+
proximal_init=False,
|
135 |
+
):
|
136 |
+
super().__init__()
|
137 |
+
assert channels % n_heads == 0
|
138 |
+
|
139 |
+
self.channels = channels
|
140 |
+
self.out_channels = out_channels
|
141 |
+
self.n_heads = n_heads
|
142 |
+
self.p_dropout = p_dropout
|
143 |
+
self.window_size = window_size
|
144 |
+
self.heads_share = heads_share
|
145 |
+
self.block_length = block_length
|
146 |
+
self.proximal_bias = proximal_bias
|
147 |
+
self.proximal_init = proximal_init
|
148 |
+
self.attn = None
|
149 |
+
|
150 |
+
self.k_channels = channels // n_heads
|
151 |
+
self.conv_q = nn.Conv1d(channels, channels, 1)
|
152 |
+
self.conv_k = nn.Conv1d(channels, channels, 1)
|
153 |
+
self.conv_v = nn.Conv1d(channels, channels, 1)
|
154 |
+
self.conv_o = nn.Conv1d(channels, out_channels, 1)
|
155 |
+
self.drop = nn.Dropout(p_dropout)
|
156 |
+
|
157 |
+
if window_size is not None:
|
158 |
+
n_heads_rel = 1 if heads_share else n_heads
|
159 |
+
rel_stddev = self.k_channels**-0.5
|
160 |
+
self.emb_rel_k = nn.Parameter(
|
161 |
+
torch.randn(n_heads_rel, window_size * 2 + 1, self.k_channels)
|
162 |
+
* rel_stddev
|
163 |
+
)
|
164 |
+
self.emb_rel_v = nn.Parameter(
|
165 |
+
torch.randn(n_heads_rel, window_size * 2 + 1, self.k_channels)
|
166 |
+
* rel_stddev
|
167 |
+
)
|
168 |
+
|
169 |
+
nn.init.xavier_uniform_(self.conv_q.weight)
|
170 |
+
nn.init.xavier_uniform_(self.conv_k.weight)
|
171 |
+
nn.init.xavier_uniform_(self.conv_v.weight)
|
172 |
+
if proximal_init:
|
173 |
+
with torch.no_grad():
|
174 |
+
self.conv_k.weight.copy_(self.conv_q.weight)
|
175 |
+
self.conv_k.bias.copy_(self.conv_q.bias)
|
176 |
+
|
177 |
+
def forward(self, x, c, attn_mask=None):
|
178 |
+
q = self.conv_q(x)
|
179 |
+
k = self.conv_k(c)
|
180 |
+
v = self.conv_v(c)
|
181 |
+
|
182 |
+
x, self.attn = self.attention(q, k, v, mask=attn_mask)
|
183 |
+
|
184 |
+
x = self.conv_o(x)
|
185 |
+
return x
|
186 |
+
|
187 |
+
def attention(self, query, key, value, mask=None):
|
188 |
+
# reshape [b, d, t] -> [b, n_h, t, d_k]
|
189 |
+
b, d, t_s, t_t = (*key.size(), query.size(2))
|
190 |
+
query = query.view(b, self.n_heads, self.k_channels, t_t).transpose(2, 3)
|
191 |
+
key = key.view(b, self.n_heads, self.k_channels, t_s).transpose(2, 3)
|
192 |
+
value = value.view(b, self.n_heads, self.k_channels, t_s).transpose(2, 3)
|
193 |
+
|
194 |
+
scores = torch.matmul(query / math.sqrt(self.k_channels), key.transpose(-2, -1))
|
195 |
+
if self.window_size is not None:
|
196 |
+
assert (
|
197 |
+
t_s == t_t
|
198 |
+
), "Relative attention is only available for self-attention."
|
199 |
+
key_relative_embeddings = self._get_relative_embeddings(self.emb_rel_k, t_s)
|
200 |
+
rel_logits = self._matmul_with_relative_keys(
|
201 |
+
query / math.sqrt(self.k_channels), key_relative_embeddings
|
202 |
+
)
|
203 |
+
scores_local = self._relative_position_to_absolute_position(rel_logits)
|
204 |
+
scores = scores + scores_local
|
205 |
+
if self.proximal_bias:
|
206 |
+
assert t_s == t_t, "Proximal bias is only available for self-attention."
|
207 |
+
scores = scores + self._attention_bias_proximal(t_s).to(
|
208 |
+
device=scores.device, dtype=scores.dtype
|
209 |
+
)
|
210 |
+
if mask is not None:
|
211 |
+
scores = scores.masked_fill(mask == 0, -1e4)
|
212 |
+
if self.block_length is not None:
|
213 |
+
assert (
|
214 |
+
t_s == t_t
|
215 |
+
), "Local attention is only available for self-attention."
|
216 |
+
block_mask = (
|
217 |
+
torch.ones_like(scores)
|
218 |
+
.triu(-self.block_length)
|
219 |
+
.tril(self.block_length)
|
220 |
+
)
|
221 |
+
scores = scores.masked_fill(block_mask == 0, -1e4)
|
222 |
+
p_attn = F.softmax(scores, dim=-1) # [b, n_h, t_t, t_s]
|
223 |
+
p_attn = self.drop(p_attn)
|
224 |
+
output = torch.matmul(p_attn, value)
|
225 |
+
if self.window_size is not None:
|
226 |
+
relative_weights = self._absolute_position_to_relative_position(p_attn)
|
227 |
+
value_relative_embeddings = self._get_relative_embeddings(
|
228 |
+
self.emb_rel_v, t_s
|
229 |
+
)
|
230 |
+
output = output + self._matmul_with_relative_values(
|
231 |
+
relative_weights, value_relative_embeddings
|
232 |
+
)
|
233 |
+
output = (
|
234 |
+
output.transpose(2, 3).contiguous().view(b, d, t_t)
|
235 |
+
) # [b, n_h, t_t, d_k] -> [b, d, t_t]
|
236 |
+
return output, p_attn
|
237 |
+
|
238 |
+
def _matmul_with_relative_values(self, x, y):
|
239 |
+
"""
|
240 |
+
x: [b, h, l, m]
|
241 |
+
y: [h or 1, m, d]
|
242 |
+
ret: [b, h, l, d]
|
243 |
+
"""
|
244 |
+
ret = torch.matmul(x, y.unsqueeze(0))
|
245 |
+
return ret
|
246 |
+
|
247 |
+
def _matmul_with_relative_keys(self, x, y):
|
248 |
+
"""
|
249 |
+
x: [b, h, l, d]
|
250 |
+
y: [h or 1, m, d]
|
251 |
+
ret: [b, h, l, m]
|
252 |
+
"""
|
253 |
+
ret = torch.matmul(x, y.unsqueeze(0).transpose(-2, -1))
|
254 |
+
return ret
|
255 |
+
|
256 |
+
def _get_relative_embeddings(self, relative_embeddings, length):
|
257 |
+
max_relative_position = 2 * self.window_size + 1
|
258 |
+
# Pad first before slice to avoid using cond ops.
|
259 |
+
pad_length = max(length - (self.window_size + 1), 0)
|
260 |
+
slice_start_position = max((self.window_size + 1) - length, 0)
|
261 |
+
slice_end_position = slice_start_position + 2 * length - 1
|
262 |
+
if pad_length > 0:
|
263 |
+
padded_relative_embeddings = F.pad(
|
264 |
+
relative_embeddings,
|
265 |
+
commons.convert_pad_shape([[0, 0], [pad_length, pad_length], [0, 0]]),
|
266 |
+
)
|
267 |
+
else:
|
268 |
+
padded_relative_embeddings = relative_embeddings
|
269 |
+
used_relative_embeddings = padded_relative_embeddings[
|
270 |
+
:, slice_start_position:slice_end_position
|
271 |
+
]
|
272 |
+
return used_relative_embeddings
|
273 |
+
|
274 |
+
def _relative_position_to_absolute_position(self, x):
|
275 |
+
"""
|
276 |
+
x: [b, h, l, 2*l-1]
|
277 |
+
ret: [b, h, l, l]
|
278 |
+
"""
|
279 |
+
batch, heads, length, _ = x.size()
|
280 |
+
# Concat columns of pad to shift from relative to absolute indexing.
|
281 |
+
x = F.pad(x, commons.convert_pad_shape([[0, 0], [0, 0], [0, 0], [0, 1]]))
|
282 |
+
|
283 |
+
# Concat extra elements so to add up to shape (len+1, 2*len-1).
|
284 |
+
x_flat = x.view([batch, heads, length * 2 * length])
|
285 |
+
x_flat = F.pad(
|
286 |
+
x_flat, commons.convert_pad_shape([[0, 0], [0, 0], [0, length - 1]])
|
287 |
+
)
|
288 |
+
|
289 |
+
# Reshape and slice out the padded elements.
|
290 |
+
x_final = x_flat.view([batch, heads, length + 1, 2 * length - 1])[
|
291 |
+
:, :, :length, length - 1 :
|
292 |
+
]
|
293 |
+
return x_final
|
294 |
+
|
295 |
+
def _absolute_position_to_relative_position(self, x):
|
296 |
+
"""
|
297 |
+
x: [b, h, l, l]
|
298 |
+
ret: [b, h, l, 2*l-1]
|
299 |
+
"""
|
300 |
+
batch, heads, length, _ = x.size()
|
301 |
+
# padd along column
|
302 |
+
x = F.pad(
|
303 |
+
x, commons.convert_pad_shape([[0, 0], [0, 0], [0, 0], [0, length - 1]])
|
304 |
+
)
|
305 |
+
x_flat = x.view([batch, heads, length**2 + length * (length - 1)])
|
306 |
+
# add 0's in the beginning that will skew the elements after reshape
|
307 |
+
x_flat = F.pad(x_flat, commons.convert_pad_shape([[0, 0], [0, 0], [length, 0]]))
|
308 |
+
x_final = x_flat.view([batch, heads, length, 2 * length])[:, :, :, 1:]
|
309 |
+
return x_final
|
310 |
+
|
311 |
+
def _attention_bias_proximal(self, length):
|
312 |
+
"""Bias for self-attention to encourage attention to close positions.
|
313 |
+
Args:
|
314 |
+
length: an integer scalar.
|
315 |
+
Returns:
|
316 |
+
a Tensor with shape [1, 1, length, length]
|
317 |
+
"""
|
318 |
+
r = torch.arange(length, dtype=torch.float32)
|
319 |
+
diff = torch.unsqueeze(r, 0) - torch.unsqueeze(r, 1)
|
320 |
+
return torch.unsqueeze(torch.unsqueeze(-torch.log1p(torch.abs(diff)), 0), 0)
|
321 |
+
|
322 |
+
|
323 |
+
class FFN(nn.Module):
|
324 |
+
def __init__(
|
325 |
+
self,
|
326 |
+
in_channels,
|
327 |
+
out_channels,
|
328 |
+
filter_channels,
|
329 |
+
kernel_size,
|
330 |
+
p_dropout=0.0,
|
331 |
+
activation=None,
|
332 |
+
causal=False,
|
333 |
+
):
|
334 |
+
super().__init__()
|
335 |
+
self.in_channels = in_channels
|
336 |
+
self.out_channels = out_channels
|
337 |
+
self.filter_channels = filter_channels
|
338 |
+
self.kernel_size = kernel_size
|
339 |
+
self.p_dropout = p_dropout
|
340 |
+
self.activation = activation
|
341 |
+
self.causal = causal
|
342 |
+
|
343 |
+
if causal:
|
344 |
+
self.padding = self._causal_padding
|
345 |
+
else:
|
346 |
+
self.padding = self._same_padding
|
347 |
+
|
348 |
+
self.conv_1 = nn.Conv1d(in_channels, filter_channels, kernel_size)
|
349 |
+
self.conv_2 = nn.Conv1d(filter_channels, out_channels, kernel_size)
|
350 |
+
self.drop = nn.Dropout(p_dropout)
|
351 |
+
|
352 |
+
def forward(self, x, x_mask):
|
353 |
+
x = self.conv_1(self.padding(x * x_mask))
|
354 |
+
if self.activation == "gelu":
|
355 |
+
x = x * torch.sigmoid(1.702 * x)
|
356 |
+
else:
|
357 |
+
x = torch.relu(x)
|
358 |
+
x = self.drop(x)
|
359 |
+
x = self.conv_2(self.padding(x * x_mask))
|
360 |
+
return x * x_mask
|
361 |
+
|
362 |
+
def _causal_padding(self, x):
|
363 |
+
if self.kernel_size == 1:
|
364 |
+
return x
|
365 |
+
pad_l = self.kernel_size - 1
|
366 |
+
pad_r = 0
|
367 |
+
padding = [[0, 0], [0, 0], [pad_l, pad_r]]
|
368 |
+
x = F.pad(x, commons.convert_pad_shape(padding))
|
369 |
+
return x
|
370 |
+
|
371 |
+
def _same_padding(self, x):
|
372 |
+
if self.kernel_size == 1:
|
373 |
+
return x
|
374 |
+
pad_l = (self.kernel_size - 1) // 2
|
375 |
+
pad_r = self.kernel_size // 2
|
376 |
+
padding = [[0, 0], [0, 0], [pad_l, pad_r]]
|
377 |
+
x = F.pad(x, commons.convert_pad_shape(padding))
|
378 |
+
return x
|
onnx_modules/V200/models_onnx.py
ADDED
@@ -0,0 +1,990 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import torch
|
3 |
+
from torch import nn
|
4 |
+
from torch.nn import functional as F
|
5 |
+
|
6 |
+
import commons
|
7 |
+
import modules
|
8 |
+
from . import attentions_onnx
|
9 |
+
|
10 |
+
from torch.nn import Conv1d, ConvTranspose1d, Conv2d
|
11 |
+
from torch.nn.utils import weight_norm, remove_weight_norm, spectral_norm
|
12 |
+
from commons import init_weights, get_padding
|
13 |
+
from .text import symbols, num_tones, num_languages
|
14 |
+
|
15 |
+
|
16 |
+
class DurationDiscriminator(nn.Module): # vits2
|
17 |
+
def __init__(
|
18 |
+
self, in_channels, filter_channels, kernel_size, p_dropout, gin_channels=0
|
19 |
+
):
|
20 |
+
super().__init__()
|
21 |
+
|
22 |
+
self.in_channels = in_channels
|
23 |
+
self.filter_channels = filter_channels
|
24 |
+
self.kernel_size = kernel_size
|
25 |
+
self.p_dropout = p_dropout
|
26 |
+
self.gin_channels = gin_channels
|
27 |
+
|
28 |
+
self.drop = nn.Dropout(p_dropout)
|
29 |
+
self.conv_1 = nn.Conv1d(
|
30 |
+
in_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
31 |
+
)
|
32 |
+
self.norm_1 = modules.LayerNorm(filter_channels)
|
33 |
+
self.conv_2 = nn.Conv1d(
|
34 |
+
filter_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
35 |
+
)
|
36 |
+
self.norm_2 = modules.LayerNorm(filter_channels)
|
37 |
+
self.dur_proj = nn.Conv1d(1, filter_channels, 1)
|
38 |
+
|
39 |
+
self.pre_out_conv_1 = nn.Conv1d(
|
40 |
+
2 * filter_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
41 |
+
)
|
42 |
+
self.pre_out_norm_1 = modules.LayerNorm(filter_channels)
|
43 |
+
self.pre_out_conv_2 = nn.Conv1d(
|
44 |
+
filter_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
45 |
+
)
|
46 |
+
self.pre_out_norm_2 = modules.LayerNorm(filter_channels)
|
47 |
+
|
48 |
+
if gin_channels != 0:
|
49 |
+
self.cond = nn.Conv1d(gin_channels, in_channels, 1)
|
50 |
+
|
51 |
+
self.output_layer = nn.Sequential(nn.Linear(filter_channels, 1), nn.Sigmoid())
|
52 |
+
|
53 |
+
def forward_probability(self, x, x_mask, dur, g=None):
|
54 |
+
dur = self.dur_proj(dur)
|
55 |
+
x = torch.cat([x, dur], dim=1)
|
56 |
+
x = self.pre_out_conv_1(x * x_mask)
|
57 |
+
x = torch.relu(x)
|
58 |
+
x = self.pre_out_norm_1(x)
|
59 |
+
x = self.drop(x)
|
60 |
+
x = self.pre_out_conv_2(x * x_mask)
|
61 |
+
x = torch.relu(x)
|
62 |
+
x = self.pre_out_norm_2(x)
|
63 |
+
x = self.drop(x)
|
64 |
+
x = x * x_mask
|
65 |
+
x = x.transpose(1, 2)
|
66 |
+
output_prob = self.output_layer(x)
|
67 |
+
return output_prob
|
68 |
+
|
69 |
+
def forward(self, x, x_mask, dur_r, dur_hat, g=None):
|
70 |
+
x = torch.detach(x)
|
71 |
+
if g is not None:
|
72 |
+
g = torch.detach(g)
|
73 |
+
x = x + self.cond(g)
|
74 |
+
x = self.conv_1(x * x_mask)
|
75 |
+
x = torch.relu(x)
|
76 |
+
x = self.norm_1(x)
|
77 |
+
x = self.drop(x)
|
78 |
+
x = self.conv_2(x * x_mask)
|
79 |
+
x = torch.relu(x)
|
80 |
+
x = self.norm_2(x)
|
81 |
+
x = self.drop(x)
|
82 |
+
|
83 |
+
output_probs = []
|
84 |
+
for dur in [dur_r, dur_hat]:
|
85 |
+
output_prob = self.forward_probability(x, x_mask, dur, g)
|
86 |
+
output_probs.append(output_prob)
|
87 |
+
|
88 |
+
return output_probs
|
89 |
+
|
90 |
+
|
91 |
+
class TransformerCouplingBlock(nn.Module):
|
92 |
+
def __init__(
|
93 |
+
self,
|
94 |
+
channels,
|
95 |
+
hidden_channels,
|
96 |
+
filter_channels,
|
97 |
+
n_heads,
|
98 |
+
n_layers,
|
99 |
+
kernel_size,
|
100 |
+
p_dropout,
|
101 |
+
n_flows=4,
|
102 |
+
gin_channels=0,
|
103 |
+
share_parameter=False,
|
104 |
+
):
|
105 |
+
super().__init__()
|
106 |
+
self.channels = channels
|
107 |
+
self.hidden_channels = hidden_channels
|
108 |
+
self.kernel_size = kernel_size
|
109 |
+
self.n_layers = n_layers
|
110 |
+
self.n_flows = n_flows
|
111 |
+
self.gin_channels = gin_channels
|
112 |
+
|
113 |
+
self.flows = nn.ModuleList()
|
114 |
+
|
115 |
+
self.wn = (
|
116 |
+
attentions_onnx.FFT(
|
117 |
+
hidden_channels,
|
118 |
+
filter_channels,
|
119 |
+
n_heads,
|
120 |
+
n_layers,
|
121 |
+
kernel_size,
|
122 |
+
p_dropout,
|
123 |
+
isflow=True,
|
124 |
+
gin_channels=self.gin_channels,
|
125 |
+
)
|
126 |
+
if share_parameter
|
127 |
+
else None
|
128 |
+
)
|
129 |
+
|
130 |
+
for i in range(n_flows):
|
131 |
+
self.flows.append(
|
132 |
+
modules.TransformerCouplingLayer(
|
133 |
+
channels,
|
134 |
+
hidden_channels,
|
135 |
+
kernel_size,
|
136 |
+
n_layers,
|
137 |
+
n_heads,
|
138 |
+
p_dropout,
|
139 |
+
filter_channels,
|
140 |
+
mean_only=True,
|
141 |
+
wn_sharing_parameter=self.wn,
|
142 |
+
gin_channels=self.gin_channels,
|
143 |
+
)
|
144 |
+
)
|
145 |
+
self.flows.append(modules.Flip())
|
146 |
+
|
147 |
+
def forward(self, x, x_mask, g=None, reverse=True):
|
148 |
+
if not reverse:
|
149 |
+
for flow in self.flows:
|
150 |
+
x, _ = flow(x, x_mask, g=g, reverse=reverse)
|
151 |
+
else:
|
152 |
+
for flow in reversed(self.flows):
|
153 |
+
x = flow(x, x_mask, g=g, reverse=reverse)
|
154 |
+
return x
|
155 |
+
|
156 |
+
|
157 |
+
class StochasticDurationPredictor(nn.Module):
|
158 |
+
def __init__(
|
159 |
+
self,
|
160 |
+
in_channels,
|
161 |
+
filter_channels,
|
162 |
+
kernel_size,
|
163 |
+
p_dropout,
|
164 |
+
n_flows=4,
|
165 |
+
gin_channels=0,
|
166 |
+
):
|
167 |
+
super().__init__()
|
168 |
+
filter_channels = in_channels # it needs to be removed from future version.
|
169 |
+
self.in_channels = in_channels
|
170 |
+
self.filter_channels = filter_channels
|
171 |
+
self.kernel_size = kernel_size
|
172 |
+
self.p_dropout = p_dropout
|
173 |
+
self.n_flows = n_flows
|
174 |
+
self.gin_channels = gin_channels
|
175 |
+
|
176 |
+
self.log_flow = modules.Log()
|
177 |
+
self.flows = nn.ModuleList()
|
178 |
+
self.flows.append(modules.ElementwiseAffine(2))
|
179 |
+
for i in range(n_flows):
|
180 |
+
self.flows.append(
|
181 |
+
modules.ConvFlow(2, filter_channels, kernel_size, n_layers=3)
|
182 |
+
)
|
183 |
+
self.flows.append(modules.Flip())
|
184 |
+
|
185 |
+
self.post_pre = nn.Conv1d(1, filter_channels, 1)
|
186 |
+
self.post_proj = nn.Conv1d(filter_channels, filter_channels, 1)
|
187 |
+
self.post_convs = modules.DDSConv(
|
188 |
+
filter_channels, kernel_size, n_layers=3, p_dropout=p_dropout
|
189 |
+
)
|
190 |
+
self.post_flows = nn.ModuleList()
|
191 |
+
self.post_flows.append(modules.ElementwiseAffine(2))
|
192 |
+
for i in range(4):
|
193 |
+
self.post_flows.append(
|
194 |
+
modules.ConvFlow(2, filter_channels, kernel_size, n_layers=3)
|
195 |
+
)
|
196 |
+
self.post_flows.append(modules.Flip())
|
197 |
+
|
198 |
+
self.pre = nn.Conv1d(in_channels, filter_channels, 1)
|
199 |
+
self.proj = nn.Conv1d(filter_channels, filter_channels, 1)
|
200 |
+
self.convs = modules.DDSConv(
|
201 |
+
filter_channels, kernel_size, n_layers=3, p_dropout=p_dropout
|
202 |
+
)
|
203 |
+
if gin_channels != 0:
|
204 |
+
self.cond = nn.Conv1d(gin_channels, filter_channels, 1)
|
205 |
+
|
206 |
+
def forward(self, x, x_mask, z, g=None):
|
207 |
+
x = torch.detach(x)
|
208 |
+
x = self.pre(x)
|
209 |
+
if g is not None:
|
210 |
+
g = torch.detach(g)
|
211 |
+
x = x + self.cond(g)
|
212 |
+
x = self.convs(x, x_mask)
|
213 |
+
x = self.proj(x) * x_mask
|
214 |
+
|
215 |
+
flows = list(reversed(self.flows))
|
216 |
+
flows = flows[:-2] + [flows[-1]] # remove a useless vflow
|
217 |
+
for flow in flows:
|
218 |
+
z = flow(z, x_mask, g=x, reverse=True)
|
219 |
+
z0, z1 = torch.split(z, [1, 1], 1)
|
220 |
+
logw = z0
|
221 |
+
return logw
|
222 |
+
|
223 |
+
|
224 |
+
class DurationPredictor(nn.Module):
|
225 |
+
def __init__(
|
226 |
+
self, in_channels, filter_channels, kernel_size, p_dropout, gin_channels=0
|
227 |
+
):
|
228 |
+
super().__init__()
|
229 |
+
|
230 |
+
self.in_channels = in_channels
|
231 |
+
self.filter_channels = filter_channels
|
232 |
+
self.kernel_size = kernel_size
|
233 |
+
self.p_dropout = p_dropout
|
234 |
+
self.gin_channels = gin_channels
|
235 |
+
|
236 |
+
self.drop = nn.Dropout(p_dropout)
|
237 |
+
self.conv_1 = nn.Conv1d(
|
238 |
+
in_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
239 |
+
)
|
240 |
+
self.norm_1 = modules.LayerNorm(filter_channels)
|
241 |
+
self.conv_2 = nn.Conv1d(
|
242 |
+
filter_channels, filter_channels, kernel_size, padding=kernel_size // 2
|
243 |
+
)
|
244 |
+
self.norm_2 = modules.LayerNorm(filter_channels)
|
245 |
+
self.proj = nn.Conv1d(filter_channels, 1, 1)
|
246 |
+
|
247 |
+
if gin_channels != 0:
|
248 |
+
self.cond = nn.Conv1d(gin_channels, in_channels, 1)
|
249 |
+
|
250 |
+
def forward(self, x, x_mask, g=None):
|
251 |
+
x = torch.detach(x)
|
252 |
+
if g is not None:
|
253 |
+
g = torch.detach(g)
|
254 |
+
x = x + self.cond(g)
|
255 |
+
x = self.conv_1(x * x_mask)
|
256 |
+
x = torch.relu(x)
|
257 |
+
x = self.norm_1(x)
|
258 |
+
x = self.drop(x)
|
259 |
+
x = self.conv_2(x * x_mask)
|
260 |
+
x = torch.relu(x)
|
261 |
+
x = self.norm_2(x)
|
262 |
+
x = self.drop(x)
|
263 |
+
x = self.proj(x * x_mask)
|
264 |
+
return x * x_mask
|
265 |
+
|
266 |
+
|
267 |
+
class TextEncoder(nn.Module):
|
268 |
+
def __init__(
|
269 |
+
self,
|
270 |
+
n_vocab,
|
271 |
+
out_channels,
|
272 |
+
hidden_channels,
|
273 |
+
filter_channels,
|
274 |
+
n_heads,
|
275 |
+
n_layers,
|
276 |
+
kernel_size,
|
277 |
+
p_dropout,
|
278 |
+
gin_channels=0,
|
279 |
+
):
|
280 |
+
super().__init__()
|
281 |
+
self.n_vocab = n_vocab
|
282 |
+
self.out_channels = out_channels
|
283 |
+
self.hidden_channels = hidden_channels
|
284 |
+
self.filter_channels = filter_channels
|
285 |
+
self.n_heads = n_heads
|
286 |
+
self.n_layers = n_layers
|
287 |
+
self.kernel_size = kernel_size
|
288 |
+
self.p_dropout = p_dropout
|
289 |
+
self.gin_channels = gin_channels
|
290 |
+
self.emb = nn.Embedding(len(symbols), hidden_channels)
|
291 |
+
nn.init.normal_(self.emb.weight, 0.0, hidden_channels**-0.5)
|
292 |
+
self.tone_emb = nn.Embedding(num_tones, hidden_channels)
|
293 |
+
nn.init.normal_(self.tone_emb.weight, 0.0, hidden_channels**-0.5)
|
294 |
+
self.language_emb = nn.Embedding(num_languages, hidden_channels)
|
295 |
+
nn.init.normal_(self.language_emb.weight, 0.0, hidden_channels**-0.5)
|
296 |
+
self.bert_proj = nn.Conv1d(1024, hidden_channels, 1)
|
297 |
+
self.ja_bert_proj = nn.Conv1d(1024, hidden_channels, 1)
|
298 |
+
self.en_bert_proj = nn.Conv1d(1024, hidden_channels, 1)
|
299 |
+
|
300 |
+
self.encoder = attentions_onnx.Encoder(
|
301 |
+
hidden_channels,
|
302 |
+
filter_channels,
|
303 |
+
n_heads,
|
304 |
+
n_layers,
|
305 |
+
kernel_size,
|
306 |
+
p_dropout,
|
307 |
+
gin_channels=self.gin_channels,
|
308 |
+
)
|
309 |
+
self.proj = nn.Conv1d(hidden_channels, out_channels * 2, 1)
|
310 |
+
|
311 |
+
def forward(self, x, x_lengths, tone, language, bert, ja_bert, en_bert, g=None):
|
312 |
+
x_mask = torch.ones_like(x).unsqueeze(0)
|
313 |
+
bert_emb = self.bert_proj(bert.transpose(0, 1).unsqueeze(0)).transpose(1, 2)
|
314 |
+
ja_bert_emb = self.ja_bert_proj(ja_bert.transpose(0, 1).unsqueeze(0)).transpose(
|
315 |
+
1, 2
|
316 |
+
)
|
317 |
+
en_bert_emb = self.en_bert_proj(en_bert.transpose(0, 1).unsqueeze(0)).transpose(
|
318 |
+
1, 2
|
319 |
+
)
|
320 |
+
x = (
|
321 |
+
self.emb(x)
|
322 |
+
+ self.tone_emb(tone)
|
323 |
+
+ self.language_emb(language)
|
324 |
+
+ bert_emb
|
325 |
+
+ ja_bert_emb
|
326 |
+
+ en_bert_emb
|
327 |
+
) * math.sqrt(
|
328 |
+
self.hidden_channels
|
329 |
+
) # [b, t, h]
|
330 |
+
x = torch.transpose(x, 1, -1) # [b, h, t]
|
331 |
+
x_mask = x_mask.to(x.dtype)
|
332 |
+
|
333 |
+
x = self.encoder(x * x_mask, x_mask, g=g)
|
334 |
+
stats = self.proj(x) * x_mask
|
335 |
+
|
336 |
+
m, logs = torch.split(stats, self.out_channels, dim=1)
|
337 |
+
return x, m, logs, x_mask
|
338 |
+
|
339 |
+
|
340 |
+
class ResidualCouplingBlock(nn.Module):
|
341 |
+
def __init__(
|
342 |
+
self,
|
343 |
+
channels,
|
344 |
+
hidden_channels,
|
345 |
+
kernel_size,
|
346 |
+
dilation_rate,
|
347 |
+
n_layers,
|
348 |
+
n_flows=4,
|
349 |
+
gin_channels=0,
|
350 |
+
):
|
351 |
+
super().__init__()
|
352 |
+
self.channels = channels
|
353 |
+
self.hidden_channels = hidden_channels
|
354 |
+
self.kernel_size = kernel_size
|
355 |
+
self.dilation_rate = dilation_rate
|
356 |
+
self.n_layers = n_layers
|
357 |
+
self.n_flows = n_flows
|
358 |
+
self.gin_channels = gin_channels
|
359 |
+
|
360 |
+
self.flows = nn.ModuleList()
|
361 |
+
for i in range(n_flows):
|
362 |
+
self.flows.append(
|
363 |
+
modules.ResidualCouplingLayer(
|
364 |
+
channels,
|
365 |
+
hidden_channels,
|
366 |
+
kernel_size,
|
367 |
+
dilation_rate,
|
368 |
+
n_layers,
|
369 |
+
gin_channels=gin_channels,
|
370 |
+
mean_only=True,
|
371 |
+
)
|
372 |
+
)
|
373 |
+
self.flows.append(modules.Flip())
|
374 |
+
|
375 |
+
def forward(self, x, x_mask, g=None, reverse=True):
|
376 |
+
if not reverse:
|
377 |
+
for flow in self.flows:
|
378 |
+
x, _ = flow(x, x_mask, g=g, reverse=reverse)
|
379 |
+
else:
|
380 |
+
for flow in reversed(self.flows):
|
381 |
+
x = flow(x, x_mask, g=g, reverse=reverse)
|
382 |
+
return x
|
383 |
+
|
384 |
+
|
385 |
+
class PosteriorEncoder(nn.Module):
|
386 |
+
def __init__(
|
387 |
+
self,
|
388 |
+
in_channels,
|
389 |
+
out_channels,
|
390 |
+
hidden_channels,
|
391 |
+
kernel_size,
|
392 |
+
dilation_rate,
|
393 |
+
n_layers,
|
394 |
+
gin_channels=0,
|
395 |
+
):
|
396 |
+
super().__init__()
|
397 |
+
self.in_channels = in_channels
|
398 |
+
self.out_channels = out_channels
|
399 |
+
self.hidden_channels = hidden_channels
|
400 |
+
self.kernel_size = kernel_size
|
401 |
+
self.dilation_rate = dilation_rate
|
402 |
+
self.n_layers = n_layers
|
403 |
+
self.gin_channels = gin_channels
|
404 |
+
|
405 |
+
self.pre = nn.Conv1d(in_channels, hidden_channels, 1)
|
406 |
+
self.enc = modules.WN(
|
407 |
+
hidden_channels,
|
408 |
+
kernel_size,
|
409 |
+
dilation_rate,
|
410 |
+
n_layers,
|
411 |
+
gin_channels=gin_channels,
|
412 |
+
)
|
413 |
+
self.proj = nn.Conv1d(hidden_channels, out_channels * 2, 1)
|
414 |
+
|
415 |
+
def forward(self, x, x_lengths, g=None):
|
416 |
+
x_mask = torch.unsqueeze(commons.sequence_mask(x_lengths, x.size(2)), 1).to(
|
417 |
+
x.dtype
|
418 |
+
)
|
419 |
+
x = self.pre(x) * x_mask
|
420 |
+
x = self.enc(x, x_mask, g=g)
|
421 |
+
stats = self.proj(x) * x_mask
|
422 |
+
m, logs = torch.split(stats, self.out_channels, dim=1)
|
423 |
+
z = (m + torch.randn_like(m) * torch.exp(logs)) * x_mask
|
424 |
+
return z, m, logs, x_mask
|
425 |
+
|
426 |
+
|
427 |
+
class Generator(torch.nn.Module):
|
428 |
+
def __init__(
|
429 |
+
self,
|
430 |
+
initial_channel,
|
431 |
+
resblock,
|
432 |
+
resblock_kernel_sizes,
|
433 |
+
resblock_dilation_sizes,
|
434 |
+
upsample_rates,
|
435 |
+
upsample_initial_channel,
|
436 |
+
upsample_kernel_sizes,
|
437 |
+
gin_channels=0,
|
438 |
+
):
|
439 |
+
super(Generator, self).__init__()
|
440 |
+
self.num_kernels = len(resblock_kernel_sizes)
|
441 |
+
self.num_upsamples = len(upsample_rates)
|
442 |
+
self.conv_pre = Conv1d(
|
443 |
+
initial_channel, upsample_initial_channel, 7, 1, padding=3
|
444 |
+
)
|
445 |
+
resblock = modules.ResBlock1 if resblock == "1" else modules.ResBlock2
|
446 |
+
|
447 |
+
self.ups = nn.ModuleList()
|
448 |
+
for i, (u, k) in enumerate(zip(upsample_rates, upsample_kernel_sizes)):
|
449 |
+
self.ups.append(
|
450 |
+
weight_norm(
|
451 |
+
ConvTranspose1d(
|
452 |
+
upsample_initial_channel // (2**i),
|
453 |
+
upsample_initial_channel // (2 ** (i + 1)),
|
454 |
+
k,
|
455 |
+
u,
|
456 |
+
padding=(k - u) // 2,
|
457 |
+
)
|
458 |
+
)
|
459 |
+
)
|
460 |
+
|
461 |
+
self.resblocks = nn.ModuleList()
|
462 |
+
for i in range(len(self.ups)):
|
463 |
+
ch = upsample_initial_channel // (2 ** (i + 1))
|
464 |
+
for j, (k, d) in enumerate(
|
465 |
+
zip(resblock_kernel_sizes, resblock_dilation_sizes)
|
466 |
+
):
|
467 |
+
self.resblocks.append(resblock(ch, k, d))
|
468 |
+
|
469 |
+
self.conv_post = Conv1d(ch, 1, 7, 1, padding=3, bias=False)
|
470 |
+
self.ups.apply(init_weights)
|
471 |
+
|
472 |
+
if gin_channels != 0:
|
473 |
+
self.cond = nn.Conv1d(gin_channels, upsample_initial_channel, 1)
|
474 |
+
|
475 |
+
def forward(self, x, g=None):
|
476 |
+
x = self.conv_pre(x)
|
477 |
+
if g is not None:
|
478 |
+
x = x + self.cond(g)
|
479 |
+
|
480 |
+
for i in range(self.num_upsamples):
|
481 |
+
x = F.leaky_relu(x, modules.LRELU_SLOPE)
|
482 |
+
x = self.ups[i](x)
|
483 |
+
xs = None
|
484 |
+
for j in range(self.num_kernels):
|
485 |
+
if xs is None:
|
486 |
+
xs = self.resblocks[i * self.num_kernels + j](x)
|
487 |
+
else:
|
488 |
+
xs += self.resblocks[i * self.num_kernels + j](x)
|
489 |
+
x = xs / self.num_kernels
|
490 |
+
x = F.leaky_relu(x)
|
491 |
+
x = self.conv_post(x)
|
492 |
+
x = torch.tanh(x)
|
493 |
+
|
494 |
+
return x
|
495 |
+
|
496 |
+
def remove_weight_norm(self):
|
497 |
+
print("Removing weight norm...")
|
498 |
+
for layer in self.ups:
|
499 |
+
remove_weight_norm(layer)
|
500 |
+
for layer in self.resblocks:
|
501 |
+
layer.remove_weight_norm()
|
502 |
+
|
503 |
+
|
504 |
+
class DiscriminatorP(torch.nn.Module):
|
505 |
+
def __init__(self, period, kernel_size=5, stride=3, use_spectral_norm=False):
|
506 |
+
super(DiscriminatorP, self).__init__()
|
507 |
+
self.period = period
|
508 |
+
self.use_spectral_norm = use_spectral_norm
|
509 |
+
norm_f = weight_norm if use_spectral_norm is False else spectral_norm
|
510 |
+
self.convs = nn.ModuleList(
|
511 |
+
[
|
512 |
+
norm_f(
|
513 |
+
Conv2d(
|
514 |
+
1,
|
515 |
+
32,
|
516 |
+
(kernel_size, 1),
|
517 |
+
(stride, 1),
|
518 |
+
padding=(get_padding(kernel_size, 1), 0),
|
519 |
+
)
|
520 |
+
),
|
521 |
+
norm_f(
|
522 |
+
Conv2d(
|
523 |
+
32,
|
524 |
+
128,
|
525 |
+
(kernel_size, 1),
|
526 |
+
(stride, 1),
|
527 |
+
padding=(get_padding(kernel_size, 1), 0),
|
528 |
+
)
|
529 |
+
),
|
530 |
+
norm_f(
|
531 |
+
Conv2d(
|
532 |
+
128,
|
533 |
+
512,
|
534 |
+
(kernel_size, 1),
|
535 |
+
(stride, 1),
|
536 |
+
padding=(get_padding(kernel_size, 1), 0),
|
537 |
+
)
|
538 |
+
),
|
539 |
+
norm_f(
|
540 |
+
Conv2d(
|
541 |
+
512,
|
542 |
+
1024,
|
543 |
+
(kernel_size, 1),
|
544 |
+
(stride, 1),
|
545 |
+
padding=(get_padding(kernel_size, 1), 0),
|
546 |
+
)
|
547 |
+
),
|
548 |
+
norm_f(
|
549 |
+
Conv2d(
|
550 |
+
1024,
|
551 |
+
1024,
|
552 |
+
(kernel_size, 1),
|
553 |
+
1,
|
554 |
+
padding=(get_padding(kernel_size, 1), 0),
|
555 |
+
)
|
556 |
+
),
|
557 |
+
]
|
558 |
+
)
|
559 |
+
self.conv_post = norm_f(Conv2d(1024, 1, (3, 1), 1, padding=(1, 0)))
|
560 |
+
|
561 |
+
def forward(self, x):
|
562 |
+
fmap = []
|
563 |
+
|
564 |
+
# 1d to 2d
|
565 |
+
b, c, t = x.shape
|
566 |
+
if t % self.period != 0: # pad first
|
567 |
+
n_pad = self.period - (t % self.period)
|
568 |
+
x = F.pad(x, (0, n_pad), "reflect")
|
569 |
+
t = t + n_pad
|
570 |
+
x = x.view(b, c, t // self.period, self.period)
|
571 |
+
|
572 |
+
for layer in self.convs:
|
573 |
+
x = layer(x)
|
574 |
+
x = F.leaky_relu(x, modules.LRELU_SLOPE)
|
575 |
+
fmap.append(x)
|
576 |
+
x = self.conv_post(x)
|
577 |
+
fmap.append(x)
|
578 |
+
x = torch.flatten(x, 1, -1)
|
579 |
+
|
580 |
+
return x, fmap
|
581 |
+
|
582 |
+
|
583 |
+
class DiscriminatorS(torch.nn.Module):
|
584 |
+
def __init__(self, use_spectral_norm=False):
|
585 |
+
super(DiscriminatorS, self).__init__()
|
586 |
+
norm_f = weight_norm if use_spectral_norm is False else spectral_norm
|
587 |
+
self.convs = nn.ModuleList(
|
588 |
+
[
|
589 |
+
norm_f(Conv1d(1, 16, 15, 1, padding=7)),
|
590 |
+
norm_f(Conv1d(16, 64, 41, 4, groups=4, padding=20)),
|
591 |
+
norm_f(Conv1d(64, 256, 41, 4, groups=16, padding=20)),
|
592 |
+
norm_f(Conv1d(256, 1024, 41, 4, groups=64, padding=20)),
|
593 |
+
norm_f(Conv1d(1024, 1024, 41, 4, groups=256, padding=20)),
|
594 |
+
norm_f(Conv1d(1024, 1024, 5, 1, padding=2)),
|
595 |
+
]
|
596 |
+
)
|
597 |
+
self.conv_post = norm_f(Conv1d(1024, 1, 3, 1, padding=1))
|
598 |
+
|
599 |
+
def forward(self, x):
|
600 |
+
fmap = []
|
601 |
+
|
602 |
+
for layer in self.convs:
|
603 |
+
x = layer(x)
|
604 |
+
x = F.leaky_relu(x, modules.LRELU_SLOPE)
|
605 |
+
fmap.append(x)
|
606 |
+
x = self.conv_post(x)
|
607 |
+
fmap.append(x)
|
608 |
+
x = torch.flatten(x, 1, -1)
|
609 |
+
|
610 |
+
return x, fmap
|
611 |
+
|
612 |
+
|
613 |
+
class MultiPeriodDiscriminator(torch.nn.Module):
|
614 |
+
def __init__(self, use_spectral_norm=False):
|
615 |
+
super(MultiPeriodDiscriminator, self).__init__()
|
616 |
+
periods = [2, 3, 5, 7, 11]
|
617 |
+
|
618 |
+
discs = [DiscriminatorS(use_spectral_norm=use_spectral_norm)]
|
619 |
+
discs = discs + [
|
620 |
+
DiscriminatorP(i, use_spectral_norm=use_spectral_norm) for i in periods
|
621 |
+
]
|
622 |
+
self.discriminators = nn.ModuleList(discs)
|
623 |
+
|
624 |
+
def forward(self, y, y_hat):
|
625 |
+
y_d_rs = []
|
626 |
+
y_d_gs = []
|
627 |
+
fmap_rs = []
|
628 |
+
fmap_gs = []
|
629 |
+
for i, d in enumerate(self.discriminators):
|
630 |
+
y_d_r, fmap_r = d(y)
|
631 |
+
y_d_g, fmap_g = d(y_hat)
|
632 |
+
y_d_rs.append(y_d_r)
|
633 |
+
y_d_gs.append(y_d_g)
|
634 |
+
fmap_rs.append(fmap_r)
|
635 |
+
fmap_gs.append(fmap_g)
|
636 |
+
|
637 |
+
return y_d_rs, y_d_gs, fmap_rs, fmap_gs
|
638 |
+
|
639 |
+
|
640 |
+
class ReferenceEncoder(nn.Module):
|
641 |
+
"""
|
642 |
+
inputs --- [N, Ty/r, n_mels*r] mels
|
643 |
+
outputs --- [N, ref_enc_gru_size]
|
644 |
+
"""
|
645 |
+
|
646 |
+
def __init__(self, spec_channels, gin_channels=0):
|
647 |
+
super().__init__()
|
648 |
+
self.spec_channels = spec_channels
|
649 |
+
ref_enc_filters = [32, 32, 64, 64, 128, 128]
|
650 |
+
K = len(ref_enc_filters)
|
651 |
+
filters = [1] + ref_enc_filters
|
652 |
+
convs = [
|
653 |
+
weight_norm(
|
654 |
+
nn.Conv2d(
|
655 |
+
in_channels=filters[i],
|
656 |
+
out_channels=filters[i + 1],
|
657 |
+
kernel_size=(3, 3),
|
658 |
+
stride=(2, 2),
|
659 |
+
padding=(1, 1),
|
660 |
+
)
|
661 |
+
)
|
662 |
+
for i in range(K)
|
663 |
+
]
|
664 |
+
self.convs = nn.ModuleList(convs)
|
665 |
+
# self.wns = nn.ModuleList([weight_norm(num_features=ref_enc_filters[i]) for i in range(K)]) # noqa: E501
|
666 |
+
|
667 |
+
out_channels = self.calculate_channels(spec_channels, 3, 2, 1, K)
|
668 |
+
self.gru = nn.GRU(
|
669 |
+
input_size=ref_enc_filters[-1] * out_channels,
|
670 |
+
hidden_size=256 // 2,
|
671 |
+
batch_first=True,
|
672 |
+
)
|
673 |
+
self.proj = nn.Linear(128, gin_channels)
|
674 |
+
|
675 |
+
def forward(self, inputs, mask=None):
|
676 |
+
N = inputs.size(0)
|
677 |
+
out = inputs.view(N, 1, -1, self.spec_channels) # [N, 1, Ty, n_freqs]
|
678 |
+
for conv in self.convs:
|
679 |
+
out = conv(out)
|
680 |
+
# out = wn(out)
|
681 |
+
out = F.relu(out) # [N, 128, Ty//2^K, n_mels//2^K]
|
682 |
+
|
683 |
+
out = out.transpose(1, 2) # [N, Ty//2^K, 128, n_mels//2^K]
|
684 |
+
T = out.size(1)
|
685 |
+
N = out.size(0)
|
686 |
+
out = out.contiguous().view(N, T, -1) # [N, Ty//2^K, 128*n_mels//2^K]
|
687 |
+
|
688 |
+
self.gru.flatten_parameters()
|
689 |
+
memory, out = self.gru(out) # out --- [1, N, 128]
|
690 |
+
|
691 |
+
return self.proj(out.squeeze(0))
|
692 |
+
|
693 |
+
def calculate_channels(self, L, kernel_size, stride, pad, n_convs):
|
694 |
+
for i in range(n_convs):
|
695 |
+
L = (L - kernel_size + 2 * pad) // stride + 1
|
696 |
+
return L
|
697 |
+
|
698 |
+
|
699 |
+
class SynthesizerTrn(nn.Module):
|
700 |
+
"""
|
701 |
+
Synthesizer for Training
|
702 |
+
"""
|
703 |
+
|
704 |
+
def __init__(
|
705 |
+
self,
|
706 |
+
n_vocab,
|
707 |
+
spec_channels,
|
708 |
+
segment_size,
|
709 |
+
inter_channels,
|
710 |
+
hidden_channels,
|
711 |
+
filter_channels,
|
712 |
+
n_heads,
|
713 |
+
n_layers,
|
714 |
+
kernel_size,
|
715 |
+
p_dropout,
|
716 |
+
resblock,
|
717 |
+
resblock_kernel_sizes,
|
718 |
+
resblock_dilation_sizes,
|
719 |
+
upsample_rates,
|
720 |
+
upsample_initial_channel,
|
721 |
+
upsample_kernel_sizes,
|
722 |
+
n_speakers=256,
|
723 |
+
gin_channels=256,
|
724 |
+
use_sdp=True,
|
725 |
+
n_flow_layer=4,
|
726 |
+
n_layers_trans_flow=4,
|
727 |
+
flow_share_parameter=False,
|
728 |
+
use_transformer_flow=True,
|
729 |
+
**kwargs,
|
730 |
+
):
|
731 |
+
super().__init__()
|
732 |
+
self.n_vocab = n_vocab
|
733 |
+
self.spec_channels = spec_channels
|
734 |
+
self.inter_channels = inter_channels
|
735 |
+
self.hidden_channels = hidden_channels
|
736 |
+
self.filter_channels = filter_channels
|
737 |
+
self.n_heads = n_heads
|
738 |
+
self.n_layers = n_layers
|
739 |
+
self.kernel_size = kernel_size
|
740 |
+
self.p_dropout = p_dropout
|
741 |
+
self.resblock = resblock
|
742 |
+
self.resblock_kernel_sizes = resblock_kernel_sizes
|
743 |
+
self.resblock_dilation_sizes = resblock_dilation_sizes
|
744 |
+
self.upsample_rates = upsample_rates
|
745 |
+
self.upsample_initial_channel = upsample_initial_channel
|
746 |
+
self.upsample_kernel_sizes = upsample_kernel_sizes
|
747 |
+
self.segment_size = segment_size
|
748 |
+
self.n_speakers = n_speakers
|
749 |
+
self.gin_channels = gin_channels
|
750 |
+
self.n_layers_trans_flow = n_layers_trans_flow
|
751 |
+
self.use_spk_conditioned_encoder = kwargs.get(
|
752 |
+
"use_spk_conditioned_encoder", True
|
753 |
+
)
|
754 |
+
self.use_sdp = use_sdp
|
755 |
+
self.use_noise_scaled_mas = kwargs.get("use_noise_scaled_mas", False)
|
756 |
+
self.mas_noise_scale_initial = kwargs.get("mas_noise_scale_initial", 0.01)
|
757 |
+
self.noise_scale_delta = kwargs.get("noise_scale_delta", 2e-6)
|
758 |
+
self.current_mas_noise_scale = self.mas_noise_scale_initial
|
759 |
+
if self.use_spk_conditioned_encoder and gin_channels > 0:
|
760 |
+
self.enc_gin_channels = gin_channels
|
761 |
+
self.enc_p = TextEncoder(
|
762 |
+
n_vocab,
|
763 |
+
inter_channels,
|
764 |
+
hidden_channels,
|
765 |
+
filter_channels,
|
766 |
+
n_heads,
|
767 |
+
n_layers,
|
768 |
+
kernel_size,
|
769 |
+
p_dropout,
|
770 |
+
gin_channels=self.enc_gin_channels,
|
771 |
+
)
|
772 |
+
self.dec = Generator(
|
773 |
+
inter_channels,
|
774 |
+
resblock,
|
775 |
+
resblock_kernel_sizes,
|
776 |
+
resblock_dilation_sizes,
|
777 |
+
upsample_rates,
|
778 |
+
upsample_initial_channel,
|
779 |
+
upsample_kernel_sizes,
|
780 |
+
gin_channels=gin_channels,
|
781 |
+
)
|
782 |
+
self.enc_q = PosteriorEncoder(
|
783 |
+
spec_channels,
|
784 |
+
inter_channels,
|
785 |
+
hidden_channels,
|
786 |
+
5,
|
787 |
+
1,
|
788 |
+
16,
|
789 |
+
gin_channels=gin_channels,
|
790 |
+
)
|
791 |
+
if use_transformer_flow:
|
792 |
+
self.flow = TransformerCouplingBlock(
|
793 |
+
inter_channels,
|
794 |
+
hidden_channels,
|
795 |
+
filter_channels,
|
796 |
+
n_heads,
|
797 |
+
n_layers_trans_flow,
|
798 |
+
5,
|
799 |
+
p_dropout,
|
800 |
+
n_flow_layer,
|
801 |
+
gin_channels=gin_channels,
|
802 |
+
share_parameter=flow_share_parameter,
|
803 |
+
)
|
804 |
+
else:
|
805 |
+
self.flow = ResidualCouplingBlock(
|
806 |
+
inter_channels,
|
807 |
+
hidden_channels,
|
808 |
+
5,
|
809 |
+
1,
|
810 |
+
n_flow_layer,
|
811 |
+
gin_channels=gin_channels,
|
812 |
+
)
|
813 |
+
self.sdp = StochasticDurationPredictor(
|
814 |
+
hidden_channels, 192, 3, 0.5, 4, gin_channels=gin_channels
|
815 |
+
)
|
816 |
+
self.dp = DurationPredictor(
|
817 |
+
hidden_channels, 256, 3, 0.5, gin_channels=gin_channels
|
818 |
+
)
|
819 |
+
|
820 |
+
if n_speakers >= 1:
|
821 |
+
self.emb_g = nn.Embedding(n_speakers, gin_channels)
|
822 |
+
else:
|
823 |
+
self.ref_enc = ReferenceEncoder(spec_channels, gin_channels)
|
824 |
+
|
825 |
+
def export_onnx(
|
826 |
+
self,
|
827 |
+
path,
|
828 |
+
max_len=None,
|
829 |
+
sdp_ratio=0,
|
830 |
+
y=None,
|
831 |
+
):
|
832 |
+
noise_scale = 0.667
|
833 |
+
length_scale = 1
|
834 |
+
noise_scale_w = 0.8
|
835 |
+
x = (
|
836 |
+
torch.LongTensor(
|
837 |
+
[
|
838 |
+
0,
|
839 |
+
97,
|
840 |
+
0,
|
841 |
+
8,
|
842 |
+
0,
|
843 |
+
78,
|
844 |
+
0,
|
845 |
+
8,
|
846 |
+
0,
|
847 |
+
76,
|
848 |
+
0,
|
849 |
+
37,
|
850 |
+
0,
|
851 |
+
40,
|
852 |
+
0,
|
853 |
+
97,
|
854 |
+
0,
|
855 |
+
8,
|
856 |
+
0,
|
857 |
+
23,
|
858 |
+
0,
|
859 |
+
8,
|
860 |
+
0,
|
861 |
+
74,
|
862 |
+
0,
|
863 |
+
26,
|
864 |
+
0,
|
865 |
+
104,
|
866 |
+
0,
|
867 |
+
]
|
868 |
+
)
|
869 |
+
.unsqueeze(0)
|
870 |
+
.cpu()
|
871 |
+
)
|
872 |
+
tone = torch.zeros_like(x).cpu()
|
873 |
+
language = torch.zeros_like(x).cpu()
|
874 |
+
x_lengths = torch.LongTensor([x.shape[1]]).cpu()
|
875 |
+
sid = torch.LongTensor([0]).cpu()
|
876 |
+
bert = torch.randn(size=(x.shape[1], 1024)).cpu()
|
877 |
+
ja_bert = torch.randn(size=(x.shape[1], 1024)).cpu()
|
878 |
+
en_bert = torch.randn(size=(x.shape[1], 1024)).cpu()
|
879 |
+
|
880 |
+
if self.n_speakers > 0:
|
881 |
+
g = self.emb_g(sid).unsqueeze(-1) # [b, h, 1]
|
882 |
+
torch.onnx.export(
|
883 |
+
self.emb_g,
|
884 |
+
(sid),
|
885 |
+
f"onnx/{path}/{path}_emb.onnx",
|
886 |
+
input_names=["sid"],
|
887 |
+
output_names=["g"],
|
888 |
+
verbose=True,
|
889 |
+
)
|
890 |
+
else:
|
891 |
+
g = self.ref_enc(y.transpose(1, 2)).unsqueeze(-1)
|
892 |
+
|
893 |
+
torch.onnx.export(
|
894 |
+
self.enc_p,
|
895 |
+
(x, x_lengths, tone, language, bert, ja_bert, en_bert, g),
|
896 |
+
f"onnx/{path}/{path}_enc_p.onnx",
|
897 |
+
input_names=[
|
898 |
+
"x",
|
899 |
+
"x_lengths",
|
900 |
+
"t",
|
901 |
+
"language",
|
902 |
+
"bert_0",
|
903 |
+
"bert_1",
|
904 |
+
"bert_2",
|
905 |
+
"g",
|
906 |
+
],
|
907 |
+
output_names=["xout", "m_p", "logs_p", "x_mask"],
|
908 |
+
dynamic_axes={
|
909 |
+
"x": [0, 1],
|
910 |
+
"t": [0, 1],
|
911 |
+
"language": [0, 1],
|
912 |
+
"bert_0": [0],
|
913 |
+
"bert_1": [0],
|
914 |
+
"bert_2": [0],
|
915 |
+
"xout": [0, 2],
|
916 |
+
"m_p": [0, 2],
|
917 |
+
"logs_p": [0, 2],
|
918 |
+
"x_mask": [0, 2],
|
919 |
+
},
|
920 |
+
verbose=True,
|
921 |
+
opset_version=16,
|
922 |
+
)
|
923 |
+
x, m_p, logs_p, x_mask = self.enc_p(
|
924 |
+
x, x_lengths, tone, language, bert, ja_bert, en_bert, g=g
|
925 |
+
)
|
926 |
+
zinput = (
|
927 |
+
torch.randn(x.size(0), 2, x.size(2)).to(device=x.device, dtype=x.dtype)
|
928 |
+
* noise_scale_w
|
929 |
+
)
|
930 |
+
torch.onnx.export(
|
931 |
+
self.sdp,
|
932 |
+
(x, x_mask, zinput, g),
|
933 |
+
f"onnx/{path}/{path}_sdp.onnx",
|
934 |
+
input_names=["x", "x_mask", "zin", "g"],
|
935 |
+
output_names=["logw"],
|
936 |
+
dynamic_axes={"x": [0, 2], "x_mask": [0, 2], "zin": [0, 2], "logw": [0, 2]},
|
937 |
+
verbose=True,
|
938 |
+
)
|
939 |
+
torch.onnx.export(
|
940 |
+
self.dp,
|
941 |
+
(x, x_mask, g),
|
942 |
+
f"onnx/{path}/{path}_dp.onnx",
|
943 |
+
input_names=["x", "x_mask", "g"],
|
944 |
+
output_names=["logw"],
|
945 |
+
dynamic_axes={"x": [0, 2], "x_mask": [0, 2], "logw": [0, 2]},
|
946 |
+
verbose=True,
|
947 |
+
)
|
948 |
+
logw = self.sdp(x, x_mask, zinput, g=g) * (sdp_ratio) + self.dp(
|
949 |
+
x, x_mask, g=g
|
950 |
+
) * (1 - sdp_ratio)
|
951 |
+
w = torch.exp(logw) * x_mask * length_scale
|
952 |
+
w_ceil = torch.ceil(w)
|
953 |
+
y_lengths = torch.clamp_min(torch.sum(w_ceil, [1, 2]), 1).long()
|
954 |
+
y_mask = torch.unsqueeze(commons.sequence_mask(y_lengths, None), 1).to(
|
955 |
+
x_mask.dtype
|
956 |
+
)
|
957 |
+
attn_mask = torch.unsqueeze(x_mask, 2) * torch.unsqueeze(y_mask, -1)
|
958 |
+
attn = commons.generate_path(w_ceil, attn_mask)
|
959 |
+
|
960 |
+
m_p = torch.matmul(attn.squeeze(1), m_p.transpose(1, 2)).transpose(
|
961 |
+
1, 2
|
962 |
+
) # [b, t', t], [b, t, d] -> [b, d, t']
|
963 |
+
logs_p = torch.matmul(attn.squeeze(1), logs_p.transpose(1, 2)).transpose(
|
964 |
+
1, 2
|
965 |
+
) # [b, t', t], [b, t, d] -> [b, d, t']
|
966 |
+
|
967 |
+
z_p = m_p + torch.randn_like(m_p) * torch.exp(logs_p) * noise_scale
|
968 |
+
torch.onnx.export(
|
969 |
+
self.flow,
|
970 |
+
(z_p, y_mask, g),
|
971 |
+
f"onnx/{path}/{path}_flow.onnx",
|
972 |
+
input_names=["z_p", "y_mask", "g"],
|
973 |
+
output_names=["z"],
|
974 |
+
dynamic_axes={"z_p": [0, 2], "y_mask": [0, 2], "z": [0, 2]},
|
975 |
+
verbose=True,
|
976 |
+
)
|
977 |
+
|
978 |
+
z = self.flow(z_p, y_mask, g=g, reverse=True)
|
979 |
+
z_in = (z * y_mask)[:, :, :max_len]
|
980 |
+
|
981 |
+
torch.onnx.export(
|
982 |
+
self.dec,
|
983 |
+
(z_in, g),
|
984 |
+
f"onnx/{path}/{path}_dec.onnx",
|
985 |
+
input_names=["z_in", "g"],
|
986 |
+
output_names=["o"],
|
987 |
+
dynamic_axes={"z_in": [0, 2], "o": [0, 2]},
|
988 |
+
verbose=True,
|
989 |
+
)
|
990 |
+
o = self.dec((z * y_mask)[:, :, :max_len], g=g)
|
onnx_modules/V200/text/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
from .symbols import *
|