Spaces:
Running
Running
saya
commited on
Commit
·
c9492f8
0
Parent(s):
Duplicate from sayashi/sovits-models
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +34 -0
- .gitignore +382 -0
- LICENSE +407 -0
- README.md +12 -0
- app.py +90 -0
- cluster/__init__.py +29 -0
- cluster/__pycache__/__init__.cpython-38.pyc +0 -0
- cluster/train_cluster.py +89 -0
- configs/config.json +64 -0
- cvec/checkpoint_best_legacy_500.pt +3 -0
- hubert/__init__.py +0 -0
- hubert/__pycache__/__init__.cpython-38.pyc +0 -0
- hubert/__pycache__/hubert_model.cpython-38.pyc +0 -0
- hubert/checkpoint_best_legacy_500.pt +3 -0
- hubert/hubert_model.py +222 -0
- hubert/hubert_model_onnx.py +217 -0
- inference/__init__.py +0 -0
- inference/__pycache__/__init__.cpython-38.pyc +0 -0
- inference/__pycache__/infer_tool.cpython-38.pyc +0 -0
- inference/__pycache__/slicer.cpython-38.pyc +0 -0
- inference/chunks_temp.json +1 -0
- inference/infer_tool.py +273 -0
- inference/infer_tool_grad.py +160 -0
- inference/slicer.py +142 -0
- inference_main.py +100 -0
- models.py +420 -0
- models/alice/alice.pth +3 -0
- models/alice/config.json +93 -0
- models/alice/cover.png +0 -0
- models/goldship/config.json +93 -0
- models/goldship/cover.png +0 -0
- models/goldship/goldship.pth +3 -0
- models/rudolf/config.json +93 -0
- models/rudolf/cover.png +0 -0
- models/rudolf/rudolf.pth +3 -0
- models/tannhauser/config.json +93 -0
- models/tannhauser/cover.png +0 -0
- models/tannhauser/tannhauser.pth +3 -0
- models/teio/config.json +93 -0
- models/teio/cover.png +0 -0
- models/teio/teio.pth +3 -0
- modules/__init__.py +0 -0
- modules/__pycache__/__init__.cpython-38.pyc +0 -0
- modules/__pycache__/attentions.cpython-38.pyc +0 -0
- modules/__pycache__/commons.cpython-38.pyc +0 -0
- modules/__pycache__/modules.cpython-38.pyc +0 -0
- modules/attentions.py +349 -0
- modules/commons.py +188 -0
- modules/ddsp.py +190 -0
- modules/losses.py +61 -0
.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
|
.gitignore
ADDED
@@ -0,0 +1,382 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## Ignore Visual Studio temporary files, build results, and
|
2 |
+
## files generated by popular Visual Studio add-ons.
|
3 |
+
##
|
4 |
+
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
5 |
+
|
6 |
+
# User-specific files
|
7 |
+
*.rsuser
|
8 |
+
*.suo
|
9 |
+
*.user
|
10 |
+
*.userosscache
|
11 |
+
*.sln.docstates
|
12 |
+
|
13 |
+
# User-specific files (MonoDevelop/Xamarin Studio)
|
14 |
+
*.userprefs
|
15 |
+
|
16 |
+
# Mono auto generated files
|
17 |
+
mono_crash.*
|
18 |
+
|
19 |
+
# Build results
|
20 |
+
[Dd]ebug/
|
21 |
+
[Dd]ebugPublic/
|
22 |
+
[Rr]elease/
|
23 |
+
[Rr]eleases/
|
24 |
+
x64/
|
25 |
+
x86/
|
26 |
+
[Ww][Ii][Nn]32/
|
27 |
+
[Aa][Rr][Mm]/
|
28 |
+
[Aa][Rr][Mm]64/
|
29 |
+
bld/
|
30 |
+
[Bb]in/
|
31 |
+
[Oo]bj/
|
32 |
+
[Oo]ut/
|
33 |
+
[Ll]og/
|
34 |
+
[Ll]ogs/
|
35 |
+
|
36 |
+
# Visual Studio 2015/2017 cache/options directory
|
37 |
+
.vs/
|
38 |
+
# Uncomment if you have tasks that create the project's static files in wwwroot
|
39 |
+
#wwwroot/
|
40 |
+
|
41 |
+
# Visual Studio 2017 auto generated files
|
42 |
+
Generated\ Files/
|
43 |
+
|
44 |
+
# MSTest test Results
|
45 |
+
[Tt]est[Rr]esult*/
|
46 |
+
[Bb]uild[Ll]og.*
|
47 |
+
|
48 |
+
# NUnit
|
49 |
+
*.VisualState.xml
|
50 |
+
TestResult.xml
|
51 |
+
nunit-*.xml
|
52 |
+
|
53 |
+
# Build Results of an ATL Project
|
54 |
+
[Dd]ebugPS/
|
55 |
+
[Rr]eleasePS/
|
56 |
+
dlldata.c
|
57 |
+
|
58 |
+
# Benchmark Results
|
59 |
+
BenchmarkDotNet.Artifacts/
|
60 |
+
|
61 |
+
# .NET Core
|
62 |
+
project.lock.json
|
63 |
+
project.fragment.lock.json
|
64 |
+
artifacts/
|
65 |
+
|
66 |
+
# ASP.NET Scaffolding
|
67 |
+
ScaffoldingReadMe.txt
|
68 |
+
|
69 |
+
# StyleCop
|
70 |
+
StyleCopReport.xml
|
71 |
+
|
72 |
+
# Files built by Visual Studio
|
73 |
+
*_i.c
|
74 |
+
*_p.c
|
75 |
+
*_h.h
|
76 |
+
*.ilk
|
77 |
+
*.meta
|
78 |
+
*.obj
|
79 |
+
*.iobj
|
80 |
+
*.pch
|
81 |
+
*.pdb
|
82 |
+
*.ipdb
|
83 |
+
*.pgc
|
84 |
+
*.pgd
|
85 |
+
*.rsp
|
86 |
+
*.sbr
|
87 |
+
*.tlb
|
88 |
+
*.tli
|
89 |
+
*.tlh
|
90 |
+
*.tmp
|
91 |
+
*.tmp_proj
|
92 |
+
*_wpftmp.csproj
|
93 |
+
*.log
|
94 |
+
*.vspscc
|
95 |
+
*.vssscc
|
96 |
+
.builds
|
97 |
+
*.pidb
|
98 |
+
*.svclog
|
99 |
+
*.scc
|
100 |
+
|
101 |
+
# Chutzpah Test files
|
102 |
+
_Chutzpah*
|
103 |
+
|
104 |
+
# Visual C++ cache files
|
105 |
+
ipch/
|
106 |
+
*.aps
|
107 |
+
*.ncb
|
108 |
+
*.opendb
|
109 |
+
*.opensdf
|
110 |
+
*.sdf
|
111 |
+
*.cachefile
|
112 |
+
*.VC.db
|
113 |
+
*.VC.VC.opendb
|
114 |
+
|
115 |
+
# Visual Studio profiler
|
116 |
+
*.psess
|
117 |
+
*.vsp
|
118 |
+
*.vspx
|
119 |
+
*.sap
|
120 |
+
|
121 |
+
# Visual Studio Trace Files
|
122 |
+
*.e2e
|
123 |
+
|
124 |
+
# TFS 2012 Local Workspace
|
125 |
+
$tf/
|
126 |
+
|
127 |
+
# Guidance Automation Toolkit
|
128 |
+
*.gpState
|
129 |
+
|
130 |
+
# ReSharper is a .NET coding add-in
|
131 |
+
_ReSharper*/
|
132 |
+
*.[Rr]e[Ss]harper
|
133 |
+
*.DotSettings.user
|
134 |
+
|
135 |
+
# TeamCity is a build add-in
|
136 |
+
_TeamCity*
|
137 |
+
|
138 |
+
# DotCover is a Code Coverage Tool
|
139 |
+
*.dotCover
|
140 |
+
|
141 |
+
# AxoCover is a Code Coverage Tool
|
142 |
+
.axoCover/*
|
143 |
+
!.axoCover/settings.json
|
144 |
+
|
145 |
+
# Coverlet is a free, cross platform Code Coverage Tool
|
146 |
+
coverage*.json
|
147 |
+
coverage*.xml
|
148 |
+
coverage*.info
|
149 |
+
|
150 |
+
# Visual Studio code coverage results
|
151 |
+
*.coverage
|
152 |
+
*.coveragexml
|
153 |
+
|
154 |
+
# NCrunch
|
155 |
+
_NCrunch_*
|
156 |
+
.*crunch*.local.xml
|
157 |
+
nCrunchTemp_*
|
158 |
+
|
159 |
+
# MightyMoose
|
160 |
+
*.mm.*
|
161 |
+
AutoTest.Net/
|
162 |
+
|
163 |
+
# Web workbench (sass)
|
164 |
+
.sass-cache/
|
165 |
+
|
166 |
+
# Installshield output folder
|
167 |
+
[Ee]xpress/
|
168 |
+
|
169 |
+
# DocProject is a documentation generator add-in
|
170 |
+
DocProject/buildhelp/
|
171 |
+
DocProject/Help/*.HxT
|
172 |
+
DocProject/Help/*.HxC
|
173 |
+
DocProject/Help/*.hhc
|
174 |
+
DocProject/Help/*.hhk
|
175 |
+
DocProject/Help/*.hhp
|
176 |
+
DocProject/Help/Html2
|
177 |
+
DocProject/Help/html
|
178 |
+
|
179 |
+
# Click-Once directory
|
180 |
+
publish/
|
181 |
+
|
182 |
+
# Publish Web Output
|
183 |
+
*.[Pp]ublish.xml
|
184 |
+
*.azurePubxml
|
185 |
+
# Note: Comment the next line if you want to checkin your web deploy settings,
|
186 |
+
# but database connection strings (with potential passwords) will be unencrypted
|
187 |
+
*.pubxml
|
188 |
+
*.publishproj
|
189 |
+
|
190 |
+
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
191 |
+
# checkin your Azure Web App publish settings, but sensitive information contained
|
192 |
+
# in these scripts will be unencrypted
|
193 |
+
PublishScripts/
|
194 |
+
|
195 |
+
# NuGet Packages
|
196 |
+
*.nupkg
|
197 |
+
# NuGet Symbol Packages
|
198 |
+
*.snupkg
|
199 |
+
# The packages folder can be ignored because of Package Restore
|
200 |
+
**/[Pp]ackages/*
|
201 |
+
# except build/, which is used as an MSBuild target.
|
202 |
+
!**/[Pp]ackages/build/
|
203 |
+
# Uncomment if necessary however generally it will be regenerated when needed
|
204 |
+
#!**/[Pp]ackages/repositories.config
|
205 |
+
# NuGet v3's project.json files produces more ignorable files
|
206 |
+
*.nuget.props
|
207 |
+
*.nuget.targets
|
208 |
+
|
209 |
+
# Microsoft Azure Build Output
|
210 |
+
csx/
|
211 |
+
*.build.csdef
|
212 |
+
|
213 |
+
# Microsoft Azure Emulator
|
214 |
+
ecf/
|
215 |
+
rcf/
|
216 |
+
|
217 |
+
# Windows Store app package directories and files
|
218 |
+
AppPackages/
|
219 |
+
BundleArtifacts/
|
220 |
+
Package.StoreAssociation.xml
|
221 |
+
_pkginfo.txt
|
222 |
+
*.appx
|
223 |
+
*.appxbundle
|
224 |
+
*.appxupload
|
225 |
+
|
226 |
+
# Visual Studio cache files
|
227 |
+
# files ending in .cache can be ignored
|
228 |
+
*.[Cc]ache
|
229 |
+
# but keep track of directories ending in .cache
|
230 |
+
!?*.[Cc]ache/
|
231 |
+
|
232 |
+
# Others
|
233 |
+
ClientBin/
|
234 |
+
~$*
|
235 |
+
*~
|
236 |
+
*.dbmdl
|
237 |
+
*.dbproj.schemaview
|
238 |
+
*.jfm
|
239 |
+
*.pfx
|
240 |
+
*.publishsettings
|
241 |
+
orleans.codegen.cs
|
242 |
+
|
243 |
+
# Including strong name files can present a security risk
|
244 |
+
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
245 |
+
#*.snk
|
246 |
+
|
247 |
+
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
248 |
+
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
249 |
+
#bower_components/
|
250 |
+
|
251 |
+
# RIA/Silverlight projects
|
252 |
+
Generated_Code/
|
253 |
+
|
254 |
+
# Backup & report files from converting an old project file
|
255 |
+
# to a newer Visual Studio version. Backup files are not needed,
|
256 |
+
# because we have git ;-)
|
257 |
+
_UpgradeReport_Files/
|
258 |
+
Backup*/
|
259 |
+
UpgradeLog*.XML
|
260 |
+
UpgradeLog*.htm
|
261 |
+
ServiceFabricBackup/
|
262 |
+
*.rptproj.bak
|
263 |
+
|
264 |
+
# SQL Server files
|
265 |
+
*.mdf
|
266 |
+
*.ldf
|
267 |
+
*.ndf
|
268 |
+
|
269 |
+
# Business Intelligence projects
|
270 |
+
*.rdl.data
|
271 |
+
*.bim.layout
|
272 |
+
*.bim_*.settings
|
273 |
+
*.rptproj.rsuser
|
274 |
+
*- [Bb]ackup.rdl
|
275 |
+
*- [Bb]ackup ([0-9]).rdl
|
276 |
+
*- [Bb]ackup ([0-9][0-9]).rdl
|
277 |
+
|
278 |
+
# Microsoft Fakes
|
279 |
+
FakesAssemblies/
|
280 |
+
|
281 |
+
# GhostDoc plugin setting file
|
282 |
+
*.GhostDoc.xml
|
283 |
+
|
284 |
+
# Node.js Tools for Visual Studio
|
285 |
+
.ntvs_analysis.dat
|
286 |
+
node_modules/
|
287 |
+
|
288 |
+
# Visual Studio 6 build log
|
289 |
+
*.plg
|
290 |
+
|
291 |
+
# Visual Studio 6 workspace options file
|
292 |
+
*.opt
|
293 |
+
|
294 |
+
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
295 |
+
*.vbw
|
296 |
+
|
297 |
+
# Visual Studio LightSwitch build output
|
298 |
+
**/*.HTMLClient/GeneratedArtifacts
|
299 |
+
**/*.DesktopClient/GeneratedArtifacts
|
300 |
+
**/*.DesktopClient/ModelManifest.xml
|
301 |
+
**/*.Server/GeneratedArtifacts
|
302 |
+
**/*.Server/ModelManifest.xml
|
303 |
+
_Pvt_Extensions
|
304 |
+
|
305 |
+
# Paket dependency manager
|
306 |
+
.paket/paket.exe
|
307 |
+
paket-files/
|
308 |
+
|
309 |
+
# FAKE - F# Make
|
310 |
+
.fake/
|
311 |
+
|
312 |
+
# CodeRush personal settings
|
313 |
+
.cr/personal
|
314 |
+
|
315 |
+
# Python Tools for Visual Studio (PTVS)
|
316 |
+
__pycache__/
|
317 |
+
|
318 |
+
|
319 |
+
# Cake - Uncomment if you are using it
|
320 |
+
# tools/**
|
321 |
+
# !tools/packages.config
|
322 |
+
|
323 |
+
# Tabs Studio
|
324 |
+
*.tss
|
325 |
+
|
326 |
+
# Telerik's JustMock configuration file
|
327 |
+
*.jmconfig
|
328 |
+
|
329 |
+
# BizTalk build output
|
330 |
+
*.btp.cs
|
331 |
+
*.btm.cs
|
332 |
+
*.odx.cs
|
333 |
+
*.xsd.cs
|
334 |
+
|
335 |
+
# OpenCover UI analysis results
|
336 |
+
OpenCover/
|
337 |
+
|
338 |
+
# Azure Stream Analytics local run output
|
339 |
+
ASALocalRun/
|
340 |
+
|
341 |
+
# MSBuild Binary and Structured Log
|
342 |
+
*.binlog
|
343 |
+
|
344 |
+
# NVidia Nsight GPU debugger configuration file
|
345 |
+
*.nvuser
|
346 |
+
|
347 |
+
# MFractors (Xamarin productivity tool) working folder
|
348 |
+
.mfractor/
|
349 |
+
|
350 |
+
# Local History for Visual Studio
|
351 |
+
.localhistory/
|
352 |
+
|
353 |
+
# BeatPulse healthcheck temp database
|
354 |
+
healthchecksdb
|
355 |
+
|
356 |
+
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
357 |
+
MigrationBackup/
|
358 |
+
|
359 |
+
# Ionide (cross platform F# VS Code tools) working folder
|
360 |
+
.ionide/
|
361 |
+
|
362 |
+
# Fody - auto-generated XML schema
|
363 |
+
FodyWeavers.xsd
|
364 |
+
|
365 |
+
# build
|
366 |
+
build
|
367 |
+
monotonic_align/core.c
|
368 |
+
*.o
|
369 |
+
*.so
|
370 |
+
*.dll
|
371 |
+
|
372 |
+
# data
|
373 |
+
/config.json
|
374 |
+
/*.pth
|
375 |
+
*.wav
|
376 |
+
/monotonic_align/monotonic_align
|
377 |
+
/resources
|
378 |
+
/MoeGoe.spec
|
379 |
+
/dist/MoeGoe
|
380 |
+
/dist
|
381 |
+
|
382 |
+
.idea
|
LICENSE
ADDED
@@ -0,0 +1,407 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Attribution-NonCommercial 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 4.0 International Public
|
58 |
+
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 4.0 International Public License ("Public
|
63 |
+
License"). To the extent this Public License may be interpreted as a
|
64 |
+
contract, You are granted the Licensed Rights in consideration of Your
|
65 |
+
acceptance of these terms and conditions, and the Licensor grants You
|
66 |
+
such rights in consideration of benefits the Licensor receives from
|
67 |
+
making the Licensed Material available under these terms and
|
68 |
+
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. Copyright and Similar Rights means copyright and/or similar rights
|
88 |
+
closely related to copyright including, without limitation,
|
89 |
+
performance, broadcast, sound recording, and Sui Generis Database
|
90 |
+
Rights, without regard to how the rights are labeled or
|
91 |
+
categorized. For purposes of this Public License, the rights
|
92 |
+
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
93 |
+
Rights.
|
94 |
+
d. Effective Technological Measures means those measures that, in the
|
95 |
+
absence of proper authority, may not be circumvented under laws
|
96 |
+
fulfilling obligations under Article 11 of the WIPO Copyright
|
97 |
+
Treaty adopted on December 20, 1996, and/or similar international
|
98 |
+
agreements.
|
99 |
+
|
100 |
+
e. Exceptions and Limitations means fair use, fair dealing, and/or
|
101 |
+
any other exception or limitation to Copyright and Similar Rights
|
102 |
+
that applies to Your use of the Licensed Material.
|
103 |
+
|
104 |
+
f. Licensed Material means the artistic or literary work, database,
|
105 |
+
or other material to which the Licensor applied this Public
|
106 |
+
License.
|
107 |
+
|
108 |
+
g. Licensed Rights means the rights granted to You subject to the
|
109 |
+
terms and conditions of this Public License, which are limited to
|
110 |
+
all Copyright and Similar Rights that apply to Your use of the
|
111 |
+
Licensed Material and that the Licensor has authority to license.
|
112 |
+
|
113 |
+
h. Licensor means the individual(s) or entity(ies) granting rights
|
114 |
+
under this Public License.
|
115 |
+
|
116 |
+
i. NonCommercial means not primarily intended for or directed towards
|
117 |
+
commercial advantage or monetary compensation. For purposes of
|
118 |
+
this Public License, the exchange of the Licensed Material for
|
119 |
+
other material subject to Copyright and Similar Rights by digital
|
120 |
+
file-sharing or similar means is NonCommercial provided there is
|
121 |
+
no payment of monetary compensation in connection with the
|
122 |
+
exchange.
|
123 |
+
|
124 |
+
j. Share means to provide material to the public by any means or
|
125 |
+
process that requires permission under the Licensed Rights, such
|
126 |
+
as reproduction, public display, public performance, distribution,
|
127 |
+
dissemination, communication, or importation, and to make material
|
128 |
+
available to the public including in ways that members of the
|
129 |
+
public may access the material from a place and at a time
|
130 |
+
individually chosen by them.
|
131 |
+
|
132 |
+
k. Sui Generis Database Rights means rights other than copyright
|
133 |
+
resulting from Directive 96/9/EC of the European Parliament and of
|
134 |
+
the Council of 11 March 1996 on the legal protection of databases,
|
135 |
+
as amended and/or succeeded, as well as other essentially
|
136 |
+
equivalent rights anywhere in the world.
|
137 |
+
|
138 |
+
l. You means the individual or entity exercising the Licensed Rights
|
139 |
+
under this Public License. Your has a corresponding meaning.
|
140 |
+
|
141 |
+
|
142 |
+
Section 2 -- Scope.
|
143 |
+
|
144 |
+
a. License grant.
|
145 |
+
|
146 |
+
1. Subject to the terms and conditions of this Public License,
|
147 |
+
the Licensor hereby grants You a worldwide, royalty-free,
|
148 |
+
non-sublicensable, non-exclusive, irrevocable license to
|
149 |
+
exercise the Licensed Rights in the Licensed Material to:
|
150 |
+
|
151 |
+
a. reproduce and Share the Licensed Material, in whole or
|
152 |
+
in part, for NonCommercial purposes only; and
|
153 |
+
|
154 |
+
b. produce, reproduce, and Share Adapted Material for
|
155 |
+
NonCommercial purposes only.
|
156 |
+
|
157 |
+
2. Exceptions and Limitations. For the avoidance of doubt, where
|
158 |
+
Exceptions and Limitations apply to Your use, this Public
|
159 |
+
License does not apply, and You do not need to comply with
|
160 |
+
its terms and conditions.
|
161 |
+
|
162 |
+
3. Term. The term of this Public License is specified in Section
|
163 |
+
6(a).
|
164 |
+
|
165 |
+
4. Media and formats; technical modifications allowed. The
|
166 |
+
Licensor authorizes You to exercise the Licensed Rights in
|
167 |
+
all media and formats whether now known or hereafter created,
|
168 |
+
and to make technical modifications necessary to do so. The
|
169 |
+
Licensor waives and/or agrees not to assert any right or
|
170 |
+
authority to forbid You from making technical modifications
|
171 |
+
necessary to exercise the Licensed Rights, including
|
172 |
+
technical modifications necessary to circumvent Effective
|
173 |
+
Technological Measures. For purposes of this Public License,
|
174 |
+
simply making modifications authorized by this Section 2(a)
|
175 |
+
(4) never produces Adapted Material.
|
176 |
+
|
177 |
+
5. Downstream recipients.
|
178 |
+
|
179 |
+
a. Offer from the Licensor -- Licensed Material. Every
|
180 |
+
recipient of the Licensed Material automatically
|
181 |
+
receives an offer from the Licensor to exercise the
|
182 |
+
Licensed Rights under the terms and conditions of this
|
183 |
+
Public License.
|
184 |
+
|
185 |
+
b. No downstream restrictions. You may not offer or impose
|
186 |
+
any additional or different terms or conditions on, or
|
187 |
+
apply any Effective Technological Measures to, the
|
188 |
+
Licensed Material if doing so restricts exercise of the
|
189 |
+
Licensed Rights by any recipient of the Licensed
|
190 |
+
Material.
|
191 |
+
|
192 |
+
6. No endorsement. Nothing in this Public License constitutes or
|
193 |
+
may be construed as permission to assert or imply that You
|
194 |
+
are, or that Your use of the Licensed Material is, connected
|
195 |
+
with, or sponsored, endorsed, or granted official status by,
|
196 |
+
the Licensor or others designated to receive attribution as
|
197 |
+
provided in Section 3(a)(1)(A)(i).
|
198 |
+
|
199 |
+
b. Other rights.
|
200 |
+
|
201 |
+
1. Moral rights, such as the right of integrity, are not
|
202 |
+
licensed under this Public License, nor are publicity,
|
203 |
+
privacy, and/or other similar personality rights; however, to
|
204 |
+
the extent possible, the Licensor waives and/or agrees not to
|
205 |
+
assert any such rights held by the Licensor to the limited
|
206 |
+
extent necessary to allow You to exercise the Licensed
|
207 |
+
Rights, but not otherwise.
|
208 |
+
|
209 |
+
2. Patent and trademark rights are not licensed under this
|
210 |
+
Public License.
|
211 |
+
|
212 |
+
3. To the extent possible, the Licensor waives any right to
|
213 |
+
collect royalties from You for the exercise of the Licensed
|
214 |
+
Rights, whether directly or through a collecting society
|
215 |
+
under any voluntary or waivable statutory or compulsory
|
216 |
+
licensing scheme. In all other cases the Licensor expressly
|
217 |
+
reserves any right to collect such royalties, including when
|
218 |
+
the Licensed Material is used other than for NonCommercial
|
219 |
+
purposes.
|
220 |
+
|
221 |
+
|
222 |
+
Section 3 -- License Conditions.
|
223 |
+
|
224 |
+
Your exercise of the Licensed Rights is expressly made subject to the
|
225 |
+
following conditions.
|
226 |
+
|
227 |
+
a. Attribution.
|
228 |
+
|
229 |
+
1. If You Share the Licensed Material (including in modified
|
230 |
+
form), You must:
|
231 |
+
|
232 |
+
a. retain the following if it is supplied by the Licensor
|
233 |
+
with the Licensed Material:
|
234 |
+
|
235 |
+
i. identification of the creator(s) of the Licensed
|
236 |
+
Material and any others designated to receive
|
237 |
+
attribution, in any reasonable manner requested by
|
238 |
+
the Licensor (including by pseudonym if
|
239 |
+
designated);
|
240 |
+
|
241 |
+
ii. a copyright notice;
|
242 |
+
|
243 |
+
iii. a notice that refers to this Public License;
|
244 |
+
|
245 |
+
iv. a notice that refers to the disclaimer of
|
246 |
+
warranties;
|
247 |
+
|
248 |
+
v. a URI or hyperlink to the Licensed Material to the
|
249 |
+
extent reasonably practicable;
|
250 |
+
|
251 |
+
b. indicate if You modified the Licensed Material and
|
252 |
+
retain an indication of any previous modifications; and
|
253 |
+
|
254 |
+
c. indicate the Licensed Material is licensed under this
|
255 |
+
Public License, and include the text of, or the URI or
|
256 |
+
hyperlink to, this Public License.
|
257 |
+
|
258 |
+
2. You may satisfy the conditions in Section 3(a)(1) in any
|
259 |
+
reasonable manner based on the medium, means, and context in
|
260 |
+
which You Share the Licensed Material. For example, it may be
|
261 |
+
reasonable to satisfy the conditions by providing a URI or
|
262 |
+
hyperlink to a resource that includes the required
|
263 |
+
information.
|
264 |
+
|
265 |
+
3. If requested by the Licensor, You must remove any of the
|
266 |
+
information required by Section 3(a)(1)(A) to the extent
|
267 |
+
reasonably practicable.
|
268 |
+
|
269 |
+
4. If You Share Adapted Material You produce, the Adapter's
|
270 |
+
License You apply must not prevent recipients of the Adapted
|
271 |
+
Material from complying with this Public License.
|
272 |
+
|
273 |
+
|
274 |
+
Section 4 -- Sui Generis Database Rights.
|
275 |
+
|
276 |
+
Where the Licensed Rights include Sui Generis Database Rights that
|
277 |
+
apply to Your use of the Licensed Material:
|
278 |
+
|
279 |
+
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
280 |
+
to extract, reuse, reproduce, and Share all or a substantial
|
281 |
+
portion of the contents of the database for NonCommercial purposes
|
282 |
+
only;
|
283 |
+
|
284 |
+
b. if You include all or a substantial portion of the database
|
285 |
+
contents in a database in which You have Sui Generis Database
|
286 |
+
Rights, then the database in which You have Sui Generis Database
|
287 |
+
Rights (but not its individual contents) is Adapted Material; and
|
288 |
+
|
289 |
+
c. You must comply with the conditions in Section 3(a) if You Share
|
290 |
+
all or a substantial portion of the contents of the database.
|
291 |
+
|
292 |
+
For the avoidance of doubt, this Section 4 supplements and does not
|
293 |
+
replace Your obligations under this Public License where the Licensed
|
294 |
+
Rights include other Copyright and Similar Rights.
|
295 |
+
|
296 |
+
|
297 |
+
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
298 |
+
|
299 |
+
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
300 |
+
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
301 |
+
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
302 |
+
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
303 |
+
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
304 |
+
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
305 |
+
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
306 |
+
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
307 |
+
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
308 |
+
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
309 |
+
|
310 |
+
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
311 |
+
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
312 |
+
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
313 |
+
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
314 |
+
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
315 |
+
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
316 |
+
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
317 |
+
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
318 |
+
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
319 |
+
|
320 |
+
c. The disclaimer of warranties and limitation of liability provided
|
321 |
+
above shall be interpreted in a manner that, to the extent
|
322 |
+
possible, most closely approximates an absolute disclaimer and
|
323 |
+
waiver of all liability.
|
324 |
+
|
325 |
+
|
326 |
+
Section 6 -- Term and Termination.
|
327 |
+
|
328 |
+
a. This Public License applies for the term of the Copyright and
|
329 |
+
Similar Rights licensed here. However, if You fail to comply with
|
330 |
+
this Public License, then Your rights under this Public License
|
331 |
+
terminate automatically.
|
332 |
+
|
333 |
+
b. Where Your right to use the Licensed Material has terminated under
|
334 |
+
Section 6(a), it reinstates:
|
335 |
+
|
336 |
+
1. automatically as of the date the violation is cured, provided
|
337 |
+
it is cured within 30 days of Your discovery of the
|
338 |
+
violation; or
|
339 |
+
|
340 |
+
2. upon express reinstatement by the Licensor.
|
341 |
+
|
342 |
+
For the avoidance of doubt, this Section 6(b) does not affect any
|
343 |
+
right the Licensor may have to seek remedies for Your violations
|
344 |
+
of this Public License.
|
345 |
+
|
346 |
+
c. For the avoidance of doubt, the Licensor may also offer the
|
347 |
+
Licensed Material under separate terms or conditions or stop
|
348 |
+
distributing the Licensed Material at any time; however, doing so
|
349 |
+
will not terminate this Public License.
|
350 |
+
|
351 |
+
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
352 |
+
License.
|
353 |
+
|
354 |
+
|
355 |
+
Section 7 -- Other Terms and Conditions.
|
356 |
+
|
357 |
+
a. The Licensor shall not be bound by any additional or different
|
358 |
+
terms or conditions communicated by You unless expressly agreed.
|
359 |
+
|
360 |
+
b. Any arrangements, understandings, or agreements regarding the
|
361 |
+
Licensed Material not stated herein are separate from and
|
362 |
+
independent of the terms and conditions of this Public License.
|
363 |
+
|
364 |
+
|
365 |
+
Section 8 -- Interpretation.
|
366 |
+
|
367 |
+
a. For the avoidance of doubt, this Public License does not, and
|
368 |
+
shall not be interpreted to, reduce, limit, restrict, or impose
|
369 |
+
conditions on any use of the Licensed Material that could lawfully
|
370 |
+
be made without permission under this Public License.
|
371 |
+
|
372 |
+
b. To the extent possible, if any provision of this Public License is
|
373 |
+
deemed unenforceable, it shall be automatically reformed to the
|
374 |
+
minimum extent necessary to make it enforceable. If the provision
|
375 |
+
cannot be reformed, it shall be severed from this Public License
|
376 |
+
without affecting the enforceability of the remaining terms and
|
377 |
+
conditions.
|
378 |
+
|
379 |
+
c. No term or condition of this Public License will be waived and no
|
380 |
+
failure to comply consented to unless expressly agreed to by the
|
381 |
+
Licensor.
|
382 |
+
|
383 |
+
d. Nothing in this Public License constitutes or may be interpreted
|
384 |
+
as a limitation upon, or waiver of, any privileges and immunities
|
385 |
+
that apply to the Licensor or You, including from the legal
|
386 |
+
processes of any jurisdiction or authority.
|
387 |
+
|
388 |
+
=======================================================================
|
389 |
+
|
390 |
+
Creative Commons is not a party to its public
|
391 |
+
licenses. Notwithstanding, Creative Commons may elect to apply one of
|
392 |
+
its public licenses to material it publishes and in those instances
|
393 |
+
will be considered the “Licensor.” The text of the Creative Commons
|
394 |
+
public licenses is dedicated to the public domain under the CC0 Public
|
395 |
+
Domain Dedication. Except for the limited purpose of indicating that
|
396 |
+
material is shared under a Creative Commons public license or as
|
397 |
+
otherwise permitted by the Creative Commons policies published at
|
398 |
+
creativecommons.org/policies, Creative Commons does not authorize the
|
399 |
+
use of the trademark "Creative Commons" or any other trademark or logo
|
400 |
+
of Creative Commons without its prior written consent including,
|
401 |
+
without limitation, in connection with any unauthorized modifications
|
402 |
+
to any of its public licenses or any other arrangements,
|
403 |
+
understandings, or agreements concerning use of licensed material. For
|
404 |
+
the avoidance of doubt, this paragraph does not form part of the
|
405 |
+
public licenses.
|
406 |
+
|
407 |
+
Creative Commons may be contacted at creativecommons.org.
|
README.md
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Sovits Models
|
3 |
+
emoji: 🎙️
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: pink
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.18.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
duplicated_from: sayashi/sovits-models
|
12 |
+
---
|
app.py
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
import librosa
|
4 |
+
import numpy as np
|
5 |
+
import utils
|
6 |
+
from inference.infer_tool import Svc
|
7 |
+
import logging
|
8 |
+
import webbrowser
|
9 |
+
import argparse
|
10 |
+
import gradio.processing_utils as gr_processing_utils
|
11 |
+
logging.getLogger('numba').setLevel(logging.WARNING)
|
12 |
+
logging.getLogger('markdown_it').setLevel(logging.WARNING)
|
13 |
+
logging.getLogger('urllib3').setLevel(logging.WARNING)
|
14 |
+
logging.getLogger('matplotlib').setLevel(logging.WARNING)
|
15 |
+
|
16 |
+
limitation = os.getenv("SYSTEM") == "spaces" # limit audio length in huggingface spaces
|
17 |
+
|
18 |
+
audio_postprocess_ori = gr.Audio.postprocess
|
19 |
+
|
20 |
+
def audio_postprocess(self, y):
|
21 |
+
data = audio_postprocess_ori(self, y)
|
22 |
+
if data is None:
|
23 |
+
return None
|
24 |
+
return gr_processing_utils.encode_url_or_file_to_base64(data["name"])
|
25 |
+
|
26 |
+
|
27 |
+
gr.Audio.postprocess = audio_postprocess
|
28 |
+
def create_vc_fn(model, sid):
|
29 |
+
def vc_fn(input_audio, vc_transform, auto_f0):
|
30 |
+
if input_audio is None:
|
31 |
+
return "You need to upload an audio", None
|
32 |
+
sampling_rate, audio = input_audio
|
33 |
+
duration = audio.shape[0] / sampling_rate
|
34 |
+
if duration > 30 and limitation:
|
35 |
+
return "Please upload an audio file that is less than 30 seconds. If you need to generate a longer audio file, please use Colab.", None
|
36 |
+
audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
|
37 |
+
if len(audio.shape) > 1:
|
38 |
+
audio = librosa.to_mono(audio.transpose(1, 0))
|
39 |
+
if sampling_rate != 44100:
|
40 |
+
audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=44100)
|
41 |
+
out_audio, out_sr = model.infer(sid, vc_transform, audio, auto_predict_f0=auto_f0)
|
42 |
+
model.clear_empty()
|
43 |
+
return "Success", (44100, out_audio.cpu().numpy())
|
44 |
+
return vc_fn
|
45 |
+
|
46 |
+
if __name__ == '__main__':
|
47 |
+
parser = argparse.ArgumentParser()
|
48 |
+
parser.add_argument('--device', type=str, default='cpu')
|
49 |
+
parser.add_argument('--api', action="store_true", default=False)
|
50 |
+
parser.add_argument("--share", action="store_true", default=False, help="share gradio app")
|
51 |
+
parser.add_argument("--colab", action="store_true", default=False, help="share gradio app")
|
52 |
+
args = parser.parse_args()
|
53 |
+
hubert_model = utils.get_hubert_model().to(args.device)
|
54 |
+
models = []
|
55 |
+
for f in os.listdir("models"):
|
56 |
+
name = f
|
57 |
+
model = Svc(fr"models/{f}/{f}.pth", f"models/{f}/config.json", device=args.device, hubert_model=hubert_model)
|
58 |
+
cover = f"models/{f}/cover.png" if os.path.exists(f"models/{f}/cover.png") else None
|
59 |
+
models.append((name, cover, create_vc_fn(model, name)))
|
60 |
+
with gr.Blocks() as app:
|
61 |
+
gr.Markdown(
|
62 |
+
"# <center> Sovits Models\n"
|
63 |
+
"## <center> The input audio should be clean and pure voice without background music.\n"
|
64 |
+
"\n\n"
|
65 |
+
"[Open In Colab](https://colab.research.google.com/drive/1wfsBbMzmtLflOJeqc5ZnJiLY7L239hJW?usp=share_link)"
|
66 |
+
" without queue and length limitation.\n\n"
|
67 |
+
"[Original Repo](https://github.com/innnky/so-vits-svc/tree/4.0)"
|
68 |
+
)
|
69 |
+
with gr.Tabs():
|
70 |
+
for (name, cover, vc_fn) in models:
|
71 |
+
with gr.TabItem(name):
|
72 |
+
with gr.Row():
|
73 |
+
gr.Markdown(
|
74 |
+
'<div align="center">'
|
75 |
+
f'<img style="width:auto;height:300px;" src="file/{cover}">' if cover else ""
|
76 |
+
'</div>'
|
77 |
+
)
|
78 |
+
with gr.Row():
|
79 |
+
with gr.Column():
|
80 |
+
vc_input = gr.Audio(label="Input audio"+' (less than 45 seconds)' if limitation else '')
|
81 |
+
vc_transform = gr.Number(label="vc_transform", value=0)
|
82 |
+
auto_f0 = gr.Checkbox(label="auto_f0", value=False)
|
83 |
+
vc_submit = gr.Button("Generate", variant="primary")
|
84 |
+
with gr.Column():
|
85 |
+
vc_output1 = gr.Textbox(label="Output Message")
|
86 |
+
vc_output2 = gr.Audio(label="Output Audio")
|
87 |
+
vc_submit.click(vc_fn, [vc_input, vc_transform, auto_f0], [vc_output1, vc_output2])
|
88 |
+
if args.colab:
|
89 |
+
webbrowser.open("http://127.0.0.1:7860")
|
90 |
+
app.queue(concurrency_count=1, api_open=args.api).launch(share=args.share)
|
cluster/__init__.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import torch
|
3 |
+
from sklearn.cluster import KMeans
|
4 |
+
|
5 |
+
def get_cluster_model(ckpt_path):
|
6 |
+
checkpoint = torch.load(ckpt_path)
|
7 |
+
kmeans_dict = {}
|
8 |
+
for spk, ckpt in checkpoint.items():
|
9 |
+
km = KMeans(ckpt["n_features_in_"])
|
10 |
+
km.__dict__["n_features_in_"] = ckpt["n_features_in_"]
|
11 |
+
km.__dict__["_n_threads"] = ckpt["_n_threads"]
|
12 |
+
km.__dict__["cluster_centers_"] = ckpt["cluster_centers_"]
|
13 |
+
kmeans_dict[spk] = km
|
14 |
+
return kmeans_dict
|
15 |
+
|
16 |
+
def get_cluster_result(model, x, speaker):
|
17 |
+
"""
|
18 |
+
x: np.array [t, 256]
|
19 |
+
return cluster class result
|
20 |
+
"""
|
21 |
+
return model[speaker].predict(x)
|
22 |
+
|
23 |
+
def get_cluster_center_result(model, x,speaker):
|
24 |
+
"""x: np.array [t, 256]"""
|
25 |
+
predict = model[speaker].predict(x)
|
26 |
+
return model[speaker].cluster_centers_[predict]
|
27 |
+
|
28 |
+
def get_center(model, x,speaker):
|
29 |
+
return model[speaker].cluster_centers_[x]
|
cluster/__pycache__/__init__.cpython-38.pyc
ADDED
Binary file (1.09 kB). View file
|
|
cluster/train_cluster.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from glob import glob
|
3 |
+
from pathlib import Path
|
4 |
+
import torch
|
5 |
+
import logging
|
6 |
+
import argparse
|
7 |
+
import torch
|
8 |
+
import numpy as np
|
9 |
+
from sklearn.cluster import KMeans, MiniBatchKMeans
|
10 |
+
import tqdm
|
11 |
+
logging.basicConfig(level=logging.INFO)
|
12 |
+
logger = logging.getLogger(__name__)
|
13 |
+
import time
|
14 |
+
import random
|
15 |
+
|
16 |
+
def train_cluster(in_dir, n_clusters, use_minibatch=True, verbose=False):
|
17 |
+
|
18 |
+
logger.info(f"Loading features from {in_dir}")
|
19 |
+
features = []
|
20 |
+
nums = 0
|
21 |
+
for path in tqdm.tqdm(in_dir.glob("*.soft.pt")):
|
22 |
+
features.append(torch.load(path).squeeze(0).numpy().T)
|
23 |
+
# print(features[-1].shape)
|
24 |
+
features = np.concatenate(features, axis=0)
|
25 |
+
print(nums, features.nbytes/ 1024**2, "MB , shape:",features.shape, features.dtype)
|
26 |
+
features = features.astype(np.float32)
|
27 |
+
logger.info(f"Clustering features of shape: {features.shape}")
|
28 |
+
t = time.time()
|
29 |
+
if use_minibatch:
|
30 |
+
kmeans = MiniBatchKMeans(n_clusters=n_clusters,verbose=verbose, batch_size=4096, max_iter=80).fit(features)
|
31 |
+
else:
|
32 |
+
kmeans = KMeans(n_clusters=n_clusters,verbose=verbose).fit(features)
|
33 |
+
print(time.time()-t, "s")
|
34 |
+
|
35 |
+
x = {
|
36 |
+
"n_features_in_": kmeans.n_features_in_,
|
37 |
+
"_n_threads": kmeans._n_threads,
|
38 |
+
"cluster_centers_": kmeans.cluster_centers_,
|
39 |
+
}
|
40 |
+
print("end")
|
41 |
+
|
42 |
+
return x
|
43 |
+
|
44 |
+
|
45 |
+
if __name__ == "__main__":
|
46 |
+
|
47 |
+
parser = argparse.ArgumentParser()
|
48 |
+
parser.add_argument('--dataset', type=Path, default="./dataset/44k",
|
49 |
+
help='path of training data directory')
|
50 |
+
parser.add_argument('--output', type=Path, default="logs/44k",
|
51 |
+
help='path of model output directory')
|
52 |
+
|
53 |
+
args = parser.parse_args()
|
54 |
+
|
55 |
+
checkpoint_dir = args.output
|
56 |
+
dataset = args.dataset
|
57 |
+
n_clusters = 10000
|
58 |
+
|
59 |
+
ckpt = {}
|
60 |
+
for spk in os.listdir(dataset):
|
61 |
+
if os.path.isdir(dataset/spk):
|
62 |
+
print(f"train kmeans for {spk}...")
|
63 |
+
in_dir = dataset/spk
|
64 |
+
x = train_cluster(in_dir, n_clusters, verbose=False)
|
65 |
+
ckpt[spk] = x
|
66 |
+
|
67 |
+
checkpoint_path = checkpoint_dir / f"kmeans_{n_clusters}.pt"
|
68 |
+
checkpoint_path.parent.mkdir(exist_ok=True, parents=True)
|
69 |
+
torch.save(
|
70 |
+
ckpt,
|
71 |
+
checkpoint_path,
|
72 |
+
)
|
73 |
+
|
74 |
+
|
75 |
+
# import cluster
|
76 |
+
# for spk in tqdm.tqdm(os.listdir("dataset")):
|
77 |
+
# if os.path.isdir(f"dataset/{spk}"):
|
78 |
+
# print(f"start kmeans inference for {spk}...")
|
79 |
+
# for feature_path in tqdm.tqdm(glob(f"dataset/{spk}/*.discrete.npy", recursive=True)):
|
80 |
+
# mel_path = feature_path.replace(".discrete.npy",".mel.npy")
|
81 |
+
# mel_spectrogram = np.load(mel_path)
|
82 |
+
# feature_len = mel_spectrogram.shape[-1]
|
83 |
+
# c = np.load(feature_path)
|
84 |
+
# c = utils.tools.repeat_expand_2d(torch.FloatTensor(c), feature_len).numpy()
|
85 |
+
# feature = c.T
|
86 |
+
# feature_class = cluster.get_cluster_result(feature, spk)
|
87 |
+
# np.save(feature_path.replace(".discrete.npy", ".discrete_class.npy"), feature_class)
|
88 |
+
|
89 |
+
|
configs/config.json
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"train": {
|
3 |
+
"log_interval": 200,
|
4 |
+
"eval_interval": 800,
|
5 |
+
"seed": 1234,
|
6 |
+
"epochs": 10000,
|
7 |
+
"learning_rate": 0.0001,
|
8 |
+
"betas": [
|
9 |
+
0.8,
|
10 |
+
0.99
|
11 |
+
],
|
12 |
+
"eps": 1e-09,
|
13 |
+
"batch_size": 6,
|
14 |
+
"fp16_run": false,
|
15 |
+
"lr_decay": 0.999875,
|
16 |
+
"segment_size": 10240,
|
17 |
+
"init_lr_ratio": 1,
|
18 |
+
"warmup_epochs": 0,
|
19 |
+
"c_mel": 45,
|
20 |
+
"c_kl": 1.0,
|
21 |
+
"use_sr": true,
|
22 |
+
"max_speclen": 512,
|
23 |
+
"port": "8001"
|
24 |
+
},
|
25 |
+
"data": {
|
26 |
+
"training_files": "filelists/train.txt",
|
27 |
+
"validation_files": "filelists/val.txt",
|
28 |
+
"max_wav_value": 32768.0,
|
29 |
+
"sampling_rate": 44100,
|
30 |
+
"filter_length": 2048,
|
31 |
+
"hop_length": 512,
|
32 |
+
"win_length": 2048,
|
33 |
+
"n_mel_channels": 80,
|
34 |
+
"mel_fmin": 0.0,
|
35 |
+
"mel_fmax": 22050
|
36 |
+
},
|
37 |
+
"model": {
|
38 |
+
"inter_channels": 192,
|
39 |
+
"hidden_channels": 192,
|
40 |
+
"filter_channels": 768,
|
41 |
+
"n_heads": 2,
|
42 |
+
"n_layers": 6,
|
43 |
+
"kernel_size": 3,
|
44 |
+
"p_dropout": 0.1,
|
45 |
+
"resblock": "1",
|
46 |
+
"resblock_kernel_sizes": [3,7,11],
|
47 |
+
"resblock_dilation_sizes": [[1,3,5], [1,3,5], [1,3,5]],
|
48 |
+
"upsample_rates": [ 8, 8, 2, 2, 2],
|
49 |
+
"upsample_initial_channel": 512,
|
50 |
+
"upsample_kernel_sizes": [16,16, 4, 4, 4],
|
51 |
+
"n_layers_q": 3,
|
52 |
+
"use_spectral_norm": false,
|
53 |
+
"gin_channels": 256,
|
54 |
+
"ssl_dim": 256,
|
55 |
+
"n_speakers": 200
|
56 |
+
},
|
57 |
+
"spk": {
|
58 |
+
"jishuang": 0,
|
59 |
+
"huiyu": 1,
|
60 |
+
"nen": 2,
|
61 |
+
"paimon": 3,
|
62 |
+
"yunhao": 4
|
63 |
+
}
|
64 |
+
}
|
cvec/checkpoint_best_legacy_500.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:294a2e8c98136070a999e040ec98dfa5a99b88a7938181c56cc2ab0e2f6ce0e8
|
3 |
+
size 48501067
|
hubert/__init__.py
ADDED
File without changes
|
hubert/__pycache__/__init__.cpython-38.pyc
ADDED
Binary file (134 Bytes). View file
|
|
hubert/__pycache__/hubert_model.cpython-38.pyc
ADDED
Binary file (7.58 kB). View file
|
|
hubert/checkpoint_best_legacy_500.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:60d936ec5a566776fc392e69ad8b630d14eb588111233fe313436e200a7b187b
|
3 |
+
size 1330114945
|
hubert/hubert_model.py
ADDED
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import copy
|
2 |
+
import random
|
3 |
+
from typing import Optional, Tuple
|
4 |
+
|
5 |
+
import torch
|
6 |
+
import torch.nn as nn
|
7 |
+
import torch.nn.functional as t_func
|
8 |
+
from torch.nn.modules.utils import consume_prefix_in_state_dict_if_present
|
9 |
+
|
10 |
+
|
11 |
+
class Hubert(nn.Module):
|
12 |
+
def __init__(self, num_label_embeddings: int = 100, mask: bool = True):
|
13 |
+
super().__init__()
|
14 |
+
self._mask = mask
|
15 |
+
self.feature_extractor = FeatureExtractor()
|
16 |
+
self.feature_projection = FeatureProjection()
|
17 |
+
self.positional_embedding = PositionalConvEmbedding()
|
18 |
+
self.norm = nn.LayerNorm(768)
|
19 |
+
self.dropout = nn.Dropout(0.1)
|
20 |
+
self.encoder = TransformerEncoder(
|
21 |
+
nn.TransformerEncoderLayer(
|
22 |
+
768, 12, 3072, activation="gelu", batch_first=True
|
23 |
+
),
|
24 |
+
12,
|
25 |
+
)
|
26 |
+
self.proj = nn.Linear(768, 256)
|
27 |
+
|
28 |
+
self.masked_spec_embed = nn.Parameter(torch.FloatTensor(768).uniform_())
|
29 |
+
self.label_embedding = nn.Embedding(num_label_embeddings, 256)
|
30 |
+
|
31 |
+
def mask(self, x: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
|
32 |
+
mask = None
|
33 |
+
if self.training and self._mask:
|
34 |
+
mask = _compute_mask((x.size(0), x.size(1)), 0.8, 10, x.device, 2)
|
35 |
+
x[mask] = self.masked_spec_embed.to(x.dtype)
|
36 |
+
return x, mask
|
37 |
+
|
38 |
+
def encode(
|
39 |
+
self, x: torch.Tensor, layer: Optional[int] = None
|
40 |
+
) -> Tuple[torch.Tensor, torch.Tensor]:
|
41 |
+
x = self.feature_extractor(x)
|
42 |
+
x = self.feature_projection(x.transpose(1, 2))
|
43 |
+
x, mask = self.mask(x)
|
44 |
+
x = x + self.positional_embedding(x)
|
45 |
+
x = self.dropout(self.norm(x))
|
46 |
+
x = self.encoder(x, output_layer=layer)
|
47 |
+
return x, mask
|
48 |
+
|
49 |
+
def logits(self, x: torch.Tensor) -> torch.Tensor:
|
50 |
+
logits = torch.cosine_similarity(
|
51 |
+
x.unsqueeze(2),
|
52 |
+
self.label_embedding.weight.unsqueeze(0).unsqueeze(0),
|
53 |
+
dim=-1,
|
54 |
+
)
|
55 |
+
return logits / 0.1
|
56 |
+
|
57 |
+
def forward(self, x: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
|
58 |
+
x, mask = self.encode(x)
|
59 |
+
x = self.proj(x)
|
60 |
+
logits = self.logits(x)
|
61 |
+
return logits, mask
|
62 |
+
|
63 |
+
|
64 |
+
class HubertSoft(Hubert):
|
65 |
+
def __init__(self):
|
66 |
+
super().__init__()
|
67 |
+
|
68 |
+
@torch.inference_mode()
|
69 |
+
def units(self, wav: torch.Tensor) -> torch.Tensor:
|
70 |
+
wav = t_func.pad(wav, ((400 - 320) // 2, (400 - 320) // 2))
|
71 |
+
x, _ = self.encode(wav)
|
72 |
+
return self.proj(x)
|
73 |
+
|
74 |
+
|
75 |
+
class FeatureExtractor(nn.Module):
|
76 |
+
def __init__(self):
|
77 |
+
super().__init__()
|
78 |
+
self.conv0 = nn.Conv1d(1, 512, 10, 5, bias=False)
|
79 |
+
self.norm0 = nn.GroupNorm(512, 512)
|
80 |
+
self.conv1 = nn.Conv1d(512, 512, 3, 2, bias=False)
|
81 |
+
self.conv2 = nn.Conv1d(512, 512, 3, 2, bias=False)
|
82 |
+
self.conv3 = nn.Conv1d(512, 512, 3, 2, bias=False)
|
83 |
+
self.conv4 = nn.Conv1d(512, 512, 3, 2, bias=False)
|
84 |
+
self.conv5 = nn.Conv1d(512, 512, 2, 2, bias=False)
|
85 |
+
self.conv6 = nn.Conv1d(512, 512, 2, 2, bias=False)
|
86 |
+
|
87 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
88 |
+
x = t_func.gelu(self.norm0(self.conv0(x)))
|
89 |
+
x = t_func.gelu(self.conv1(x))
|
90 |
+
x = t_func.gelu(self.conv2(x))
|
91 |
+
x = t_func.gelu(self.conv3(x))
|
92 |
+
x = t_func.gelu(self.conv4(x))
|
93 |
+
x = t_func.gelu(self.conv5(x))
|
94 |
+
x = t_func.gelu(self.conv6(x))
|
95 |
+
return x
|
96 |
+
|
97 |
+
|
98 |
+
class FeatureProjection(nn.Module):
|
99 |
+
def __init__(self):
|
100 |
+
super().__init__()
|
101 |
+
self.norm = nn.LayerNorm(512)
|
102 |
+
self.projection = nn.Linear(512, 768)
|
103 |
+
self.dropout = nn.Dropout(0.1)
|
104 |
+
|
105 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
106 |
+
x = self.norm(x)
|
107 |
+
x = self.projection(x)
|
108 |
+
x = self.dropout(x)
|
109 |
+
return x
|
110 |
+
|
111 |
+
|
112 |
+
class PositionalConvEmbedding(nn.Module):
|
113 |
+
def __init__(self):
|
114 |
+
super().__init__()
|
115 |
+
self.conv = nn.Conv1d(
|
116 |
+
768,
|
117 |
+
768,
|
118 |
+
kernel_size=128,
|
119 |
+
padding=128 // 2,
|
120 |
+
groups=16,
|
121 |
+
)
|
122 |
+
self.conv = nn.utils.weight_norm(self.conv, name="weight", dim=2)
|
123 |
+
|
124 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
125 |
+
x = self.conv(x.transpose(1, 2))
|
126 |
+
x = t_func.gelu(x[:, :, :-1])
|
127 |
+
return x.transpose(1, 2)
|
128 |
+
|
129 |
+
|
130 |
+
class TransformerEncoder(nn.Module):
|
131 |
+
def __init__(
|
132 |
+
self, encoder_layer: nn.TransformerEncoderLayer, num_layers: int
|
133 |
+
) -> None:
|
134 |
+
super(TransformerEncoder, self).__init__()
|
135 |
+
self.layers = nn.ModuleList(
|
136 |
+
[copy.deepcopy(encoder_layer) for _ in range(num_layers)]
|
137 |
+
)
|
138 |
+
self.num_layers = num_layers
|
139 |
+
|
140 |
+
def forward(
|
141 |
+
self,
|
142 |
+
src: torch.Tensor,
|
143 |
+
mask: torch.Tensor = None,
|
144 |
+
src_key_padding_mask: torch.Tensor = None,
|
145 |
+
output_layer: Optional[int] = None,
|
146 |
+
) -> torch.Tensor:
|
147 |
+
output = src
|
148 |
+
for layer in self.layers[:output_layer]:
|
149 |
+
output = layer(
|
150 |
+
output, src_mask=mask, src_key_padding_mask=src_key_padding_mask
|
151 |
+
)
|
152 |
+
return output
|
153 |
+
|
154 |
+
|
155 |
+
def _compute_mask(
|
156 |
+
shape: Tuple[int, int],
|
157 |
+
mask_prob: float,
|
158 |
+
mask_length: int,
|
159 |
+
device: torch.device,
|
160 |
+
min_masks: int = 0,
|
161 |
+
) -> torch.Tensor:
|
162 |
+
batch_size, sequence_length = shape
|
163 |
+
|
164 |
+
if mask_length < 1:
|
165 |
+
raise ValueError("`mask_length` has to be bigger than 0.")
|
166 |
+
|
167 |
+
if mask_length > sequence_length:
|
168 |
+
raise ValueError(
|
169 |
+
f"`mask_length` has to be smaller than `sequence_length`, but got `mask_length`: {mask_length} and `sequence_length`: {sequence_length}`"
|
170 |
+
)
|
171 |
+
|
172 |
+
# compute number of masked spans in batch
|
173 |
+
num_masked_spans = int(mask_prob * sequence_length / mask_length + random.random())
|
174 |
+
num_masked_spans = max(num_masked_spans, min_masks)
|
175 |
+
|
176 |
+
# make sure num masked indices <= sequence_length
|
177 |
+
if num_masked_spans * mask_length > sequence_length:
|
178 |
+
num_masked_spans = sequence_length // mask_length
|
179 |
+
|
180 |
+
# SpecAugment mask to fill
|
181 |
+
mask = torch.zeros((batch_size, sequence_length), device=device, dtype=torch.bool)
|
182 |
+
|
183 |
+
# uniform distribution to sample from, make sure that offset samples are < sequence_length
|
184 |
+
uniform_dist = torch.ones(
|
185 |
+
(batch_size, sequence_length - (mask_length - 1)), device=device
|
186 |
+
)
|
187 |
+
|
188 |
+
# get random indices to mask
|
189 |
+
mask_indices = torch.multinomial(uniform_dist, num_masked_spans)
|
190 |
+
|
191 |
+
# expand masked indices to masked spans
|
192 |
+
mask_indices = (
|
193 |
+
mask_indices.unsqueeze(dim=-1)
|
194 |
+
.expand((batch_size, num_masked_spans, mask_length))
|
195 |
+
.reshape(batch_size, num_masked_spans * mask_length)
|
196 |
+
)
|
197 |
+
offsets = (
|
198 |
+
torch.arange(mask_length, device=device)[None, None, :]
|
199 |
+
.expand((batch_size, num_masked_spans, mask_length))
|
200 |
+
.reshape(batch_size, num_masked_spans * mask_length)
|
201 |
+
)
|
202 |
+
mask_idxs = mask_indices + offsets
|
203 |
+
|
204 |
+
# scatter indices to mask
|
205 |
+
mask = mask.scatter(1, mask_idxs, True)
|
206 |
+
|
207 |
+
return mask
|
208 |
+
|
209 |
+
|
210 |
+
def hubert_soft(
|
211 |
+
path: str,
|
212 |
+
) -> HubertSoft:
|
213 |
+
r"""HuBERT-Soft from `"A Comparison of Discrete and Soft Speech Units for Improved Voice Conversion"`.
|
214 |
+
Args:
|
215 |
+
path (str): path of a pretrained model
|
216 |
+
"""
|
217 |
+
hubert = HubertSoft()
|
218 |
+
checkpoint = torch.load(path)
|
219 |
+
consume_prefix_in_state_dict_if_present(checkpoint, "module.")
|
220 |
+
hubert.load_state_dict(checkpoint)
|
221 |
+
hubert.eval()
|
222 |
+
return hubert
|
hubert/hubert_model_onnx.py
ADDED
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import copy
|
2 |
+
import random
|
3 |
+
from typing import Optional, Tuple
|
4 |
+
|
5 |
+
import torch
|
6 |
+
import torch.nn as nn
|
7 |
+
import torch.nn.functional as t_func
|
8 |
+
from torch.nn.modules.utils import consume_prefix_in_state_dict_if_present
|
9 |
+
|
10 |
+
|
11 |
+
class Hubert(nn.Module):
|
12 |
+
def __init__(self, num_label_embeddings: int = 100, mask: bool = True):
|
13 |
+
super().__init__()
|
14 |
+
self._mask = mask
|
15 |
+
self.feature_extractor = FeatureExtractor()
|
16 |
+
self.feature_projection = FeatureProjection()
|
17 |
+
self.positional_embedding = PositionalConvEmbedding()
|
18 |
+
self.norm = nn.LayerNorm(768)
|
19 |
+
self.dropout = nn.Dropout(0.1)
|
20 |
+
self.encoder = TransformerEncoder(
|
21 |
+
nn.TransformerEncoderLayer(
|
22 |
+
768, 12, 3072, activation="gelu", batch_first=True
|
23 |
+
),
|
24 |
+
12,
|
25 |
+
)
|
26 |
+
self.proj = nn.Linear(768, 256)
|
27 |
+
|
28 |
+
self.masked_spec_embed = nn.Parameter(torch.FloatTensor(768).uniform_())
|
29 |
+
self.label_embedding = nn.Embedding(num_label_embeddings, 256)
|
30 |
+
|
31 |
+
def mask(self, x: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
|
32 |
+
mask = None
|
33 |
+
if self.training and self._mask:
|
34 |
+
mask = _compute_mask((x.size(0), x.size(1)), 0.8, 10, x.device, 2)
|
35 |
+
x[mask] = self.masked_spec_embed.to(x.dtype)
|
36 |
+
return x, mask
|
37 |
+
|
38 |
+
def encode(
|
39 |
+
self, x: torch.Tensor, layer: Optional[int] = None
|
40 |
+
) -> Tuple[torch.Tensor, torch.Tensor]:
|
41 |
+
x = self.feature_extractor(x)
|
42 |
+
x = self.feature_projection(x.transpose(1, 2))
|
43 |
+
x, mask = self.mask(x)
|
44 |
+
x = x + self.positional_embedding(x)
|
45 |
+
x = self.dropout(self.norm(x))
|
46 |
+
x = self.encoder(x, output_layer=layer)
|
47 |
+
return x, mask
|
48 |
+
|
49 |
+
def logits(self, x: torch.Tensor) -> torch.Tensor:
|
50 |
+
logits = torch.cosine_similarity(
|
51 |
+
x.unsqueeze(2),
|
52 |
+
self.label_embedding.weight.unsqueeze(0).unsqueeze(0),
|
53 |
+
dim=-1,
|
54 |
+
)
|
55 |
+
return logits / 0.1
|
56 |
+
|
57 |
+
|
58 |
+
class HubertSoft(Hubert):
|
59 |
+
def __init__(self):
|
60 |
+
super().__init__()
|
61 |
+
|
62 |
+
def units(self, wav: torch.Tensor) -> torch.Tensor:
|
63 |
+
wav = t_func.pad(wav, ((400 - 320) // 2, (400 - 320) // 2))
|
64 |
+
x, _ = self.encode(wav)
|
65 |
+
return self.proj(x)
|
66 |
+
|
67 |
+
def forward(self, x):
|
68 |
+
return self.units(x)
|
69 |
+
|
70 |
+
class FeatureExtractor(nn.Module):
|
71 |
+
def __init__(self):
|
72 |
+
super().__init__()
|
73 |
+
self.conv0 = nn.Conv1d(1, 512, 10, 5, bias=False)
|
74 |
+
self.norm0 = nn.GroupNorm(512, 512)
|
75 |
+
self.conv1 = nn.Conv1d(512, 512, 3, 2, bias=False)
|
76 |
+
self.conv2 = nn.Conv1d(512, 512, 3, 2, bias=False)
|
77 |
+
self.conv3 = nn.Conv1d(512, 512, 3, 2, bias=False)
|
78 |
+
self.conv4 = nn.Conv1d(512, 512, 3, 2, bias=False)
|
79 |
+
self.conv5 = nn.Conv1d(512, 512, 2, 2, bias=False)
|
80 |
+
self.conv6 = nn.Conv1d(512, 512, 2, 2, bias=False)
|
81 |
+
|
82 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
83 |
+
x = t_func.gelu(self.norm0(self.conv0(x)))
|
84 |
+
x = t_func.gelu(self.conv1(x))
|
85 |
+
x = t_func.gelu(self.conv2(x))
|
86 |
+
x = t_func.gelu(self.conv3(x))
|
87 |
+
x = t_func.gelu(self.conv4(x))
|
88 |
+
x = t_func.gelu(self.conv5(x))
|
89 |
+
x = t_func.gelu(self.conv6(x))
|
90 |
+
return x
|
91 |
+
|
92 |
+
|
93 |
+
class FeatureProjection(nn.Module):
|
94 |
+
def __init__(self):
|
95 |
+
super().__init__()
|
96 |
+
self.norm = nn.LayerNorm(512)
|
97 |
+
self.projection = nn.Linear(512, 768)
|
98 |
+
self.dropout = nn.Dropout(0.1)
|
99 |
+
|
100 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
101 |
+
x = self.norm(x)
|
102 |
+
x = self.projection(x)
|
103 |
+
x = self.dropout(x)
|
104 |
+
return x
|
105 |
+
|
106 |
+
|
107 |
+
class PositionalConvEmbedding(nn.Module):
|
108 |
+
def __init__(self):
|
109 |
+
super().__init__()
|
110 |
+
self.conv = nn.Conv1d(
|
111 |
+
768,
|
112 |
+
768,
|
113 |
+
kernel_size=128,
|
114 |
+
padding=128 // 2,
|
115 |
+
groups=16,
|
116 |
+
)
|
117 |
+
self.conv = nn.utils.weight_norm(self.conv, name="weight", dim=2)
|
118 |
+
|
119 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
120 |
+
x = self.conv(x.transpose(1, 2))
|
121 |
+
x = t_func.gelu(x[:, :, :-1])
|
122 |
+
return x.transpose(1, 2)
|
123 |
+
|
124 |
+
|
125 |
+
class TransformerEncoder(nn.Module):
|
126 |
+
def __init__(
|
127 |
+
self, encoder_layer: nn.TransformerEncoderLayer, num_layers: int
|
128 |
+
) -> None:
|
129 |
+
super(TransformerEncoder, self).__init__()
|
130 |
+
self.layers = nn.ModuleList(
|
131 |
+
[copy.deepcopy(encoder_layer) for _ in range(num_layers)]
|
132 |
+
)
|
133 |
+
self.num_layers = num_layers
|
134 |
+
|
135 |
+
def forward(
|
136 |
+
self,
|
137 |
+
src: torch.Tensor,
|
138 |
+
mask: torch.Tensor = None,
|
139 |
+
src_key_padding_mask: torch.Tensor = None,
|
140 |
+
output_layer: Optional[int] = None,
|
141 |
+
) -> torch.Tensor:
|
142 |
+
output = src
|
143 |
+
for layer in self.layers[:output_layer]:
|
144 |
+
output = layer(
|
145 |
+
output, src_mask=mask, src_key_padding_mask=src_key_padding_mask
|
146 |
+
)
|
147 |
+
return output
|
148 |
+
|
149 |
+
|
150 |
+
def _compute_mask(
|
151 |
+
shape: Tuple[int, int],
|
152 |
+
mask_prob: float,
|
153 |
+
mask_length: int,
|
154 |
+
device: torch.device,
|
155 |
+
min_masks: int = 0,
|
156 |
+
) -> torch.Tensor:
|
157 |
+
batch_size, sequence_length = shape
|
158 |
+
|
159 |
+
if mask_length < 1:
|
160 |
+
raise ValueError("`mask_length` has to be bigger than 0.")
|
161 |
+
|
162 |
+
if mask_length > sequence_length:
|
163 |
+
raise ValueError(
|
164 |
+
f"`mask_length` has to be smaller than `sequence_length`, but got `mask_length`: {mask_length} and `sequence_length`: {sequence_length}`"
|
165 |
+
)
|
166 |
+
|
167 |
+
# compute number of masked spans in batch
|
168 |
+
num_masked_spans = int(mask_prob * sequence_length / mask_length + random.random())
|
169 |
+
num_masked_spans = max(num_masked_spans, min_masks)
|
170 |
+
|
171 |
+
# make sure num masked indices <= sequence_length
|
172 |
+
if num_masked_spans * mask_length > sequence_length:
|
173 |
+
num_masked_spans = sequence_length // mask_length
|
174 |
+
|
175 |
+
# SpecAugment mask to fill
|
176 |
+
mask = torch.zeros((batch_size, sequence_length), device=device, dtype=torch.bool)
|
177 |
+
|
178 |
+
# uniform distribution to sample from, make sure that offset samples are < sequence_length
|
179 |
+
uniform_dist = torch.ones(
|
180 |
+
(batch_size, sequence_length - (mask_length - 1)), device=device
|
181 |
+
)
|
182 |
+
|
183 |
+
# get random indices to mask
|
184 |
+
mask_indices = torch.multinomial(uniform_dist, num_masked_spans)
|
185 |
+
|
186 |
+
# expand masked indices to masked spans
|
187 |
+
mask_indices = (
|
188 |
+
mask_indices.unsqueeze(dim=-1)
|
189 |
+
.expand((batch_size, num_masked_spans, mask_length))
|
190 |
+
.reshape(batch_size, num_masked_spans * mask_length)
|
191 |
+
)
|
192 |
+
offsets = (
|
193 |
+
torch.arange(mask_length, device=device)[None, None, :]
|
194 |
+
.expand((batch_size, num_masked_spans, mask_length))
|
195 |
+
.reshape(batch_size, num_masked_spans * mask_length)
|
196 |
+
)
|
197 |
+
mask_idxs = mask_indices + offsets
|
198 |
+
|
199 |
+
# scatter indices to mask
|
200 |
+
mask = mask.scatter(1, mask_idxs, True)
|
201 |
+
|
202 |
+
return mask
|
203 |
+
|
204 |
+
|
205 |
+
def hubert_soft(
|
206 |
+
path: str,
|
207 |
+
) -> HubertSoft:
|
208 |
+
r"""HuBERT-Soft from `"A Comparison of Discrete and Soft Speech Units for Improved Voice Conversion"`.
|
209 |
+
Args:
|
210 |
+
path (str): path of a pretrained model
|
211 |
+
"""
|
212 |
+
hubert = HubertSoft()
|
213 |
+
checkpoint = torch.load(path)
|
214 |
+
consume_prefix_in_state_dict_if_present(checkpoint, "module.")
|
215 |
+
hubert.load_state_dict(checkpoint)
|
216 |
+
hubert.eval()
|
217 |
+
return hubert
|
inference/__init__.py
ADDED
File without changes
|
inference/__pycache__/__init__.cpython-38.pyc
ADDED
Binary file (157 Bytes). View file
|
|
inference/__pycache__/infer_tool.cpython-38.pyc
ADDED
Binary file (9.23 kB). View file
|
|
inference/__pycache__/slicer.cpython-38.pyc
ADDED
Binary file (3.86 kB). View file
|
|
inference/chunks_temp.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"info": "temp_dict"}
|
inference/infer_tool.py
ADDED
@@ -0,0 +1,273 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import hashlib
|
2 |
+
import io
|
3 |
+
import json
|
4 |
+
import logging
|
5 |
+
import os
|
6 |
+
import time
|
7 |
+
from pathlib import Path
|
8 |
+
from inference import slicer
|
9 |
+
|
10 |
+
import librosa
|
11 |
+
import numpy as np
|
12 |
+
# import onnxruntime
|
13 |
+
import parselmouth
|
14 |
+
import soundfile
|
15 |
+
import torch
|
16 |
+
import torchaudio
|
17 |
+
|
18 |
+
import cluster
|
19 |
+
from hubert import hubert_model
|
20 |
+
import utils
|
21 |
+
from models import SynthesizerTrn
|
22 |
+
|
23 |
+
logging.getLogger('matplotlib').setLevel(logging.WARNING)
|
24 |
+
|
25 |
+
|
26 |
+
def read_temp(file_name):
|
27 |
+
if not os.path.exists(file_name):
|
28 |
+
with open(file_name, "w") as f:
|
29 |
+
f.write(json.dumps({"info": "temp_dict"}))
|
30 |
+
return {}
|
31 |
+
else:
|
32 |
+
try:
|
33 |
+
with open(file_name, "r") as f:
|
34 |
+
data = f.read()
|
35 |
+
data_dict = json.loads(data)
|
36 |
+
if os.path.getsize(file_name) > 50 * 1024 * 1024:
|
37 |
+
f_name = file_name.replace("\\", "/").split("/")[-1]
|
38 |
+
print(f"clean {f_name}")
|
39 |
+
for wav_hash in list(data_dict.keys()):
|
40 |
+
if int(time.time()) - int(data_dict[wav_hash]["time"]) > 14 * 24 * 3600:
|
41 |
+
del data_dict[wav_hash]
|
42 |
+
except Exception as e:
|
43 |
+
print(e)
|
44 |
+
print(f"{file_name} error,auto rebuild file")
|
45 |
+
data_dict = {"info": "temp_dict"}
|
46 |
+
return data_dict
|
47 |
+
|
48 |
+
|
49 |
+
def write_temp(file_name, data):
|
50 |
+
with open(file_name, "w") as f:
|
51 |
+
f.write(json.dumps(data))
|
52 |
+
|
53 |
+
|
54 |
+
def timeit(func):
|
55 |
+
def run(*args, **kwargs):
|
56 |
+
t = time.time()
|
57 |
+
res = func(*args, **kwargs)
|
58 |
+
print('executing \'%s\' costed %.3fs' % (func.__name__, time.time() - t))
|
59 |
+
return res
|
60 |
+
|
61 |
+
return run
|
62 |
+
|
63 |
+
|
64 |
+
def format_wav(audio_path):
|
65 |
+
if Path(audio_path).suffix == '.wav':
|
66 |
+
return
|
67 |
+
raw_audio, raw_sample_rate = librosa.load(audio_path, mono=True, sr=None)
|
68 |
+
soundfile.write(Path(audio_path).with_suffix(".wav"), raw_audio, raw_sample_rate)
|
69 |
+
|
70 |
+
|
71 |
+
def get_end_file(dir_path, end):
|
72 |
+
file_lists = []
|
73 |
+
for root, dirs, files in os.walk(dir_path):
|
74 |
+
files = [f for f in files if f[0] != '.']
|
75 |
+
dirs[:] = [d for d in dirs if d[0] != '.']
|
76 |
+
for f_file in files:
|
77 |
+
if f_file.endswith(end):
|
78 |
+
file_lists.append(os.path.join(root, f_file).replace("\\", "/"))
|
79 |
+
return file_lists
|
80 |
+
|
81 |
+
|
82 |
+
def get_md5(content):
|
83 |
+
return hashlib.new("md5", content).hexdigest()
|
84 |
+
|
85 |
+
def fill_a_to_b(a, b):
|
86 |
+
if len(a) < len(b):
|
87 |
+
for _ in range(0, len(b) - len(a)):
|
88 |
+
a.append(a[0])
|
89 |
+
|
90 |
+
def mkdir(paths: list):
|
91 |
+
for path in paths:
|
92 |
+
if not os.path.exists(path):
|
93 |
+
os.mkdir(path)
|
94 |
+
|
95 |
+
def pad_array(arr, target_length):
|
96 |
+
current_length = arr.shape[0]
|
97 |
+
if current_length >= target_length:
|
98 |
+
return arr
|
99 |
+
else:
|
100 |
+
pad_width = target_length - current_length
|
101 |
+
pad_left = pad_width // 2
|
102 |
+
pad_right = pad_width - pad_left
|
103 |
+
padded_arr = np.pad(arr, (pad_left, pad_right), 'constant', constant_values=(0, 0))
|
104 |
+
return padded_arr
|
105 |
+
|
106 |
+
def split_list_by_n(list_collection, n, pre=0):
|
107 |
+
for i in range(0, len(list_collection), n):
|
108 |
+
yield list_collection[i-pre if i-pre>=0 else i: i + n]
|
109 |
+
|
110 |
+
|
111 |
+
class Svc(object):
|
112 |
+
def __init__(self, net_g_path, config_path, hubert_model,
|
113 |
+
device=None,
|
114 |
+
cluster_model_path="logs/44k/kmeans_10000.pt"):
|
115 |
+
self.net_g_path = net_g_path
|
116 |
+
if device is None:
|
117 |
+
self.dev = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
118 |
+
else:
|
119 |
+
self.dev = torch.device(device)
|
120 |
+
self.net_g_ms = None
|
121 |
+
self.hps_ms = utils.get_hparams_from_file(config_path)
|
122 |
+
self.target_sample = self.hps_ms.data.sampling_rate
|
123 |
+
self.hop_size = self.hps_ms.data.hop_length
|
124 |
+
self.spk2id = self.hps_ms.spk
|
125 |
+
# 加载hubert
|
126 |
+
self.hubert_model = hubert_model
|
127 |
+
self.load_model()
|
128 |
+
if os.path.exists(cluster_model_path):
|
129 |
+
self.cluster_model = cluster.get_cluster_model(cluster_model_path)
|
130 |
+
|
131 |
+
def load_model(self):
|
132 |
+
# 获取模型配置
|
133 |
+
self.net_g_ms = SynthesizerTrn(
|
134 |
+
self.hps_ms.data.filter_length // 2 + 1,
|
135 |
+
self.hps_ms.train.segment_size // self.hps_ms.data.hop_length,
|
136 |
+
**self.hps_ms.model)
|
137 |
+
_ = utils.load_checkpoint(self.net_g_path, self.net_g_ms, None)
|
138 |
+
if "half" in self.net_g_path and torch.cuda.is_available():
|
139 |
+
_ = self.net_g_ms.half().eval().to(self.dev)
|
140 |
+
else:
|
141 |
+
_ = self.net_g_ms.eval().to(self.dev)
|
142 |
+
|
143 |
+
|
144 |
+
|
145 |
+
def get_unit_f0(self, wav, tran, cluster_infer_ratio, speaker):
|
146 |
+
f0 = utils.compute_f0_parselmouth(wav, sampling_rate=self.target_sample, hop_length=self.hop_size)
|
147 |
+
f0, uv = utils.interpolate_f0(f0)
|
148 |
+
f0 = torch.FloatTensor(f0)
|
149 |
+
uv = torch.FloatTensor(uv)
|
150 |
+
f0 = f0 * 2 ** (tran / 12)
|
151 |
+
f0 = f0.unsqueeze(0).to(self.dev)
|
152 |
+
uv = uv.unsqueeze(0).to(self.dev)
|
153 |
+
|
154 |
+
wav16k = librosa.resample(wav, orig_sr=44100, target_sr=16000)
|
155 |
+
wav16k = torch.from_numpy(wav16k).to(self.dev)
|
156 |
+
c = utils.get_hubert_content(self.hubert_model, wav_16k_tensor=wav16k)
|
157 |
+
c = utils.repeat_expand_2d(c.squeeze(0), f0.shape[1])
|
158 |
+
|
159 |
+
if cluster_infer_ratio !=0:
|
160 |
+
cluster_c = cluster.get_cluster_center_result(self.cluster_model, c.cpu().numpy().T, speaker).T
|
161 |
+
cluster_c = torch.FloatTensor(cluster_c).to(self.dev)
|
162 |
+
c = cluster_infer_ratio * cluster_c + (1 - cluster_infer_ratio) * c
|
163 |
+
|
164 |
+
c = c.unsqueeze(0)
|
165 |
+
return c, f0, uv
|
166 |
+
|
167 |
+
def infer(self, speaker, tran, raw_wav,
|
168 |
+
cluster_infer_ratio=0,
|
169 |
+
auto_predict_f0=False,
|
170 |
+
noice_scale=0.4):
|
171 |
+
speaker_id = self.spk2id.__dict__.get(speaker)
|
172 |
+
if not speaker_id and type(speaker) is int:
|
173 |
+
if len(self.spk2id.__dict__) >= speaker:
|
174 |
+
speaker_id = speaker
|
175 |
+
sid = torch.LongTensor([int(speaker_id)]).to(self.dev).unsqueeze(0)
|
176 |
+
c, f0, uv = self.get_unit_f0(raw_wav, tran, cluster_infer_ratio, speaker)
|
177 |
+
if "half" in self.net_g_path and torch.cuda.is_available():
|
178 |
+
c = c.half()
|
179 |
+
with torch.no_grad():
|
180 |
+
start = time.time()
|
181 |
+
audio = self.net_g_ms.infer(c, f0=f0, g=sid, uv=uv, predict_f0=auto_predict_f0, noice_scale=noice_scale)[0,0].data.float()
|
182 |
+
use_time = time.time() - start
|
183 |
+
print("vits use time:{}".format(use_time))
|
184 |
+
return audio, audio.shape[-1]
|
185 |
+
|
186 |
+
def clear_empty(self):
|
187 |
+
# 清理显存
|
188 |
+
torch.cuda.empty_cache()
|
189 |
+
|
190 |
+
def slice_inference(self,raw_audio_path, spk, tran, slice_db,cluster_infer_ratio, auto_predict_f0,noice_scale, pad_seconds=0.5, clip_seconds=0,lg_num=0,lgr_num =0.75):
|
191 |
+
wav_path = raw_audio_path
|
192 |
+
chunks = slicer.cut(wav_path, db_thresh=slice_db)
|
193 |
+
audio_data, audio_sr = slicer.chunks2audio(wav_path, chunks)
|
194 |
+
per_size = int(clip_seconds*audio_sr)
|
195 |
+
lg_size = int(lg_num*audio_sr)
|
196 |
+
lg_size_r = int(lg_size*lgr_num)
|
197 |
+
lg_size_c_l = (lg_size-lg_size_r)//2
|
198 |
+
lg_size_c_r = lg_size-lg_size_r-lg_size_c_l
|
199 |
+
lg = np.linspace(0,1,lg_size_r) if lg_size!=0 else 0
|
200 |
+
|
201 |
+
audio = []
|
202 |
+
for (slice_tag, data) in audio_data:
|
203 |
+
print(f'#=====segment start, {round(len(data) / audio_sr, 3)}s======')
|
204 |
+
# padd
|
205 |
+
length = int(np.ceil(len(data) / audio_sr * self.target_sample))
|
206 |
+
if slice_tag:
|
207 |
+
print('jump empty segment')
|
208 |
+
_audio = np.zeros(length)
|
209 |
+
audio.extend(list(pad_array(_audio, length)))
|
210 |
+
continue
|
211 |
+
if per_size != 0:
|
212 |
+
datas = split_list_by_n(data, per_size,lg_size)
|
213 |
+
else:
|
214 |
+
datas = [data]
|
215 |
+
for k,dat in enumerate(datas):
|
216 |
+
per_length = int(np.ceil(len(dat) / audio_sr * self.target_sample)) if clip_seconds!=0 else length
|
217 |
+
if clip_seconds!=0: print(f'###=====segment clip start, {round(len(dat) / audio_sr, 3)}s======')
|
218 |
+
# padd
|
219 |
+
pad_len = int(audio_sr * pad_seconds)
|
220 |
+
dat = np.concatenate([np.zeros([pad_len]), dat, np.zeros([pad_len])])
|
221 |
+
raw_path = io.BytesIO()
|
222 |
+
soundfile.write(raw_path, dat, audio_sr, format="wav")
|
223 |
+
raw_path.seek(0)
|
224 |
+
out_audio, out_sr = self.infer(spk, tran, raw_path,
|
225 |
+
cluster_infer_ratio=cluster_infer_ratio,
|
226 |
+
auto_predict_f0=auto_predict_f0,
|
227 |
+
noice_scale=noice_scale
|
228 |
+
)
|
229 |
+
_audio = out_audio.cpu().numpy()
|
230 |
+
pad_len = int(self.target_sample * pad_seconds)
|
231 |
+
_audio = _audio[pad_len:-pad_len]
|
232 |
+
_audio = pad_array(_audio, per_length)
|
233 |
+
if lg_size!=0 and k!=0:
|
234 |
+
lg1 = audio[-(lg_size_r+lg_size_c_r):-lg_size_c_r] if lgr_num != 1 else audio[-lg_size:]
|
235 |
+
lg2 = _audio[lg_size_c_l:lg_size_c_l+lg_size_r] if lgr_num != 1 else _audio[0:lg_size]
|
236 |
+
lg_pre = lg1*(1-lg)+lg2*lg
|
237 |
+
audio = audio[0:-(lg_size_r+lg_size_c_r)] if lgr_num != 1 else audio[0:-lg_size]
|
238 |
+
audio.extend(lg_pre)
|
239 |
+
_audio = _audio[lg_size_c_l+lg_size_r:] if lgr_num != 1 else _audio[lg_size:]
|
240 |
+
audio.extend(list(_audio))
|
241 |
+
return np.array(audio)
|
242 |
+
|
243 |
+
class RealTimeVC:
|
244 |
+
def __init__(self):
|
245 |
+
self.last_chunk = None
|
246 |
+
self.last_o = None
|
247 |
+
self.chunk_len = 16000 # 区块长度
|
248 |
+
self.pre_len = 3840 # 交叉淡化长度,640的倍数
|
249 |
+
|
250 |
+
"""输入输出都是1维numpy 音频波形数组"""
|
251 |
+
|
252 |
+
def process(self, svc_model, speaker_id, f_pitch_change, input_wav_path):
|
253 |
+
import maad
|
254 |
+
audio, sr = torchaudio.load(input_wav_path)
|
255 |
+
audio = audio.cpu().numpy()[0]
|
256 |
+
temp_wav = io.BytesIO()
|
257 |
+
if self.last_chunk is None:
|
258 |
+
input_wav_path.seek(0)
|
259 |
+
audio, sr = svc_model.infer(speaker_id, f_pitch_change, input_wav_path)
|
260 |
+
audio = audio.cpu().numpy()
|
261 |
+
self.last_chunk = audio[-self.pre_len:]
|
262 |
+
self.last_o = audio
|
263 |
+
return audio[-self.chunk_len:]
|
264 |
+
else:
|
265 |
+
audio = np.concatenate([self.last_chunk, audio])
|
266 |
+
soundfile.write(temp_wav, audio, sr, format="wav")
|
267 |
+
temp_wav.seek(0)
|
268 |
+
audio, sr = svc_model.infer(speaker_id, f_pitch_change, temp_wav)
|
269 |
+
audio = audio.cpu().numpy()
|
270 |
+
ret = maad.util.crossfade(self.last_o, audio, self.pre_len)
|
271 |
+
self.last_chunk = audio[-self.pre_len:]
|
272 |
+
self.last_o = audio
|
273 |
+
return ret[self.chunk_len:2 * self.chunk_len]
|
inference/infer_tool_grad.py
ADDED
@@ -0,0 +1,160 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import hashlib
|
2 |
+
import json
|
3 |
+
import logging
|
4 |
+
import os
|
5 |
+
import time
|
6 |
+
from pathlib import Path
|
7 |
+
import io
|
8 |
+
import librosa
|
9 |
+
import maad
|
10 |
+
import numpy as np
|
11 |
+
from inference import slicer
|
12 |
+
import parselmouth
|
13 |
+
import soundfile
|
14 |
+
import torch
|
15 |
+
import torchaudio
|
16 |
+
|
17 |
+
from hubert import hubert_model
|
18 |
+
import utils
|
19 |
+
from models import SynthesizerTrn
|
20 |
+
logging.getLogger('numba').setLevel(logging.WARNING)
|
21 |
+
logging.getLogger('matplotlib').setLevel(logging.WARNING)
|
22 |
+
|
23 |
+
def resize2d_f0(x, target_len):
|
24 |
+
source = np.array(x)
|
25 |
+
source[source < 0.001] = np.nan
|
26 |
+
target = np.interp(np.arange(0, len(source) * target_len, len(source)) / target_len, np.arange(0, len(source)),
|
27 |
+
source)
|
28 |
+
res = np.nan_to_num(target)
|
29 |
+
return res
|
30 |
+
|
31 |
+
def get_f0(x, p_len,f0_up_key=0):
|
32 |
+
|
33 |
+
time_step = 160 / 16000 * 1000
|
34 |
+
f0_min = 50
|
35 |
+
f0_max = 1100
|
36 |
+
f0_mel_min = 1127 * np.log(1 + f0_min / 700)
|
37 |
+
f0_mel_max = 1127 * np.log(1 + f0_max / 700)
|
38 |
+
|
39 |
+
f0 = parselmouth.Sound(x, 16000).to_pitch_ac(
|
40 |
+
time_step=time_step / 1000, voicing_threshold=0.6,
|
41 |
+
pitch_floor=f0_min, pitch_ceiling=f0_max).selected_array['frequency']
|
42 |
+
|
43 |
+
pad_size=(p_len - len(f0) + 1) // 2
|
44 |
+
if(pad_size>0 or p_len - len(f0) - pad_size>0):
|
45 |
+
f0 = np.pad(f0,[[pad_size,p_len - len(f0) - pad_size]], mode='constant')
|
46 |
+
|
47 |
+
f0 *= pow(2, f0_up_key / 12)
|
48 |
+
f0_mel = 1127 * np.log(1 + f0 / 700)
|
49 |
+
f0_mel[f0_mel > 0] = (f0_mel[f0_mel > 0] - f0_mel_min) * 254 / (f0_mel_max - f0_mel_min) + 1
|
50 |
+
f0_mel[f0_mel <= 1] = 1
|
51 |
+
f0_mel[f0_mel > 255] = 255
|
52 |
+
f0_coarse = np.rint(f0_mel).astype(np.int)
|
53 |
+
return f0_coarse, f0
|
54 |
+
|
55 |
+
def clean_pitch(input_pitch):
|
56 |
+
num_nan = np.sum(input_pitch == 1)
|
57 |
+
if num_nan / len(input_pitch) > 0.9:
|
58 |
+
input_pitch[input_pitch != 1] = 1
|
59 |
+
return input_pitch
|
60 |
+
|
61 |
+
|
62 |
+
def plt_pitch(input_pitch):
|
63 |
+
input_pitch = input_pitch.astype(float)
|
64 |
+
input_pitch[input_pitch == 1] = np.nan
|
65 |
+
return input_pitch
|
66 |
+
|
67 |
+
|
68 |
+
def f0_to_pitch(ff):
|
69 |
+
f0_pitch = 69 + 12 * np.log2(ff / 440)
|
70 |
+
return f0_pitch
|
71 |
+
|
72 |
+
|
73 |
+
def fill_a_to_b(a, b):
|
74 |
+
if len(a) < len(b):
|
75 |
+
for _ in range(0, len(b) - len(a)):
|
76 |
+
a.append(a[0])
|
77 |
+
|
78 |
+
|
79 |
+
def mkdir(paths: list):
|
80 |
+
for path in paths:
|
81 |
+
if not os.path.exists(path):
|
82 |
+
os.mkdir(path)
|
83 |
+
|
84 |
+
|
85 |
+
class VitsSvc(object):
|
86 |
+
def __init__(self):
|
87 |
+
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
88 |
+
self.SVCVITS = None
|
89 |
+
self.hps = None
|
90 |
+
self.speakers = None
|
91 |
+
self.hubert_soft = utils.get_hubert_model()
|
92 |
+
|
93 |
+
def set_device(self, device):
|
94 |
+
self.device = torch.device(device)
|
95 |
+
self.hubert_soft.to(self.device)
|
96 |
+
if self.SVCVITS != None:
|
97 |
+
self.SVCVITS.to(self.device)
|
98 |
+
|
99 |
+
def loadCheckpoint(self, path):
|
100 |
+
self.hps = utils.get_hparams_from_file(f"checkpoints/{path}/config.json")
|
101 |
+
self.SVCVITS = SynthesizerTrn(
|
102 |
+
self.hps.data.filter_length // 2 + 1,
|
103 |
+
self.hps.train.segment_size // self.hps.data.hop_length,
|
104 |
+
**self.hps.model)
|
105 |
+
_ = utils.load_checkpoint(f"checkpoints/{path}/model.pth", self.SVCVITS, None)
|
106 |
+
_ = self.SVCVITS.eval().to(self.device)
|
107 |
+
self.speakers = self.hps.spk
|
108 |
+
|
109 |
+
def get_units(self, source, sr):
|
110 |
+
source = source.unsqueeze(0).to(self.device)
|
111 |
+
with torch.inference_mode():
|
112 |
+
units = self.hubert_soft.units(source)
|
113 |
+
return units
|
114 |
+
|
115 |
+
|
116 |
+
def get_unit_pitch(self, in_path, tran):
|
117 |
+
source, sr = torchaudio.load(in_path)
|
118 |
+
source = torchaudio.functional.resample(source, sr, 16000)
|
119 |
+
if len(source.shape) == 2 and source.shape[1] >= 2:
|
120 |
+
source = torch.mean(source, dim=0).unsqueeze(0)
|
121 |
+
soft = self.get_units(source, sr).squeeze(0).cpu().numpy()
|
122 |
+
f0_coarse, f0 = get_f0(source.cpu().numpy()[0], soft.shape[0]*2, tran)
|
123 |
+
return soft, f0
|
124 |
+
|
125 |
+
def infer(self, speaker_id, tran, raw_path):
|
126 |
+
speaker_id = self.speakers[speaker_id]
|
127 |
+
sid = torch.LongTensor([int(speaker_id)]).to(self.device).unsqueeze(0)
|
128 |
+
soft, pitch = self.get_unit_pitch(raw_path, tran)
|
129 |
+
f0 = torch.FloatTensor(clean_pitch(pitch)).unsqueeze(0).to(self.device)
|
130 |
+
stn_tst = torch.FloatTensor(soft)
|
131 |
+
with torch.no_grad():
|
132 |
+
x_tst = stn_tst.unsqueeze(0).to(self.device)
|
133 |
+
x_tst = torch.repeat_interleave(x_tst, repeats=2, dim=1).transpose(1, 2)
|
134 |
+
audio = self.SVCVITS.infer(x_tst, f0=f0, g=sid)[0,0].data.float()
|
135 |
+
return audio, audio.shape[-1]
|
136 |
+
|
137 |
+
def inference(self,srcaudio,chara,tran,slice_db):
|
138 |
+
sampling_rate, audio = srcaudio
|
139 |
+
audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
|
140 |
+
if len(audio.shape) > 1:
|
141 |
+
audio = librosa.to_mono(audio.transpose(1, 0))
|
142 |
+
if sampling_rate != 16000:
|
143 |
+
audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000)
|
144 |
+
soundfile.write("tmpwav.wav", audio, 16000, format="wav")
|
145 |
+
chunks = slicer.cut("tmpwav.wav", db_thresh=slice_db)
|
146 |
+
audio_data, audio_sr = slicer.chunks2audio("tmpwav.wav", chunks)
|
147 |
+
audio = []
|
148 |
+
for (slice_tag, data) in audio_data:
|
149 |
+
length = int(np.ceil(len(data) / audio_sr * self.hps.data.sampling_rate))
|
150 |
+
raw_path = io.BytesIO()
|
151 |
+
soundfile.write(raw_path, data, audio_sr, format="wav")
|
152 |
+
raw_path.seek(0)
|
153 |
+
if slice_tag:
|
154 |
+
_audio = np.zeros(length)
|
155 |
+
else:
|
156 |
+
out_audio, out_sr = self.infer(chara, tran, raw_path)
|
157 |
+
_audio = out_audio.cpu().numpy()
|
158 |
+
audio.extend(list(_audio))
|
159 |
+
audio = (np.array(audio) * 32768.0).astype('int16')
|
160 |
+
return (self.hps.data.sampling_rate,audio)
|
inference/slicer.py
ADDED
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import librosa
|
2 |
+
import torch
|
3 |
+
import torchaudio
|
4 |
+
|
5 |
+
|
6 |
+
class Slicer:
|
7 |
+
def __init__(self,
|
8 |
+
sr: int,
|
9 |
+
threshold: float = -40.,
|
10 |
+
min_length: int = 5000,
|
11 |
+
min_interval: int = 300,
|
12 |
+
hop_size: int = 20,
|
13 |
+
max_sil_kept: int = 5000):
|
14 |
+
if not min_length >= min_interval >= hop_size:
|
15 |
+
raise ValueError('The following condition must be satisfied: min_length >= min_interval >= hop_size')
|
16 |
+
if not max_sil_kept >= hop_size:
|
17 |
+
raise ValueError('The following condition must be satisfied: max_sil_kept >= hop_size')
|
18 |
+
min_interval = sr * min_interval / 1000
|
19 |
+
self.threshold = 10 ** (threshold / 20.)
|
20 |
+
self.hop_size = round(sr * hop_size / 1000)
|
21 |
+
self.win_size = min(round(min_interval), 4 * self.hop_size)
|
22 |
+
self.min_length = round(sr * min_length / 1000 / self.hop_size)
|
23 |
+
self.min_interval = round(min_interval / self.hop_size)
|
24 |
+
self.max_sil_kept = round(sr * max_sil_kept / 1000 / self.hop_size)
|
25 |
+
|
26 |
+
def _apply_slice(self, waveform, begin, end):
|
27 |
+
if len(waveform.shape) > 1:
|
28 |
+
return waveform[:, begin * self.hop_size: min(waveform.shape[1], end * self.hop_size)]
|
29 |
+
else:
|
30 |
+
return waveform[begin * self.hop_size: min(waveform.shape[0], end * self.hop_size)]
|
31 |
+
|
32 |
+
# @timeit
|
33 |
+
def slice(self, waveform):
|
34 |
+
if len(waveform.shape) > 1:
|
35 |
+
samples = librosa.to_mono(waveform)
|
36 |
+
else:
|
37 |
+
samples = waveform
|
38 |
+
if samples.shape[0] <= self.min_length:
|
39 |
+
return {"0": {"slice": False, "split_time": f"0,{len(waveform)}"}}
|
40 |
+
rms_list = librosa.feature.rms(y=samples, frame_length=self.win_size, hop_length=self.hop_size).squeeze(0)
|
41 |
+
sil_tags = []
|
42 |
+
silence_start = None
|
43 |
+
clip_start = 0
|
44 |
+
for i, rms in enumerate(rms_list):
|
45 |
+
# Keep looping while frame is silent.
|
46 |
+
if rms < self.threshold:
|
47 |
+
# Record start of silent frames.
|
48 |
+
if silence_start is None:
|
49 |
+
silence_start = i
|
50 |
+
continue
|
51 |
+
# Keep looping while frame is not silent and silence start has not been recorded.
|
52 |
+
if silence_start is None:
|
53 |
+
continue
|
54 |
+
# Clear recorded silence start if interval is not enough or clip is too short
|
55 |
+
is_leading_silence = silence_start == 0 and i > self.max_sil_kept
|
56 |
+
need_slice_middle = i - silence_start >= self.min_interval and i - clip_start >= self.min_length
|
57 |
+
if not is_leading_silence and not need_slice_middle:
|
58 |
+
silence_start = None
|
59 |
+
continue
|
60 |
+
# Need slicing. Record the range of silent frames to be removed.
|
61 |
+
if i - silence_start <= self.max_sil_kept:
|
62 |
+
pos = rms_list[silence_start: i + 1].argmin() + silence_start
|
63 |
+
if silence_start == 0:
|
64 |
+
sil_tags.append((0, pos))
|
65 |
+
else:
|
66 |
+
sil_tags.append((pos, pos))
|
67 |
+
clip_start = pos
|
68 |
+
elif i - silence_start <= self.max_sil_kept * 2:
|
69 |
+
pos = rms_list[i - self.max_sil_kept: silence_start + self.max_sil_kept + 1].argmin()
|
70 |
+
pos += i - self.max_sil_kept
|
71 |
+
pos_l = rms_list[silence_start: silence_start + self.max_sil_kept + 1].argmin() + silence_start
|
72 |
+
pos_r = rms_list[i - self.max_sil_kept: i + 1].argmin() + i - self.max_sil_kept
|
73 |
+
if silence_start == 0:
|
74 |
+
sil_tags.append((0, pos_r))
|
75 |
+
clip_start = pos_r
|
76 |
+
else:
|
77 |
+
sil_tags.append((min(pos_l, pos), max(pos_r, pos)))
|
78 |
+
clip_start = max(pos_r, pos)
|
79 |
+
else:
|
80 |
+
pos_l = rms_list[silence_start: silence_start + self.max_sil_kept + 1].argmin() + silence_start
|
81 |
+
pos_r = rms_list[i - self.max_sil_kept: i + 1].argmin() + i - self.max_sil_kept
|
82 |
+
if silence_start == 0:
|
83 |
+
sil_tags.append((0, pos_r))
|
84 |
+
else:
|
85 |
+
sil_tags.append((pos_l, pos_r))
|
86 |
+
clip_start = pos_r
|
87 |
+
silence_start = None
|
88 |
+
# Deal with trailing silence.
|
89 |
+
total_frames = rms_list.shape[0]
|
90 |
+
if silence_start is not None and total_frames - silence_start >= self.min_interval:
|
91 |
+
silence_end = min(total_frames, silence_start + self.max_sil_kept)
|
92 |
+
pos = rms_list[silence_start: silence_end + 1].argmin() + silence_start
|
93 |
+
sil_tags.append((pos, total_frames + 1))
|
94 |
+
# Apply and return slices.
|
95 |
+
if len(sil_tags) == 0:
|
96 |
+
return {"0": {"slice": False, "split_time": f"0,{len(waveform)}"}}
|
97 |
+
else:
|
98 |
+
chunks = []
|
99 |
+
# 第一段静音并非从头开始,补上有声片段
|
100 |
+
if sil_tags[0][0]:
|
101 |
+
chunks.append(
|
102 |
+
{"slice": False, "split_time": f"0,{min(waveform.shape[0], sil_tags[0][0] * self.hop_size)}"})
|
103 |
+
for i in range(0, len(sil_tags)):
|
104 |
+
# 标识有声片段(跳过第一段)
|
105 |
+
if i:
|
106 |
+
chunks.append({"slice": False,
|
107 |
+
"split_time": f"{sil_tags[i - 1][1] * self.hop_size},{min(waveform.shape[0], sil_tags[i][0] * self.hop_size)}"})
|
108 |
+
# 标识所有静音片段
|
109 |
+
chunks.append({"slice": True,
|
110 |
+
"split_time": f"{sil_tags[i][0] * self.hop_size},{min(waveform.shape[0], sil_tags[i][1] * self.hop_size)}"})
|
111 |
+
# 最后一段静音并非结尾,补上结尾片段
|
112 |
+
if sil_tags[-1][1] * self.hop_size < len(waveform):
|
113 |
+
chunks.append({"slice": False, "split_time": f"{sil_tags[-1][1] * self.hop_size},{len(waveform)}"})
|
114 |
+
chunk_dict = {}
|
115 |
+
for i in range(len(chunks)):
|
116 |
+
chunk_dict[str(i)] = chunks[i]
|
117 |
+
return chunk_dict
|
118 |
+
|
119 |
+
|
120 |
+
def cut(audio_path, db_thresh=-30, min_len=5000):
|
121 |
+
audio, sr = librosa.load(audio_path, sr=None)
|
122 |
+
slicer = Slicer(
|
123 |
+
sr=sr,
|
124 |
+
threshold=db_thresh,
|
125 |
+
min_length=min_len
|
126 |
+
)
|
127 |
+
chunks = slicer.slice(audio)
|
128 |
+
return chunks
|
129 |
+
|
130 |
+
|
131 |
+
def chunks2audio(audio_path, chunks):
|
132 |
+
chunks = dict(chunks)
|
133 |
+
audio, sr = torchaudio.load(audio_path)
|
134 |
+
if len(audio.shape) == 2 and audio.shape[1] >= 2:
|
135 |
+
audio = torch.mean(audio, dim=0).unsqueeze(0)
|
136 |
+
audio = audio.cpu().numpy()[0]
|
137 |
+
result = []
|
138 |
+
for k, v in chunks.items():
|
139 |
+
tag = v["split_time"].split(",")
|
140 |
+
if tag[0] != tag[1]:
|
141 |
+
result.append((v["slice"], audio[int(tag[0]):int(tag[1])]))
|
142 |
+
return result, sr
|
inference_main.py
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import io
|
2 |
+
import logging
|
3 |
+
import time
|
4 |
+
from pathlib import Path
|
5 |
+
|
6 |
+
import librosa
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
import numpy as np
|
9 |
+
import soundfile
|
10 |
+
|
11 |
+
from inference import infer_tool
|
12 |
+
from inference import slicer
|
13 |
+
from inference.infer_tool import Svc
|
14 |
+
|
15 |
+
logging.getLogger('numba').setLevel(logging.WARNING)
|
16 |
+
chunks_dict = infer_tool.read_temp("inference/chunks_temp.json")
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
def main():
|
21 |
+
import argparse
|
22 |
+
|
23 |
+
parser = argparse.ArgumentParser(description='sovits4 inference')
|
24 |
+
|
25 |
+
# 一定要设置的部分
|
26 |
+
parser.add_argument('-m', '--model_path', type=str, default="/Volumes/Extend/下载/G_20800.pth", help='模型路径')
|
27 |
+
parser.add_argument('-c', '--config_path', type=str, default="configs/config.json", help='配置文件路径')
|
28 |
+
parser.add_argument('-n', '--clean_names', type=str, nargs='+', default=["君の知らない物語-src"], help='wav文件名列表,放在raw文件夹下')
|
29 |
+
parser.add_argument('-t', '--trans', type=int, nargs='+', default=[0], help='音高调整,支持正负(半音)')
|
30 |
+
parser.add_argument('-s', '--spk_list', type=str, nargs='+', default=['nyaru'], help='合成目标说话人名称')
|
31 |
+
|
32 |
+
# 可选项部分
|
33 |
+
parser.add_argument('-a', '--auto_predict_f0', action='store_true', default=False,
|
34 |
+
help='语音转换自动预测音高,转换歌声时不要打开这个会严重跑调')
|
35 |
+
parser.add_argument('-cm', '--cluster_model_path', type=str, default="/Volumes/Extend/下载/so-vits-svc-4.0/logs/44k/kmeans_10000.pt", help='聚类模型路径,如果没有训练聚类则随便填')
|
36 |
+
parser.add_argument('-cr', '--cluster_infer_ratio', type=float, default=1, help='聚类方案占比,范围0-1,若没有训练聚类模型则填0即可')
|
37 |
+
|
38 |
+
# 不用动的部分
|
39 |
+
parser.add_argument('-sd', '--slice_db', type=int, default=-40, help='默认-40,嘈杂的音频可以-30,干声保留呼吸可以-50')
|
40 |
+
parser.add_argument('-d', '--device', type=str, default=None, help='推理设备,None则为自动选择cpu和gpu')
|
41 |
+
parser.add_argument('-ns', '--noice_scale', type=float, default=0.4, help='噪音级别,会影响咬字和音质,较为玄学')
|
42 |
+
parser.add_argument('-p', '--pad_seconds', type=float, default=0.5, help='推理音频pad秒数,由于未知原因开头结尾会有异响,pad一小段静音段后就不会出现')
|
43 |
+
parser.add_argument('-wf', '--wav_format', type=str, default='flac', help='音频输出格式')
|
44 |
+
|
45 |
+
args = parser.parse_args()
|
46 |
+
|
47 |
+
svc_model = Svc(args.model_path, args.config_path, args.device, args.cluster_model_path)
|
48 |
+
infer_tool.mkdir(["raw", "results"])
|
49 |
+
clean_names = args.clean_names
|
50 |
+
trans = args.trans
|
51 |
+
spk_list = args.spk_list
|
52 |
+
slice_db = args.slice_db
|
53 |
+
wav_format = args.wav_format
|
54 |
+
auto_predict_f0 = args.auto_predict_f0
|
55 |
+
cluster_infer_ratio = args.cluster_infer_ratio
|
56 |
+
noice_scale = args.noice_scale
|
57 |
+
pad_seconds = args.pad_seconds
|
58 |
+
|
59 |
+
infer_tool.fill_a_to_b(trans, clean_names)
|
60 |
+
for clean_name, tran in zip(clean_names, trans):
|
61 |
+
raw_audio_path = f"raw/{clean_name}"
|
62 |
+
if "." not in raw_audio_path:
|
63 |
+
raw_audio_path += ".wav"
|
64 |
+
infer_tool.format_wav(raw_audio_path)
|
65 |
+
wav_path = Path(raw_audio_path).with_suffix('.wav')
|
66 |
+
chunks = slicer.cut(wav_path, db_thresh=slice_db)
|
67 |
+
audio_data, audio_sr = slicer.chunks2audio(wav_path, chunks)
|
68 |
+
|
69 |
+
for spk in spk_list:
|
70 |
+
audio = []
|
71 |
+
for (slice_tag, data) in audio_data:
|
72 |
+
print(f'#=====segment start, {round(len(data) / audio_sr, 3)}s======')
|
73 |
+
# padd
|
74 |
+
pad_len = int(audio_sr * pad_seconds)
|
75 |
+
data = np.concatenate([np.zeros([pad_len]), data, np.zeros([pad_len])])
|
76 |
+
length = int(np.ceil(len(data) / audio_sr * svc_model.target_sample))
|
77 |
+
raw_path = io.BytesIO()
|
78 |
+
soundfile.write(raw_path, data, audio_sr, format="wav")
|
79 |
+
raw_path.seek(0)
|
80 |
+
if slice_tag:
|
81 |
+
print('jump empty segment')
|
82 |
+
_audio = np.zeros(length)
|
83 |
+
else:
|
84 |
+
out_audio, out_sr = svc_model.infer(spk, tran, raw_path,
|
85 |
+
cluster_infer_ratio=cluster_infer_ratio,
|
86 |
+
auto_predict_f0=auto_predict_f0,
|
87 |
+
noice_scale=noice_scale
|
88 |
+
)
|
89 |
+
_audio = out_audio.cpu().numpy()
|
90 |
+
|
91 |
+
pad_len = int(svc_model.target_sample * pad_seconds)
|
92 |
+
_audio = _audio[pad_len:-pad_len]
|
93 |
+
audio.extend(list(_audio))
|
94 |
+
key = "auto" if auto_predict_f0 else f"{tran}key"
|
95 |
+
cluster_name = "" if cluster_infer_ratio == 0 else f"_{cluster_infer_ratio}"
|
96 |
+
res_path = f'./results/old——{clean_name}_{key}_{spk}{cluster_name}.{wav_format}'
|
97 |
+
soundfile.write(res_path, audio, svc_model.target_sample, format=wav_format)
|
98 |
+
|
99 |
+
if __name__ == '__main__':
|
100 |
+
main()
|
models.py
ADDED
@@ -0,0 +1,420 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import copy
|
2 |
+
import math
|
3 |
+
import torch
|
4 |
+
from torch import nn
|
5 |
+
from torch.nn import functional as F
|
6 |
+
|
7 |
+
import modules.attentions as attentions
|
8 |
+
import modules.commons as commons
|
9 |
+
import modules.modules as modules
|
10 |
+
|
11 |
+
from torch.nn import Conv1d, ConvTranspose1d, AvgPool1d, Conv2d
|
12 |
+
from torch.nn.utils import weight_norm, remove_weight_norm, spectral_norm
|
13 |
+
|
14 |
+
import utils
|
15 |
+
from modules.commons import init_weights, get_padding
|
16 |
+
from vdecoder.hifigan.models import Generator
|
17 |
+
from utils import f0_to_coarse
|
18 |
+
|
19 |
+
class ResidualCouplingBlock(nn.Module):
|
20 |
+
def __init__(self,
|
21 |
+
channels,
|
22 |
+
hidden_channels,
|
23 |
+
kernel_size,
|
24 |
+
dilation_rate,
|
25 |
+
n_layers,
|
26 |
+
n_flows=4,
|
27 |
+
gin_channels=0):
|
28 |
+
super().__init__()
|
29 |
+
self.channels = channels
|
30 |
+
self.hidden_channels = hidden_channels
|
31 |
+
self.kernel_size = kernel_size
|
32 |
+
self.dilation_rate = dilation_rate
|
33 |
+
self.n_layers = n_layers
|
34 |
+
self.n_flows = n_flows
|
35 |
+
self.gin_channels = gin_channels
|
36 |
+
|
37 |
+
self.flows = nn.ModuleList()
|
38 |
+
for i in range(n_flows):
|
39 |
+
self.flows.append(modules.ResidualCouplingLayer(channels, hidden_channels, kernel_size, dilation_rate, n_layers, gin_channels=gin_channels, mean_only=True))
|
40 |
+
self.flows.append(modules.Flip())
|
41 |
+
|
42 |
+
def forward(self, x, x_mask, g=None, reverse=False):
|
43 |
+
if not reverse:
|
44 |
+
for flow in self.flows:
|
45 |
+
x, _ = flow(x, x_mask, g=g, reverse=reverse)
|
46 |
+
else:
|
47 |
+
for flow in reversed(self.flows):
|
48 |
+
x = flow(x, x_mask, g=g, reverse=reverse)
|
49 |
+
return x
|
50 |
+
|
51 |
+
|
52 |
+
class Encoder(nn.Module):
|
53 |
+
def __init__(self,
|
54 |
+
in_channels,
|
55 |
+
out_channels,
|
56 |
+
hidden_channels,
|
57 |
+
kernel_size,
|
58 |
+
dilation_rate,
|
59 |
+
n_layers,
|
60 |
+
gin_channels=0):
|
61 |
+
super().__init__()
|
62 |
+
self.in_channels = in_channels
|
63 |
+
self.out_channels = out_channels
|
64 |
+
self.hidden_channels = hidden_channels
|
65 |
+
self.kernel_size = kernel_size
|
66 |
+
self.dilation_rate = dilation_rate
|
67 |
+
self.n_layers = n_layers
|
68 |
+
self.gin_channels = gin_channels
|
69 |
+
|
70 |
+
self.pre = nn.Conv1d(in_channels, hidden_channels, 1)
|
71 |
+
self.enc = modules.WN(hidden_channels, kernel_size, dilation_rate, n_layers, gin_channels=gin_channels)
|
72 |
+
self.proj = nn.Conv1d(hidden_channels, out_channels * 2, 1)
|
73 |
+
|
74 |
+
def forward(self, x, x_lengths, g=None):
|
75 |
+
# print(x.shape,x_lengths.shape)
|
76 |
+
x_mask = torch.unsqueeze(commons.sequence_mask(x_lengths, x.size(2)), 1).to(x.dtype)
|
77 |
+
x = self.pre(x) * x_mask
|
78 |
+
x = self.enc(x, x_mask, g=g)
|
79 |
+
stats = self.proj(x) * x_mask
|
80 |
+
m, logs = torch.split(stats, self.out_channels, dim=1)
|
81 |
+
z = (m + torch.randn_like(m) * torch.exp(logs)) * x_mask
|
82 |
+
return z, m, logs, x_mask
|
83 |
+
|
84 |
+
|
85 |
+
class TextEncoder(nn.Module):
|
86 |
+
def __init__(self,
|
87 |
+
out_channels,
|
88 |
+
hidden_channels,
|
89 |
+
kernel_size,
|
90 |
+
n_layers,
|
91 |
+
gin_channels=0,
|
92 |
+
filter_channels=None,
|
93 |
+
n_heads=None,
|
94 |
+
p_dropout=None):
|
95 |
+
super().__init__()
|
96 |
+
self.out_channels = out_channels
|
97 |
+
self.hidden_channels = hidden_channels
|
98 |
+
self.kernel_size = kernel_size
|
99 |
+
self.n_layers = n_layers
|
100 |
+
self.gin_channels = gin_channels
|
101 |
+
self.proj = nn.Conv1d(hidden_channels, out_channels * 2, 1)
|
102 |
+
self.f0_emb = nn.Embedding(256, hidden_channels)
|
103 |
+
|
104 |
+
self.enc_ = attentions.Encoder(
|
105 |
+
hidden_channels,
|
106 |
+
filter_channels,
|
107 |
+
n_heads,
|
108 |
+
n_layers,
|
109 |
+
kernel_size,
|
110 |
+
p_dropout)
|
111 |
+
|
112 |
+
def forward(self, x, x_mask, f0=None, noice_scale=1):
|
113 |
+
x = x + self.f0_emb(f0).transpose(1,2)
|
114 |
+
x = self.enc_(x * x_mask, x_mask)
|
115 |
+
stats = self.proj(x) * x_mask
|
116 |
+
m, logs = torch.split(stats, self.out_channels, dim=1)
|
117 |
+
z = (m + torch.randn_like(m) * torch.exp(logs) * noice_scale) * x_mask
|
118 |
+
|
119 |
+
return z, m, logs, x_mask
|
120 |
+
|
121 |
+
|
122 |
+
|
123 |
+
class DiscriminatorP(torch.nn.Module):
|
124 |
+
def __init__(self, period, kernel_size=5, stride=3, use_spectral_norm=False):
|
125 |
+
super(DiscriminatorP, self).__init__()
|
126 |
+
self.period = period
|
127 |
+
self.use_spectral_norm = use_spectral_norm
|
128 |
+
norm_f = weight_norm if use_spectral_norm == False else spectral_norm
|
129 |
+
self.convs = nn.ModuleList([
|
130 |
+
norm_f(Conv2d(1, 32, (kernel_size, 1), (stride, 1), padding=(get_padding(kernel_size, 1), 0))),
|
131 |
+
norm_f(Conv2d(32, 128, (kernel_size, 1), (stride, 1), padding=(get_padding(kernel_size, 1), 0))),
|
132 |
+
norm_f(Conv2d(128, 512, (kernel_size, 1), (stride, 1), padding=(get_padding(kernel_size, 1), 0))),
|
133 |
+
norm_f(Conv2d(512, 1024, (kernel_size, 1), (stride, 1), padding=(get_padding(kernel_size, 1), 0))),
|
134 |
+
norm_f(Conv2d(1024, 1024, (kernel_size, 1), 1, padding=(get_padding(kernel_size, 1), 0))),
|
135 |
+
])
|
136 |
+
self.conv_post = norm_f(Conv2d(1024, 1, (3, 1), 1, padding=(1, 0)))
|
137 |
+
|
138 |
+
def forward(self, x):
|
139 |
+
fmap = []
|
140 |
+
|
141 |
+
# 1d to 2d
|
142 |
+
b, c, t = x.shape
|
143 |
+
if t % self.period != 0: # pad first
|
144 |
+
n_pad = self.period - (t % self.period)
|
145 |
+
x = F.pad(x, (0, n_pad), "reflect")
|
146 |
+
t = t + n_pad
|
147 |
+
x = x.view(b, c, t // self.period, self.period)
|
148 |
+
|
149 |
+
for l in self.convs:
|
150 |
+
x = l(x)
|
151 |
+
x = F.leaky_relu(x, modules.LRELU_SLOPE)
|
152 |
+
fmap.append(x)
|
153 |
+
x = self.conv_post(x)
|
154 |
+
fmap.append(x)
|
155 |
+
x = torch.flatten(x, 1, -1)
|
156 |
+
|
157 |
+
return x, fmap
|
158 |
+
|
159 |
+
|
160 |
+
class DiscriminatorS(torch.nn.Module):
|
161 |
+
def __init__(self, use_spectral_norm=False):
|
162 |
+
super(DiscriminatorS, self).__init__()
|
163 |
+
norm_f = weight_norm if use_spectral_norm == False else spectral_norm
|
164 |
+
self.convs = nn.ModuleList([
|
165 |
+
norm_f(Conv1d(1, 16, 15, 1, padding=7)),
|
166 |
+
norm_f(Conv1d(16, 64, 41, 4, groups=4, padding=20)),
|
167 |
+
norm_f(Conv1d(64, 256, 41, 4, groups=16, padding=20)),
|
168 |
+
norm_f(Conv1d(256, 1024, 41, 4, groups=64, padding=20)),
|
169 |
+
norm_f(Conv1d(1024, 1024, 41, 4, groups=256, padding=20)),
|
170 |
+
norm_f(Conv1d(1024, 1024, 5, 1, padding=2)),
|
171 |
+
])
|
172 |
+
self.conv_post = norm_f(Conv1d(1024, 1, 3, 1, padding=1))
|
173 |
+
|
174 |
+
def forward(self, x):
|
175 |
+
fmap = []
|
176 |
+
|
177 |
+
for l in self.convs:
|
178 |
+
x = l(x)
|
179 |
+
x = F.leaky_relu(x, modules.LRELU_SLOPE)
|
180 |
+
fmap.append(x)
|
181 |
+
x = self.conv_post(x)
|
182 |
+
fmap.append(x)
|
183 |
+
x = torch.flatten(x, 1, -1)
|
184 |
+
|
185 |
+
return x, fmap
|
186 |
+
|
187 |
+
|
188 |
+
class MultiPeriodDiscriminator(torch.nn.Module):
|
189 |
+
def __init__(self, use_spectral_norm=False):
|
190 |
+
super(MultiPeriodDiscriminator, self).__init__()
|
191 |
+
periods = [2,3,5,7,11]
|
192 |
+
|
193 |
+
discs = [DiscriminatorS(use_spectral_norm=use_spectral_norm)]
|
194 |
+
discs = discs + [DiscriminatorP(i, use_spectral_norm=use_spectral_norm) for i in periods]
|
195 |
+
self.discriminators = nn.ModuleList(discs)
|
196 |
+
|
197 |
+
def forward(self, y, y_hat):
|
198 |
+
y_d_rs = []
|
199 |
+
y_d_gs = []
|
200 |
+
fmap_rs = []
|
201 |
+
fmap_gs = []
|
202 |
+
for i, d in enumerate(self.discriminators):
|
203 |
+
y_d_r, fmap_r = d(y)
|
204 |
+
y_d_g, fmap_g = d(y_hat)
|
205 |
+
y_d_rs.append(y_d_r)
|
206 |
+
y_d_gs.append(y_d_g)
|
207 |
+
fmap_rs.append(fmap_r)
|
208 |
+
fmap_gs.append(fmap_g)
|
209 |
+
|
210 |
+
return y_d_rs, y_d_gs, fmap_rs, fmap_gs
|
211 |
+
|
212 |
+
|
213 |
+
class SpeakerEncoder(torch.nn.Module):
|
214 |
+
def __init__(self, mel_n_channels=80, model_num_layers=3, model_hidden_size=256, model_embedding_size=256):
|
215 |
+
super(SpeakerEncoder, self).__init__()
|
216 |
+
self.lstm = nn.LSTM(mel_n_channels, model_hidden_size, model_num_layers, batch_first=True)
|
217 |
+
self.linear = nn.Linear(model_hidden_size, model_embedding_size)
|
218 |
+
self.relu = nn.ReLU()
|
219 |
+
|
220 |
+
def forward(self, mels):
|
221 |
+
self.lstm.flatten_parameters()
|
222 |
+
_, (hidden, _) = self.lstm(mels)
|
223 |
+
embeds_raw = self.relu(self.linear(hidden[-1]))
|
224 |
+
return embeds_raw / torch.norm(embeds_raw, dim=1, keepdim=True)
|
225 |
+
|
226 |
+
def compute_partial_slices(self, total_frames, partial_frames, partial_hop):
|
227 |
+
mel_slices = []
|
228 |
+
for i in range(0, total_frames-partial_frames, partial_hop):
|
229 |
+
mel_range = torch.arange(i, i+partial_frames)
|
230 |
+
mel_slices.append(mel_range)
|
231 |
+
|
232 |
+
return mel_slices
|
233 |
+
|
234 |
+
def embed_utterance(self, mel, partial_frames=128, partial_hop=64):
|
235 |
+
mel_len = mel.size(1)
|
236 |
+
last_mel = mel[:,-partial_frames:]
|
237 |
+
|
238 |
+
if mel_len > partial_frames:
|
239 |
+
mel_slices = self.compute_partial_slices(mel_len, partial_frames, partial_hop)
|
240 |
+
mels = list(mel[:,s] for s in mel_slices)
|
241 |
+
mels.append(last_mel)
|
242 |
+
mels = torch.stack(tuple(mels), 0).squeeze(1)
|
243 |
+
|
244 |
+
with torch.no_grad():
|
245 |
+
partial_embeds = self(mels)
|
246 |
+
embed = torch.mean(partial_embeds, axis=0).unsqueeze(0)
|
247 |
+
#embed = embed / torch.linalg.norm(embed, 2)
|
248 |
+
else:
|
249 |
+
with torch.no_grad():
|
250 |
+
embed = self(last_mel)
|
251 |
+
|
252 |
+
return embed
|
253 |
+
|
254 |
+
class F0Decoder(nn.Module):
|
255 |
+
def __init__(self,
|
256 |
+
out_channels,
|
257 |
+
hidden_channels,
|
258 |
+
filter_channels,
|
259 |
+
n_heads,
|
260 |
+
n_layers,
|
261 |
+
kernel_size,
|
262 |
+
p_dropout,
|
263 |
+
spk_channels=0):
|
264 |
+
super().__init__()
|
265 |
+
self.out_channels = out_channels
|
266 |
+
self.hidden_channels = hidden_channels
|
267 |
+
self.filter_channels = filter_channels
|
268 |
+
self.n_heads = n_heads
|
269 |
+
self.n_layers = n_layers
|
270 |
+
self.kernel_size = kernel_size
|
271 |
+
self.p_dropout = p_dropout
|
272 |
+
self.spk_channels = spk_channels
|
273 |
+
|
274 |
+
self.prenet = nn.Conv1d(hidden_channels, hidden_channels, 3, padding=1)
|
275 |
+
self.decoder = attentions.FFT(
|
276 |
+
hidden_channels,
|
277 |
+
filter_channels,
|
278 |
+
n_heads,
|
279 |
+
n_layers,
|
280 |
+
kernel_size,
|
281 |
+
p_dropout)
|
282 |
+
self.proj = nn.Conv1d(hidden_channels, out_channels, 1)
|
283 |
+
self.f0_prenet = nn.Conv1d(1, hidden_channels , 3, padding=1)
|
284 |
+
self.cond = nn.Conv1d(spk_channels, hidden_channels, 1)
|
285 |
+
|
286 |
+
def forward(self, x, norm_f0, x_mask, spk_emb=None):
|
287 |
+
x = torch.detach(x)
|
288 |
+
if (spk_emb is not None):
|
289 |
+
x = x + self.cond(spk_emb)
|
290 |
+
x += self.f0_prenet(norm_f0)
|
291 |
+
x = self.prenet(x) * x_mask
|
292 |
+
x = self.decoder(x * x_mask, x_mask)
|
293 |
+
x = self.proj(x) * x_mask
|
294 |
+
return x
|
295 |
+
|
296 |
+
|
297 |
+
class SynthesizerTrn(nn.Module):
|
298 |
+
"""
|
299 |
+
Synthesizer for Training
|
300 |
+
"""
|
301 |
+
|
302 |
+
def __init__(self,
|
303 |
+
spec_channels,
|
304 |
+
segment_size,
|
305 |
+
inter_channels,
|
306 |
+
hidden_channels,
|
307 |
+
filter_channels,
|
308 |
+
n_heads,
|
309 |
+
n_layers,
|
310 |
+
kernel_size,
|
311 |
+
p_dropout,
|
312 |
+
resblock,
|
313 |
+
resblock_kernel_sizes,
|
314 |
+
resblock_dilation_sizes,
|
315 |
+
upsample_rates,
|
316 |
+
upsample_initial_channel,
|
317 |
+
upsample_kernel_sizes,
|
318 |
+
gin_channels,
|
319 |
+
ssl_dim,
|
320 |
+
n_speakers,
|
321 |
+
sampling_rate=44100,
|
322 |
+
**kwargs):
|
323 |
+
|
324 |
+
super().__init__()
|
325 |
+
self.spec_channels = spec_channels
|
326 |
+
self.inter_channels = inter_channels
|
327 |
+
self.hidden_channels = hidden_channels
|
328 |
+
self.filter_channels = filter_channels
|
329 |
+
self.n_heads = n_heads
|
330 |
+
self.n_layers = n_layers
|
331 |
+
self.kernel_size = kernel_size
|
332 |
+
self.p_dropout = p_dropout
|
333 |
+
self.resblock = resblock
|
334 |
+
self.resblock_kernel_sizes = resblock_kernel_sizes
|
335 |
+
self.resblock_dilation_sizes = resblock_dilation_sizes
|
336 |
+
self.upsample_rates = upsample_rates
|
337 |
+
self.upsample_initial_channel = upsample_initial_channel
|
338 |
+
self.upsample_kernel_sizes = upsample_kernel_sizes
|
339 |
+
self.segment_size = segment_size
|
340 |
+
self.gin_channels = gin_channels
|
341 |
+
self.ssl_dim = ssl_dim
|
342 |
+
self.emb_g = nn.Embedding(n_speakers, gin_channels)
|
343 |
+
|
344 |
+
self.pre = nn.Conv1d(ssl_dim, hidden_channels, kernel_size=5, padding=2)
|
345 |
+
|
346 |
+
self.enc_p = TextEncoder(
|
347 |
+
inter_channels,
|
348 |
+
hidden_channels,
|
349 |
+
filter_channels=filter_channels,
|
350 |
+
n_heads=n_heads,
|
351 |
+
n_layers=n_layers,
|
352 |
+
kernel_size=kernel_size,
|
353 |
+
p_dropout=p_dropout
|
354 |
+
)
|
355 |
+
hps = {
|
356 |
+
"sampling_rate": sampling_rate,
|
357 |
+
"inter_channels": inter_channels,
|
358 |
+
"resblock": resblock,
|
359 |
+
"resblock_kernel_sizes": resblock_kernel_sizes,
|
360 |
+
"resblock_dilation_sizes": resblock_dilation_sizes,
|
361 |
+
"upsample_rates": upsample_rates,
|
362 |
+
"upsample_initial_channel": upsample_initial_channel,
|
363 |
+
"upsample_kernel_sizes": upsample_kernel_sizes,
|
364 |
+
"gin_channels": gin_channels,
|
365 |
+
}
|
366 |
+
self.dec = Generator(h=hps)
|
367 |
+
self.enc_q = Encoder(spec_channels, inter_channels, hidden_channels, 5, 1, 16, gin_channels=gin_channels)
|
368 |
+
self.flow = ResidualCouplingBlock(inter_channels, hidden_channels, 5, 1, 4, gin_channels=gin_channels)
|
369 |
+
self.f0_decoder = F0Decoder(
|
370 |
+
1,
|
371 |
+
hidden_channels,
|
372 |
+
filter_channels,
|
373 |
+
n_heads,
|
374 |
+
n_layers,
|
375 |
+
kernel_size,
|
376 |
+
p_dropout,
|
377 |
+
spk_channels=gin_channels
|
378 |
+
)
|
379 |
+
self.emb_uv = nn.Embedding(2, hidden_channels)
|
380 |
+
|
381 |
+
def forward(self, c, f0, uv, spec, g=None, c_lengths=None, spec_lengths=None):
|
382 |
+
g = self.emb_g(g).transpose(1,2)
|
383 |
+
# ssl prenet
|
384 |
+
x_mask = torch.unsqueeze(commons.sequence_mask(c_lengths, c.size(2)), 1).to(c.dtype)
|
385 |
+
x = self.pre(c) * x_mask + self.emb_uv(uv.long()).transpose(1,2)
|
386 |
+
|
387 |
+
# f0 predict
|
388 |
+
lf0 = 2595. * torch.log10(1. + f0.unsqueeze(1) / 700.) / 500
|
389 |
+
norm_lf0 = utils.normalize_f0(lf0, x_mask, uv)
|
390 |
+
pred_lf0 = self.f0_decoder(x, norm_lf0, x_mask, spk_emb=g)
|
391 |
+
|
392 |
+
# encoder
|
393 |
+
z_ptemp, m_p, logs_p, _ = self.enc_p(x, x_mask, f0=f0_to_coarse(f0))
|
394 |
+
z, m_q, logs_q, spec_mask = self.enc_q(spec, spec_lengths, g=g)
|
395 |
+
|
396 |
+
# flow
|
397 |
+
z_p = self.flow(z, spec_mask, g=g)
|
398 |
+
z_slice, pitch_slice, ids_slice = commons.rand_slice_segments_with_pitch(z, f0, spec_lengths, self.segment_size)
|
399 |
+
|
400 |
+
# nsf decoder
|
401 |
+
o = self.dec(z_slice, g=g, f0=pitch_slice)
|
402 |
+
|
403 |
+
return o, ids_slice, spec_mask, (z, z_p, m_p, logs_p, m_q, logs_q), pred_lf0, norm_lf0, lf0
|
404 |
+
|
405 |
+
def infer(self, c, f0, uv, g=None, noice_scale=0.35, predict_f0=False):
|
406 |
+
c_lengths = (torch.ones(c.size(0)) * c.size(-1)).to(c.device)
|
407 |
+
g = self.emb_g(g).transpose(1,2)
|
408 |
+
x_mask = torch.unsqueeze(commons.sequence_mask(c_lengths, c.size(2)), 1).to(c.dtype)
|
409 |
+
x = self.pre(c) * x_mask + self.emb_uv(uv.long()).transpose(1,2)
|
410 |
+
|
411 |
+
if predict_f0:
|
412 |
+
lf0 = 2595. * torch.log10(1. + f0.unsqueeze(1) / 700.) / 500
|
413 |
+
norm_lf0 = utils.normalize_f0(lf0, x_mask, uv, random_scale=False)
|
414 |
+
pred_lf0 = self.f0_decoder(x, norm_lf0, x_mask, spk_emb=g)
|
415 |
+
f0 = (700 * (torch.pow(10, pred_lf0 * 500 / 2595) - 1)).squeeze(1)
|
416 |
+
|
417 |
+
z_p, m_p, logs_p, c_mask = self.enc_p(x, x_mask, f0=f0_to_coarse(f0), noice_scale=noice_scale)
|
418 |
+
z = self.flow(z_p, c_mask, g=g, reverse=True)
|
419 |
+
o = self.dec(z * c_mask, g=g, f0=f0)
|
420 |
+
return o
|
models/alice/alice.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6d1bef76e26beeadcae5f716cc0b60abb2aac4aae1316cac709cc439726cf533
|
3 |
+
size 180883747
|
models/alice/config.json
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"train": {
|
3 |
+
"log_interval": 200,
|
4 |
+
"eval_interval": 800,
|
5 |
+
"seed": 1234,
|
6 |
+
"epochs": 10000,
|
7 |
+
"learning_rate": 0.0001,
|
8 |
+
"betas": [
|
9 |
+
0.8,
|
10 |
+
0.99
|
11 |
+
],
|
12 |
+
"eps": 1e-09,
|
13 |
+
"batch_size": 32,
|
14 |
+
"fp16_run": false,
|
15 |
+
"lr_decay": 0.999875,
|
16 |
+
"segment_size": 10240,
|
17 |
+
"init_lr_ratio": 1,
|
18 |
+
"warmup_epochs": 0,
|
19 |
+
"c_mel": 45,
|
20 |
+
"c_kl": 1.0,
|
21 |
+
"use_sr": true,
|
22 |
+
"max_speclen": 512,
|
23 |
+
"port": "8001",
|
24 |
+
"keep_ckpts": 99
|
25 |
+
},
|
26 |
+
"data": {
|
27 |
+
"training_files": "filelists/train.txt",
|
28 |
+
"validation_files": "filelists/val.txt",
|
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": 80,
|
35 |
+
"mel_fmin": 0.0,
|
36 |
+
"mel_fmax": 22050
|
37 |
+
},
|
38 |
+
"model": {
|
39 |
+
"inter_channels": 192,
|
40 |
+
"hidden_channels": 192,
|
41 |
+
"filter_channels": 768,
|
42 |
+
"n_heads": 2,
|
43 |
+
"n_layers": 6,
|
44 |
+
"kernel_size": 3,
|
45 |
+
"p_dropout": 0.1,
|
46 |
+
"resblock": "1",
|
47 |
+
"resblock_kernel_sizes": [
|
48 |
+
3,
|
49 |
+
7,
|
50 |
+
11
|
51 |
+
],
|
52 |
+
"resblock_dilation_sizes": [
|
53 |
+
[
|
54 |
+
1,
|
55 |
+
3,
|
56 |
+
5
|
57 |
+
],
|
58 |
+
[
|
59 |
+
1,
|
60 |
+
3,
|
61 |
+
5
|
62 |
+
],
|
63 |
+
[
|
64 |
+
1,
|
65 |
+
3,
|
66 |
+
5
|
67 |
+
]
|
68 |
+
],
|
69 |
+
"upsample_rates": [
|
70 |
+
8,
|
71 |
+
8,
|
72 |
+
2,
|
73 |
+
2,
|
74 |
+
2
|
75 |
+
],
|
76 |
+
"upsample_initial_channel": 512,
|
77 |
+
"upsample_kernel_sizes": [
|
78 |
+
16,
|
79 |
+
16,
|
80 |
+
4,
|
81 |
+
4,
|
82 |
+
4
|
83 |
+
],
|
84 |
+
"n_layers_q": 3,
|
85 |
+
"use_spectral_norm": false,
|
86 |
+
"gin_channels": 256,
|
87 |
+
"ssl_dim": 256,
|
88 |
+
"n_speakers": 200
|
89 |
+
},
|
90 |
+
"spk": {
|
91 |
+
"alice": 0
|
92 |
+
}
|
93 |
+
}
|
models/alice/cover.png
ADDED
![]() |
models/goldship/config.json
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"train": {
|
3 |
+
"log_interval": 200,
|
4 |
+
"eval_interval": 800,
|
5 |
+
"seed": 1234,
|
6 |
+
"epochs": 10000,
|
7 |
+
"learning_rate": 0.0001,
|
8 |
+
"betas": [
|
9 |
+
0.8,
|
10 |
+
0.99
|
11 |
+
],
|
12 |
+
"eps": 1e-09,
|
13 |
+
"batch_size": 32,
|
14 |
+
"fp16_run": false,
|
15 |
+
"lr_decay": 0.999875,
|
16 |
+
"segment_size": 10240,
|
17 |
+
"init_lr_ratio": 1,
|
18 |
+
"warmup_epochs": 0,
|
19 |
+
"c_mel": 45,
|
20 |
+
"c_kl": 1.0,
|
21 |
+
"use_sr": true,
|
22 |
+
"max_speclen": 512,
|
23 |
+
"port": "8001",
|
24 |
+
"keep_ckpts": 99
|
25 |
+
},
|
26 |
+
"data": {
|
27 |
+
"training_files": "filelists/train.txt",
|
28 |
+
"validation_files": "filelists/val.txt",
|
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": 80,
|
35 |
+
"mel_fmin": 0.0,
|
36 |
+
"mel_fmax": 22050
|
37 |
+
},
|
38 |
+
"model": {
|
39 |
+
"inter_channels": 192,
|
40 |
+
"hidden_channels": 192,
|
41 |
+
"filter_channels": 768,
|
42 |
+
"n_heads": 2,
|
43 |
+
"n_layers": 6,
|
44 |
+
"kernel_size": 3,
|
45 |
+
"p_dropout": 0.1,
|
46 |
+
"resblock": "1",
|
47 |
+
"resblock_kernel_sizes": [
|
48 |
+
3,
|
49 |
+
7,
|
50 |
+
11
|
51 |
+
],
|
52 |
+
"resblock_dilation_sizes": [
|
53 |
+
[
|
54 |
+
1,
|
55 |
+
3,
|
56 |
+
5
|
57 |
+
],
|
58 |
+
[
|
59 |
+
1,
|
60 |
+
3,
|
61 |
+
5
|
62 |
+
],
|
63 |
+
[
|
64 |
+
1,
|
65 |
+
3,
|
66 |
+
5
|
67 |
+
]
|
68 |
+
],
|
69 |
+
"upsample_rates": [
|
70 |
+
8,
|
71 |
+
8,
|
72 |
+
2,
|
73 |
+
2,
|
74 |
+
2
|
75 |
+
],
|
76 |
+
"upsample_initial_channel": 512,
|
77 |
+
"upsample_kernel_sizes": [
|
78 |
+
16,
|
79 |
+
16,
|
80 |
+
4,
|
81 |
+
4,
|
82 |
+
4
|
83 |
+
],
|
84 |
+
"n_layers_q": 3,
|
85 |
+
"use_spectral_norm": false,
|
86 |
+
"gin_channels": 256,
|
87 |
+
"ssl_dim": 256,
|
88 |
+
"n_speakers": 200
|
89 |
+
},
|
90 |
+
"spk": {
|
91 |
+
"goldship": 0
|
92 |
+
}
|
93 |
+
}
|
models/goldship/cover.png
ADDED
![]() |
models/goldship/goldship.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c91b69fa9dc4f101e80a9a64fddab15a68919dc2a3d0129d0d626ab31805dc9e
|
3 |
+
size 180883747
|
models/rudolf/config.json
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"train": {
|
3 |
+
"log_interval": 200,
|
4 |
+
"eval_interval": 800,
|
5 |
+
"seed": 1234,
|
6 |
+
"epochs": 10000,
|
7 |
+
"learning_rate": 0.0001,
|
8 |
+
"betas": [
|
9 |
+
0.8,
|
10 |
+
0.99
|
11 |
+
],
|
12 |
+
"eps": 1e-09,
|
13 |
+
"batch_size": 32,
|
14 |
+
"fp16_run": false,
|
15 |
+
"lr_decay": 0.999875,
|
16 |
+
"segment_size": 10240,
|
17 |
+
"init_lr_ratio": 1,
|
18 |
+
"warmup_epochs": 0,
|
19 |
+
"c_mel": 45,
|
20 |
+
"c_kl": 1.0,
|
21 |
+
"use_sr": true,
|
22 |
+
"max_speclen": 512,
|
23 |
+
"port": "8001",
|
24 |
+
"keep_ckpts": 99
|
25 |
+
},
|
26 |
+
"data": {
|
27 |
+
"training_files": "filelists/train.txt",
|
28 |
+
"validation_files": "filelists/val.txt",
|
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": 80,
|
35 |
+
"mel_fmin": 0.0,
|
36 |
+
"mel_fmax": 22050
|
37 |
+
},
|
38 |
+
"model": {
|
39 |
+
"inter_channels": 192,
|
40 |
+
"hidden_channels": 192,
|
41 |
+
"filter_channels": 768,
|
42 |
+
"n_heads": 2,
|
43 |
+
"n_layers": 6,
|
44 |
+
"kernel_size": 3,
|
45 |
+
"p_dropout": 0.1,
|
46 |
+
"resblock": "1",
|
47 |
+
"resblock_kernel_sizes": [
|
48 |
+
3,
|
49 |
+
7,
|
50 |
+
11
|
51 |
+
],
|
52 |
+
"resblock_dilation_sizes": [
|
53 |
+
[
|
54 |
+
1,
|
55 |
+
3,
|
56 |
+
5
|
57 |
+
],
|
58 |
+
[
|
59 |
+
1,
|
60 |
+
3,
|
61 |
+
5
|
62 |
+
],
|
63 |
+
[
|
64 |
+
1,
|
65 |
+
3,
|
66 |
+
5
|
67 |
+
]
|
68 |
+
],
|
69 |
+
"upsample_rates": [
|
70 |
+
8,
|
71 |
+
8,
|
72 |
+
2,
|
73 |
+
2,
|
74 |
+
2
|
75 |
+
],
|
76 |
+
"upsample_initial_channel": 512,
|
77 |
+
"upsample_kernel_sizes": [
|
78 |
+
16,
|
79 |
+
16,
|
80 |
+
4,
|
81 |
+
4,
|
82 |
+
4
|
83 |
+
],
|
84 |
+
"n_layers_q": 3,
|
85 |
+
"use_spectral_norm": false,
|
86 |
+
"gin_channels": 256,
|
87 |
+
"ssl_dim": 256,
|
88 |
+
"n_speakers": 200
|
89 |
+
},
|
90 |
+
"spk": {
|
91 |
+
"rudolf": 0
|
92 |
+
}
|
93 |
+
}
|
models/rudolf/cover.png
ADDED
![]() |
models/rudolf/rudolf.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0dc3027ae74f1747208c4c4c686dd65c7064899cce37d8d19e2e1eb7cb53df09
|
3 |
+
size 180883747
|
models/tannhauser/config.json
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"train": {
|
3 |
+
"log_interval": 200,
|
4 |
+
"eval_interval": 800,
|
5 |
+
"seed": 1234,
|
6 |
+
"epochs": 10000,
|
7 |
+
"learning_rate": 0.0001,
|
8 |
+
"betas": [
|
9 |
+
0.8,
|
10 |
+
0.99
|
11 |
+
],
|
12 |
+
"eps": 1e-09,
|
13 |
+
"batch_size": 32,
|
14 |
+
"fp16_run": false,
|
15 |
+
"lr_decay": 0.999875,
|
16 |
+
"segment_size": 10240,
|
17 |
+
"init_lr_ratio": 1,
|
18 |
+
"warmup_epochs": 0,
|
19 |
+
"c_mel": 45,
|
20 |
+
"c_kl": 1.0,
|
21 |
+
"use_sr": true,
|
22 |
+
"max_speclen": 512,
|
23 |
+
"port": "8001",
|
24 |
+
"keep_ckpts": 99
|
25 |
+
},
|
26 |
+
"data": {
|
27 |
+
"training_files": "filelists/train.txt",
|
28 |
+
"validation_files": "filelists/val.txt",
|
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": 80,
|
35 |
+
"mel_fmin": 0.0,
|
36 |
+
"mel_fmax": 22050
|
37 |
+
},
|
38 |
+
"model": {
|
39 |
+
"inter_channels": 192,
|
40 |
+
"hidden_channels": 192,
|
41 |
+
"filter_channels": 768,
|
42 |
+
"n_heads": 2,
|
43 |
+
"n_layers": 6,
|
44 |
+
"kernel_size": 3,
|
45 |
+
"p_dropout": 0.1,
|
46 |
+
"resblock": "1",
|
47 |
+
"resblock_kernel_sizes": [
|
48 |
+
3,
|
49 |
+
7,
|
50 |
+
11
|
51 |
+
],
|
52 |
+
"resblock_dilation_sizes": [
|
53 |
+
[
|
54 |
+
1,
|
55 |
+
3,
|
56 |
+
5
|
57 |
+
],
|
58 |
+
[
|
59 |
+
1,
|
60 |
+
3,
|
61 |
+
5
|
62 |
+
],
|
63 |
+
[
|
64 |
+
1,
|
65 |
+
3,
|
66 |
+
5
|
67 |
+
]
|
68 |
+
],
|
69 |
+
"upsample_rates": [
|
70 |
+
8,
|
71 |
+
8,
|
72 |
+
2,
|
73 |
+
2,
|
74 |
+
2
|
75 |
+
],
|
76 |
+
"upsample_initial_channel": 512,
|
77 |
+
"upsample_kernel_sizes": [
|
78 |
+
16,
|
79 |
+
16,
|
80 |
+
4,
|
81 |
+
4,
|
82 |
+
4
|
83 |
+
],
|
84 |
+
"n_layers_q": 3,
|
85 |
+
"use_spectral_norm": false,
|
86 |
+
"gin_channels": 256,
|
87 |
+
"ssl_dim": 256,
|
88 |
+
"n_speakers": 200
|
89 |
+
},
|
90 |
+
"spk": {
|
91 |
+
"tannhauser": 0
|
92 |
+
}
|
93 |
+
}
|
models/tannhauser/cover.png
ADDED
![]() |
models/tannhauser/tannhauser.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a39d57f9e5ae1eba070eb782df6355699ff93f680b075f99c45613ad590035ef
|
3 |
+
size 180883747
|
models/teio/config.json
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"train": {
|
3 |
+
"log_interval": 200,
|
4 |
+
"eval_interval": 800,
|
5 |
+
"seed": 1234,
|
6 |
+
"epochs": 10000,
|
7 |
+
"learning_rate": 0.0001,
|
8 |
+
"betas": [
|
9 |
+
0.8,
|
10 |
+
0.99
|
11 |
+
],
|
12 |
+
"eps": 1e-09,
|
13 |
+
"batch_size": 32,
|
14 |
+
"fp16_run": false,
|
15 |
+
"lr_decay": 0.999875,
|
16 |
+
"segment_size": 10240,
|
17 |
+
"init_lr_ratio": 1,
|
18 |
+
"warmup_epochs": 0,
|
19 |
+
"c_mel": 45,
|
20 |
+
"c_kl": 1.0,
|
21 |
+
"use_sr": true,
|
22 |
+
"max_speclen": 512,
|
23 |
+
"port": "8001",
|
24 |
+
"keep_ckpts": 99
|
25 |
+
},
|
26 |
+
"data": {
|
27 |
+
"training_files": "filelists/train.txt",
|
28 |
+
"validation_files": "filelists/val.txt",
|
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": 80,
|
35 |
+
"mel_fmin": 0.0,
|
36 |
+
"mel_fmax": 22050
|
37 |
+
},
|
38 |
+
"model": {
|
39 |
+
"inter_channels": 192,
|
40 |
+
"hidden_channels": 192,
|
41 |
+
"filter_channels": 768,
|
42 |
+
"n_heads": 2,
|
43 |
+
"n_layers": 6,
|
44 |
+
"kernel_size": 3,
|
45 |
+
"p_dropout": 0.1,
|
46 |
+
"resblock": "1",
|
47 |
+
"resblock_kernel_sizes": [
|
48 |
+
3,
|
49 |
+
7,
|
50 |
+
11
|
51 |
+
],
|
52 |
+
"resblock_dilation_sizes": [
|
53 |
+
[
|
54 |
+
1,
|
55 |
+
3,
|
56 |
+
5
|
57 |
+
],
|
58 |
+
[
|
59 |
+
1,
|
60 |
+
3,
|
61 |
+
5
|
62 |
+
],
|
63 |
+
[
|
64 |
+
1,
|
65 |
+
3,
|
66 |
+
5
|
67 |
+
]
|
68 |
+
],
|
69 |
+
"upsample_rates": [
|
70 |
+
8,
|
71 |
+
8,
|
72 |
+
2,
|
73 |
+
2,
|
74 |
+
2
|
75 |
+
],
|
76 |
+
"upsample_initial_channel": 512,
|
77 |
+
"upsample_kernel_sizes": [
|
78 |
+
16,
|
79 |
+
16,
|
80 |
+
4,
|
81 |
+
4,
|
82 |
+
4
|
83 |
+
],
|
84 |
+
"n_layers_q": 3,
|
85 |
+
"use_spectral_norm": false,
|
86 |
+
"gin_channels": 256,
|
87 |
+
"ssl_dim": 256,
|
88 |
+
"n_speakers": 200
|
89 |
+
},
|
90 |
+
"spk": {
|
91 |
+
"teio": 0
|
92 |
+
}
|
93 |
+
}
|
models/teio/cover.png
ADDED
![]() |
models/teio/teio.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:305cbd8bc9bc468f2744d0fc425d1c7363a6232140728d403e90486dc2921160
|
3 |
+
size 180883747
|
modules/__init__.py
ADDED
File without changes
|
modules/__pycache__/__init__.cpython-38.pyc
ADDED
Binary file (155 Bytes). View file
|
|
modules/__pycache__/attentions.cpython-38.pyc
ADDED
Binary file (10.7 kB). View file
|
|
modules/__pycache__/commons.cpython-38.pyc
ADDED
Binary file (6.65 kB). View file
|
|
modules/__pycache__/modules.cpython-38.pyc
ADDED
Binary file (10.1 kB). View file
|
|
modules/attentions.py
ADDED
@@ -0,0 +1,349 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import copy
|
2 |
+
import math
|
3 |
+
import numpy as np
|
4 |
+
import torch
|
5 |
+
from torch import nn
|
6 |
+
from torch.nn import functional as F
|
7 |
+
|
8 |
+
import modules.commons as commons
|
9 |
+
import modules.modules as modules
|
10 |
+
from modules.modules import LayerNorm
|
11 |
+
|
12 |
+
|
13 |
+
class FFT(nn.Module):
|
14 |
+
def __init__(self, hidden_channels, filter_channels, n_heads, n_layers=1, kernel_size=1, p_dropout=0.,
|
15 |
+
proximal_bias=False, proximal_init=True, **kwargs):
|
16 |
+
super().__init__()
|
17 |
+
self.hidden_channels = hidden_channels
|
18 |
+
self.filter_channels = filter_channels
|
19 |
+
self.n_heads = n_heads
|
20 |
+
self.n_layers = n_layers
|
21 |
+
self.kernel_size = kernel_size
|
22 |
+
self.p_dropout = p_dropout
|
23 |
+
self.proximal_bias = proximal_bias
|
24 |
+
self.proximal_init = proximal_init
|
25 |
+
|
26 |
+
self.drop = nn.Dropout(p_dropout)
|
27 |
+
self.self_attn_layers = nn.ModuleList()
|
28 |
+
self.norm_layers_0 = nn.ModuleList()
|
29 |
+
self.ffn_layers = nn.ModuleList()
|
30 |
+
self.norm_layers_1 = nn.ModuleList()
|
31 |
+
for i in range(self.n_layers):
|
32 |
+
self.self_attn_layers.append(
|
33 |
+
MultiHeadAttention(hidden_channels, hidden_channels, n_heads, p_dropout=p_dropout, proximal_bias=proximal_bias,
|
34 |
+
proximal_init=proximal_init))
|
35 |
+
self.norm_layers_0.append(LayerNorm(hidden_channels))
|
36 |
+
self.ffn_layers.append(
|
37 |
+
FFN(hidden_channels, hidden_channels, filter_channels, kernel_size, p_dropout=p_dropout, causal=True))
|
38 |
+
self.norm_layers_1.append(LayerNorm(hidden_channels))
|
39 |
+
|
40 |
+
def forward(self, x, x_mask):
|
41 |
+
"""
|
42 |
+
x: decoder input
|
43 |
+
h: encoder output
|
44 |
+
"""
|
45 |
+
self_attn_mask = commons.subsequent_mask(x_mask.size(2)).to(device=x.device, dtype=x.dtype)
|
46 |
+
x = x * x_mask
|
47 |
+
for i in range(self.n_layers):
|
48 |
+
y = self.self_attn_layers[i](x, x, self_attn_mask)
|
49 |
+
y = self.drop(y)
|
50 |
+
x = self.norm_layers_0[i](x + y)
|
51 |
+
|
52 |
+
y = self.ffn_layers[i](x, x_mask)
|
53 |
+
y = self.drop(y)
|
54 |
+
x = self.norm_layers_1[i](x + y)
|
55 |
+
x = x * x_mask
|
56 |
+
return x
|
57 |
+
|
58 |
+
|
59 |
+
class Encoder(nn.Module):
|
60 |
+
def __init__(self, hidden_channels, filter_channels, n_heads, n_layers, kernel_size=1, p_dropout=0., window_size=4, **kwargs):
|
61 |
+
super().__init__()
|
62 |
+
self.hidden_channels = hidden_channels
|
63 |
+
self.filter_channels = filter_channels
|
64 |
+
self.n_heads = n_heads
|
65 |
+
self.n_layers = n_layers
|
66 |
+
self.kernel_size = kernel_size
|
67 |
+
self.p_dropout = p_dropout
|
68 |
+
self.window_size = window_size
|
69 |
+
|
70 |
+
self.drop = nn.Dropout(p_dropout)
|
71 |
+
self.attn_layers = nn.ModuleList()
|
72 |
+
self.norm_layers_1 = nn.ModuleList()
|
73 |
+
self.ffn_layers = nn.ModuleList()
|
74 |
+
self.norm_layers_2 = nn.ModuleList()
|
75 |
+
for i in range(self.n_layers):
|
76 |
+
self.attn_layers.append(MultiHeadAttention(hidden_channels, hidden_channels, n_heads, p_dropout=p_dropout, window_size=window_size))
|
77 |
+
self.norm_layers_1.append(LayerNorm(hidden_channels))
|
78 |
+
self.ffn_layers.append(FFN(hidden_channels, hidden_channels, filter_channels, kernel_size, p_dropout=p_dropout))
|
79 |
+
self.norm_layers_2.append(LayerNorm(hidden_channels))
|
80 |
+
|
81 |
+
def forward(self, x, x_mask):
|
82 |
+
attn_mask = x_mask.unsqueeze(2) * x_mask.unsqueeze(-1)
|
83 |
+
x = x * x_mask
|
84 |
+
for i in range(self.n_layers):
|
85 |
+
y = self.attn_layers[i](x, x, attn_mask)
|
86 |
+
y = self.drop(y)
|
87 |
+
x = self.norm_layers_1[i](x + y)
|
88 |
+
|
89 |
+
y = self.ffn_layers[i](x, x_mask)
|
90 |
+
y = self.drop(y)
|
91 |
+
x = self.norm_layers_2[i](x + y)
|
92 |
+
x = x * x_mask
|
93 |
+
return x
|
94 |
+
|
95 |
+
|
96 |
+
class Decoder(nn.Module):
|
97 |
+
def __init__(self, hidden_channels, filter_channels, n_heads, n_layers, kernel_size=1, p_dropout=0., proximal_bias=False, proximal_init=True, **kwargs):
|
98 |
+
super().__init__()
|
99 |
+
self.hidden_channels = hidden_channels
|
100 |
+
self.filter_channels = filter_channels
|
101 |
+
self.n_heads = n_heads
|
102 |
+
self.n_layers = n_layers
|
103 |
+
self.kernel_size = kernel_size
|
104 |
+
self.p_dropout = p_dropout
|
105 |
+
self.proximal_bias = proximal_bias
|
106 |
+
self.proximal_init = proximal_init
|
107 |
+
|
108 |
+
self.drop = nn.Dropout(p_dropout)
|
109 |
+
self.self_attn_layers = nn.ModuleList()
|
110 |
+
self.norm_layers_0 = nn.ModuleList()
|
111 |
+
self.encdec_attn_layers = nn.ModuleList()
|
112 |
+
self.norm_layers_1 = nn.ModuleList()
|
113 |
+
self.ffn_layers = nn.ModuleList()
|
114 |
+
self.norm_layers_2 = nn.ModuleList()
|
115 |
+
for i in range(self.n_layers):
|
116 |
+
self.self_attn_layers.append(MultiHeadAttention(hidden_channels, hidden_channels, n_heads, p_dropout=p_dropout, proximal_bias=proximal_bias, proximal_init=proximal_init))
|
117 |
+
self.norm_layers_0.append(LayerNorm(hidden_channels))
|
118 |
+
self.encdec_attn_layers.append(MultiHeadAttention(hidden_channels, hidden_channels, n_heads, p_dropout=p_dropout))
|
119 |
+
self.norm_layers_1.append(LayerNorm(hidden_channels))
|
120 |
+
self.ffn_layers.append(FFN(hidden_channels, hidden_channels, filter_channels, kernel_size, p_dropout=p_dropout, causal=True))
|
121 |
+
self.norm_layers_2.append(LayerNorm(hidden_channels))
|
122 |
+
|
123 |
+
def forward(self, x, x_mask, h, h_mask):
|
124 |
+
"""
|
125 |
+
x: decoder input
|
126 |
+
h: encoder output
|
127 |
+
"""
|
128 |
+
self_attn_mask = commons.subsequent_mask(x_mask.size(2)).to(device=x.device, dtype=x.dtype)
|
129 |
+
encdec_attn_mask = h_mask.unsqueeze(2) * x_mask.unsqueeze(-1)
|
130 |
+
x = x * x_mask
|
131 |
+
for i in range(self.n_layers):
|
132 |
+
y = self.self_attn_layers[i](x, x, self_attn_mask)
|
133 |
+
y = self.drop(y)
|
134 |
+
x = self.norm_layers_0[i](x + y)
|
135 |
+
|
136 |
+
y = self.encdec_attn_layers[i](x, h, encdec_attn_mask)
|
137 |
+
y = self.drop(y)
|
138 |
+
x = self.norm_layers_1[i](x + y)
|
139 |
+
|
140 |
+
y = self.ffn_layers[i](x, x_mask)
|
141 |
+
y = self.drop(y)
|
142 |
+
x = self.norm_layers_2[i](x + y)
|
143 |
+
x = x * x_mask
|
144 |
+
return x
|
145 |
+
|
146 |
+
|
147 |
+
class MultiHeadAttention(nn.Module):
|
148 |
+
def __init__(self, channels, out_channels, n_heads, p_dropout=0., window_size=None, heads_share=True, block_length=None, proximal_bias=False, proximal_init=False):
|
149 |
+
super().__init__()
|
150 |
+
assert channels % n_heads == 0
|
151 |
+
|
152 |
+
self.channels = channels
|
153 |
+
self.out_channels = out_channels
|
154 |
+
self.n_heads = n_heads
|
155 |
+
self.p_dropout = p_dropout
|
156 |
+
self.window_size = window_size
|
157 |
+
self.heads_share = heads_share
|
158 |
+
self.block_length = block_length
|
159 |
+
self.proximal_bias = proximal_bias
|
160 |
+
self.proximal_init = proximal_init
|
161 |
+
self.attn = None
|
162 |
+
|
163 |
+
self.k_channels = channels // n_heads
|
164 |
+
self.conv_q = nn.Conv1d(channels, channels, 1)
|
165 |
+
self.conv_k = nn.Conv1d(channels, channels, 1)
|
166 |
+
self.conv_v = nn.Conv1d(channels, channels, 1)
|
167 |
+
self.conv_o = nn.Conv1d(channels, out_channels, 1)
|
168 |
+
self.drop = nn.Dropout(p_dropout)
|
169 |
+
|
170 |
+
if window_size is not None:
|
171 |
+
n_heads_rel = 1 if heads_share else n_heads
|
172 |
+
rel_stddev = self.k_channels**-0.5
|
173 |
+
self.emb_rel_k = nn.Parameter(torch.randn(n_heads_rel, window_size * 2 + 1, self.k_channels) * rel_stddev)
|
174 |
+
self.emb_rel_v = nn.Parameter(torch.randn(n_heads_rel, window_size * 2 + 1, self.k_channels) * rel_stddev)
|
175 |
+
|
176 |
+
nn.init.xavier_uniform_(self.conv_q.weight)
|
177 |
+
nn.init.xavier_uniform_(self.conv_k.weight)
|
178 |
+
nn.init.xavier_uniform_(self.conv_v.weight)
|
179 |
+
if proximal_init:
|
180 |
+
with torch.no_grad():
|
181 |
+
self.conv_k.weight.copy_(self.conv_q.weight)
|
182 |
+
self.conv_k.bias.copy_(self.conv_q.bias)
|
183 |
+
|
184 |
+
def forward(self, x, c, attn_mask=None):
|
185 |
+
q = self.conv_q(x)
|
186 |
+
k = self.conv_k(c)
|
187 |
+
v = self.conv_v(c)
|
188 |
+
|
189 |
+
x, self.attn = self.attention(q, k, v, mask=attn_mask)
|
190 |
+
|
191 |
+
x = self.conv_o(x)
|
192 |
+
return x
|
193 |
+
|
194 |
+
def attention(self, query, key, value, mask=None):
|
195 |
+
# reshape [b, d, t] -> [b, n_h, t, d_k]
|
196 |
+
b, d, t_s, t_t = (*key.size(), query.size(2))
|
197 |
+
query = query.view(b, self.n_heads, self.k_channels, t_t).transpose(2, 3)
|
198 |
+
key = key.view(b, self.n_heads, self.k_channels, t_s).transpose(2, 3)
|
199 |
+
value = value.view(b, self.n_heads, self.k_channels, t_s).transpose(2, 3)
|
200 |
+
|
201 |
+
scores = torch.matmul(query / math.sqrt(self.k_channels), key.transpose(-2, -1))
|
202 |
+
if self.window_size is not None:
|
203 |
+
assert t_s == t_t, "Relative attention is only available for self-attention."
|
204 |
+
key_relative_embeddings = self._get_relative_embeddings(self.emb_rel_k, t_s)
|
205 |
+
rel_logits = self._matmul_with_relative_keys(query /math.sqrt(self.k_channels), key_relative_embeddings)
|
206 |
+
scores_local = self._relative_position_to_absolute_position(rel_logits)
|
207 |
+
scores = scores + scores_local
|
208 |
+
if self.proximal_bias:
|
209 |
+
assert t_s == t_t, "Proximal bias is only available for self-attention."
|
210 |
+
scores = scores + self._attention_bias_proximal(t_s).to(device=scores.device, dtype=scores.dtype)
|
211 |
+
if mask is not None:
|
212 |
+
scores = scores.masked_fill(mask == 0, -1e4)
|
213 |
+
if self.block_length is not None:
|
214 |
+
assert t_s == t_t, "Local attention is only available for self-attention."
|
215 |
+
block_mask = torch.ones_like(scores).triu(-self.block_length).tril(self.block_length)
|
216 |
+
scores = scores.masked_fill(block_mask == 0, -1e4)
|
217 |
+
p_attn = F.softmax(scores, dim=-1) # [b, n_h, t_t, t_s]
|
218 |
+
p_attn = self.drop(p_attn)
|
219 |
+
output = torch.matmul(p_attn, value)
|
220 |
+
if self.window_size is not None:
|
221 |
+
relative_weights = self._absolute_position_to_relative_position(p_attn)
|
222 |
+
value_relative_embeddings = self._get_relative_embeddings(self.emb_rel_v, t_s)
|
223 |
+
output = output + self._matmul_with_relative_values(relative_weights, value_relative_embeddings)
|
224 |
+
output = output.transpose(2, 3).contiguous().view(b, d, t_t) # [b, n_h, t_t, d_k] -> [b, d, t_t]
|
225 |
+
return output, p_attn
|
226 |
+
|
227 |
+
def _matmul_with_relative_values(self, x, y):
|
228 |
+
"""
|
229 |
+
x: [b, h, l, m]
|
230 |
+
y: [h or 1, m, d]
|
231 |
+
ret: [b, h, l, d]
|
232 |
+
"""
|
233 |
+
ret = torch.matmul(x, y.unsqueeze(0))
|
234 |
+
return ret
|
235 |
+
|
236 |
+
def _matmul_with_relative_keys(self, x, y):
|
237 |
+
"""
|
238 |
+
x: [b, h, l, d]
|
239 |
+
y: [h or 1, m, d]
|
240 |
+
ret: [b, h, l, m]
|
241 |
+
"""
|
242 |
+
ret = torch.matmul(x, y.unsqueeze(0).transpose(-2, -1))
|
243 |
+
return ret
|
244 |
+
|
245 |
+
def _get_relative_embeddings(self, relative_embeddings, length):
|
246 |
+
max_relative_position = 2 * self.window_size + 1
|
247 |
+
# Pad first before slice to avoid using cond ops.
|
248 |
+
pad_length = max(length - (self.window_size + 1), 0)
|
249 |
+
slice_start_position = max((self.window_size + 1) - length, 0)
|
250 |
+
slice_end_position = slice_start_position + 2 * length - 1
|
251 |
+
if pad_length > 0:
|
252 |
+
padded_relative_embeddings = F.pad(
|
253 |
+
relative_embeddings,
|
254 |
+
commons.convert_pad_shape([[0, 0], [pad_length, pad_length], [0, 0]]))
|
255 |
+
else:
|
256 |
+
padded_relative_embeddings = relative_embeddings
|
257 |
+
used_relative_embeddings = padded_relative_embeddings[:,slice_start_position:slice_end_position]
|
258 |
+
return used_relative_embeddings
|
259 |
+
|
260 |
+
def _relative_position_to_absolute_position(self, x):
|
261 |
+
"""
|
262 |
+
x: [b, h, l, 2*l-1]
|
263 |
+
ret: [b, h, l, l]
|
264 |
+
"""
|
265 |
+
batch, heads, length, _ = x.size()
|
266 |
+
# Concat columns of pad to shift from relative to absolute indexing.
|
267 |
+
x = F.pad(x, commons.convert_pad_shape([[0,0],[0,0],[0,0],[0,1]]))
|
268 |
+
|
269 |
+
# Concat extra elements so to add up to shape (len+1, 2*len-1).
|
270 |
+
x_flat = x.view([batch, heads, length * 2 * length])
|
271 |
+
x_flat = F.pad(x_flat, commons.convert_pad_shape([[0,0],[0,0],[0,length-1]]))
|
272 |
+
|
273 |
+
# Reshape and slice out the padded elements.
|
274 |
+
x_final = x_flat.view([batch, heads, length+1, 2*length-1])[:, :, :length, length-1:]
|
275 |
+
return x_final
|
276 |
+
|
277 |
+
def _absolute_position_to_relative_position(self, x):
|
278 |
+
"""
|
279 |
+
x: [b, h, l, l]
|
280 |
+
ret: [b, h, l, 2*l-1]
|
281 |
+
"""
|
282 |
+
batch, heads, length, _ = x.size()
|
283 |
+
# padd along column
|
284 |
+
x = F.pad(x, commons.convert_pad_shape([[0, 0], [0, 0], [0, 0], [0, length-1]]))
|
285 |
+
x_flat = x.view([batch, heads, length**2 + length*(length -1)])
|
286 |
+
# add 0's in the beginning that will skew the elements after reshape
|
287 |
+
x_flat = F.pad(x_flat, commons.convert_pad_shape([[0, 0], [0, 0], [length, 0]]))
|
288 |
+
x_final = x_flat.view([batch, heads, length, 2*length])[:,:,:,1:]
|
289 |
+
return x_final
|
290 |
+
|
291 |
+
def _attention_bias_proximal(self, length):
|
292 |
+
"""Bias for self-attention to encourage attention to close positions.
|
293 |
+
Args:
|
294 |
+
length: an integer scalar.
|
295 |
+
Returns:
|
296 |
+
a Tensor with shape [1, 1, length, length]
|
297 |
+
"""
|
298 |
+
r = torch.arange(length, dtype=torch.float32)
|
299 |
+
diff = torch.unsqueeze(r, 0) - torch.unsqueeze(r, 1)
|
300 |
+
return torch.unsqueeze(torch.unsqueeze(-torch.log1p(torch.abs(diff)), 0), 0)
|
301 |
+
|
302 |
+
|
303 |
+
class FFN(nn.Module):
|
304 |
+
def __init__(self, in_channels, out_channels, filter_channels, kernel_size, p_dropout=0., activation=None, causal=False):
|
305 |
+
super().__init__()
|
306 |
+
self.in_channels = in_channels
|
307 |
+
self.out_channels = out_channels
|
308 |
+
self.filter_channels = filter_channels
|
309 |
+
self.kernel_size = kernel_size
|
310 |
+
self.p_dropout = p_dropout
|
311 |
+
self.activation = activation
|
312 |
+
self.causal = causal
|
313 |
+
|
314 |
+
if causal:
|
315 |
+
self.padding = self._causal_padding
|
316 |
+
else:
|
317 |
+
self.padding = self._same_padding
|
318 |
+
|
319 |
+
self.conv_1 = nn.Conv1d(in_channels, filter_channels, kernel_size)
|
320 |
+
self.conv_2 = nn.Conv1d(filter_channels, out_channels, kernel_size)
|
321 |
+
self.drop = nn.Dropout(p_dropout)
|
322 |
+
|
323 |
+
def forward(self, x, x_mask):
|
324 |
+
x = self.conv_1(self.padding(x * x_mask))
|
325 |
+
if self.activation == "gelu":
|
326 |
+
x = x * torch.sigmoid(1.702 * x)
|
327 |
+
else:
|
328 |
+
x = torch.relu(x)
|
329 |
+
x = self.drop(x)
|
330 |
+
x = self.conv_2(self.padding(x * x_mask))
|
331 |
+
return x * x_mask
|
332 |
+
|
333 |
+
def _causal_padding(self, x):
|
334 |
+
if self.kernel_size == 1:
|
335 |
+
return x
|
336 |
+
pad_l = self.kernel_size - 1
|
337 |
+
pad_r = 0
|
338 |
+
padding = [[0, 0], [0, 0], [pad_l, pad_r]]
|
339 |
+
x = F.pad(x, commons.convert_pad_shape(padding))
|
340 |
+
return x
|
341 |
+
|
342 |
+
def _same_padding(self, x):
|
343 |
+
if self.kernel_size == 1:
|
344 |
+
return x
|
345 |
+
pad_l = (self.kernel_size - 1) // 2
|
346 |
+
pad_r = self.kernel_size // 2
|
347 |
+
padding = [[0, 0], [0, 0], [pad_l, pad_r]]
|
348 |
+
x = F.pad(x, commons.convert_pad_shape(padding))
|
349 |
+
return x
|
modules/commons.py
ADDED
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import math
|
2 |
+
import numpy as np
|
3 |
+
import torch
|
4 |
+
from torch import nn
|
5 |
+
from torch.nn import functional as F
|
6 |
+
|
7 |
+
def slice_pitch_segments(x, ids_str, segment_size=4):
|
8 |
+
ret = torch.zeros_like(x[:, :segment_size])
|
9 |
+
for i in range(x.size(0)):
|
10 |
+
idx_str = ids_str[i]
|
11 |
+
idx_end = idx_str + segment_size
|
12 |
+
ret[i] = x[i, idx_str:idx_end]
|
13 |
+
return ret
|
14 |
+
|
15 |
+
def rand_slice_segments_with_pitch(x, pitch, x_lengths=None, segment_size=4):
|
16 |
+
b, d, t = x.size()
|
17 |
+
if x_lengths is None:
|
18 |
+
x_lengths = t
|
19 |
+
ids_str_max = x_lengths - segment_size + 1
|
20 |
+
ids_str = (torch.rand([b]).to(device=x.device) * ids_str_max).to(dtype=torch.long)
|
21 |
+
ret = slice_segments(x, ids_str, segment_size)
|
22 |
+
ret_pitch = slice_pitch_segments(pitch, ids_str, segment_size)
|
23 |
+
return ret, ret_pitch, ids_str
|
24 |
+
|
25 |
+
def init_weights(m, mean=0.0, std=0.01):
|
26 |
+
classname = m.__class__.__name__
|
27 |
+
if classname.find("Conv") != -1:
|
28 |
+
m.weight.data.normal_(mean, std)
|
29 |
+
|
30 |
+
|
31 |
+
def get_padding(kernel_size, dilation=1):
|
32 |
+
return int((kernel_size*dilation - dilation)/2)
|
33 |
+
|
34 |
+
|
35 |
+
def convert_pad_shape(pad_shape):
|
36 |
+
l = pad_shape[::-1]
|
37 |
+
pad_shape = [item for sublist in l for item in sublist]
|
38 |
+
return pad_shape
|
39 |
+
|
40 |
+
|
41 |
+
def intersperse(lst, item):
|
42 |
+
result = [item] * (len(lst) * 2 + 1)
|
43 |
+
result[1::2] = lst
|
44 |
+
return result
|
45 |
+
|
46 |
+
|
47 |
+
def kl_divergence(m_p, logs_p, m_q, logs_q):
|
48 |
+
"""KL(P||Q)"""
|
49 |
+
kl = (logs_q - logs_p) - 0.5
|
50 |
+
kl += 0.5 * (torch.exp(2. * logs_p) + ((m_p - m_q)**2)) * torch.exp(-2. * logs_q)
|
51 |
+
return kl
|
52 |
+
|
53 |
+
|
54 |
+
def rand_gumbel(shape):
|
55 |
+
"""Sample from the Gumbel distribution, protect from overflows."""
|
56 |
+
uniform_samples = torch.rand(shape) * 0.99998 + 0.00001
|
57 |
+
return -torch.log(-torch.log(uniform_samples))
|
58 |
+
|
59 |
+
|
60 |
+
def rand_gumbel_like(x):
|
61 |
+
g = rand_gumbel(x.size()).to(dtype=x.dtype, device=x.device)
|
62 |
+
return g
|
63 |
+
|
64 |
+
|
65 |
+
def slice_segments(x, ids_str, segment_size=4):
|
66 |
+
ret = torch.zeros_like(x[:, :, :segment_size])
|
67 |
+
for i in range(x.size(0)):
|
68 |
+
idx_str = ids_str[i]
|
69 |
+
idx_end = idx_str + segment_size
|
70 |
+
ret[i] = x[i, :, idx_str:idx_end]
|
71 |
+
return ret
|
72 |
+
|
73 |
+
|
74 |
+
def rand_slice_segments(x, x_lengths=None, segment_size=4):
|
75 |
+
b, d, t = x.size()
|
76 |
+
if x_lengths is None:
|
77 |
+
x_lengths = t
|
78 |
+
ids_str_max = x_lengths - segment_size + 1
|
79 |
+
ids_str = (torch.rand([b]).to(device=x.device) * ids_str_max).to(dtype=torch.long)
|
80 |
+
ret = slice_segments(x, ids_str, segment_size)
|
81 |
+
return ret, ids_str
|
82 |
+
|
83 |
+
|
84 |
+
def rand_spec_segments(x, x_lengths=None, segment_size=4):
|
85 |
+
b, d, t = x.size()
|
86 |
+
if x_lengths is None:
|
87 |
+
x_lengths = t
|
88 |
+
ids_str_max = x_lengths - segment_size
|
89 |
+
ids_str = (torch.rand([b]).to(device=x.device) * ids_str_max).to(dtype=torch.long)
|
90 |
+
ret = slice_segments(x, ids_str, segment_size)
|
91 |
+
return ret, ids_str
|
92 |
+
|
93 |
+
|
94 |
+
def get_timing_signal_1d(
|
95 |
+
length, channels, min_timescale=1.0, max_timescale=1.0e4):
|
96 |
+
position = torch.arange(length, dtype=torch.float)
|
97 |
+
num_timescales = channels // 2
|
98 |
+
log_timescale_increment = (
|
99 |
+
math.log(float(max_timescale) / float(min_timescale)) /
|
100 |
+
(num_timescales - 1))
|
101 |
+
inv_timescales = min_timescale * torch.exp(
|
102 |
+
torch.arange(num_timescales, dtype=torch.float) * -log_timescale_increment)
|
103 |
+
scaled_time = position.unsqueeze(0) * inv_timescales.unsqueeze(1)
|
104 |
+
signal = torch.cat([torch.sin(scaled_time), torch.cos(scaled_time)], 0)
|
105 |
+
signal = F.pad(signal, [0, 0, 0, channels % 2])
|
106 |
+
signal = signal.view(1, channels, length)
|
107 |
+
return signal
|
108 |
+
|
109 |
+
|
110 |
+
def add_timing_signal_1d(x, min_timescale=1.0, max_timescale=1.0e4):
|
111 |
+
b, channels, length = x.size()
|
112 |
+
signal = get_timing_signal_1d(length, channels, min_timescale, max_timescale)
|
113 |
+
return x + signal.to(dtype=x.dtype, device=x.device)
|
114 |
+
|
115 |
+
|
116 |
+
def cat_timing_signal_1d(x, min_timescale=1.0, max_timescale=1.0e4, axis=1):
|
117 |
+
b, channels, length = x.size()
|
118 |
+
signal = get_timing_signal_1d(length, channels, min_timescale, max_timescale)
|
119 |
+
return torch.cat([x, signal.to(dtype=x.dtype, device=x.device)], axis)
|
120 |
+
|
121 |
+
|
122 |
+
def subsequent_mask(length):
|
123 |
+
mask = torch.tril(torch.ones(length, length)).unsqueeze(0).unsqueeze(0)
|
124 |
+
return mask
|
125 |
+
|
126 |
+
|
127 |
+
@torch.jit.script
|
128 |
+
def fused_add_tanh_sigmoid_multiply(input_a, input_b, n_channels):
|
129 |
+
n_channels_int = n_channels[0]
|
130 |
+
in_act = input_a + input_b
|
131 |
+
t_act = torch.tanh(in_act[:, :n_channels_int, :])
|
132 |
+
s_act = torch.sigmoid(in_act[:, n_channels_int:, :])
|
133 |
+
acts = t_act * s_act
|
134 |
+
return acts
|
135 |
+
|
136 |
+
|
137 |
+
def convert_pad_shape(pad_shape):
|
138 |
+
l = pad_shape[::-1]
|
139 |
+
pad_shape = [item for sublist in l for item in sublist]
|
140 |
+
return pad_shape
|
141 |
+
|
142 |
+
|
143 |
+
def shift_1d(x):
|
144 |
+
x = F.pad(x, convert_pad_shape([[0, 0], [0, 0], [1, 0]]))[:, :, :-1]
|
145 |
+
return x
|
146 |
+
|
147 |
+
|
148 |
+
def sequence_mask(length, max_length=None):
|
149 |
+
if max_length is None:
|
150 |
+
max_length = length.max()
|
151 |
+
x = torch.arange(max_length, dtype=length.dtype, device=length.device)
|
152 |
+
return x.unsqueeze(0) < length.unsqueeze(1)
|
153 |
+
|
154 |
+
|
155 |
+
def generate_path(duration, mask):
|
156 |
+
"""
|
157 |
+
duration: [b, 1, t_x]
|
158 |
+
mask: [b, 1, t_y, t_x]
|
159 |
+
"""
|
160 |
+
device = duration.device
|
161 |
+
|
162 |
+
b, _, t_y, t_x = mask.shape
|
163 |
+
cum_duration = torch.cumsum(duration, -1)
|
164 |
+
|
165 |
+
cum_duration_flat = cum_duration.view(b * t_x)
|
166 |
+
path = sequence_mask(cum_duration_flat, t_y).to(mask.dtype)
|
167 |
+
path = path.view(b, t_x, t_y)
|
168 |
+
path = path - F.pad(path, convert_pad_shape([[0, 0], [1, 0], [0, 0]]))[:, :-1]
|
169 |
+
path = path.unsqueeze(1).transpose(2,3) * mask
|
170 |
+
return path
|
171 |
+
|
172 |
+
|
173 |
+
def clip_grad_value_(parameters, clip_value, norm_type=2):
|
174 |
+
if isinstance(parameters, torch.Tensor):
|
175 |
+
parameters = [parameters]
|
176 |
+
parameters = list(filter(lambda p: p.grad is not None, parameters))
|
177 |
+
norm_type = float(norm_type)
|
178 |
+
if clip_value is not None:
|
179 |
+
clip_value = float(clip_value)
|
180 |
+
|
181 |
+
total_norm = 0
|
182 |
+
for p in parameters:
|
183 |
+
param_norm = p.grad.data.norm(norm_type)
|
184 |
+
total_norm += param_norm.item() ** norm_type
|
185 |
+
if clip_value is not None:
|
186 |
+
p.grad.data.clamp_(min=-clip_value, max=clip_value)
|
187 |
+
total_norm = total_norm ** (1. / norm_type)
|
188 |
+
return total_norm
|
modules/ddsp.py
ADDED
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torch.nn as nn
|
3 |
+
from torch.nn import functional as F
|
4 |
+
import torch.fft as fft
|
5 |
+
import numpy as np
|
6 |
+
import librosa as li
|
7 |
+
import math
|
8 |
+
from scipy.signal import get_window
|
9 |
+
|
10 |
+
|
11 |
+
def safe_log(x):
|
12 |
+
return torch.log(x + 1e-7)
|
13 |
+
|
14 |
+
|
15 |
+
@torch.no_grad()
|
16 |
+
def mean_std_loudness(dataset):
|
17 |
+
mean = 0
|
18 |
+
std = 0
|
19 |
+
n = 0
|
20 |
+
for _, _, l in dataset:
|
21 |
+
n += 1
|
22 |
+
mean += (l.mean().item() - mean) / n
|
23 |
+
std += (l.std().item() - std) / n
|
24 |
+
return mean, std
|
25 |
+
|
26 |
+
|
27 |
+
def multiscale_fft(signal, scales, overlap):
|
28 |
+
stfts = []
|
29 |
+
for s in scales:
|
30 |
+
S = torch.stft(
|
31 |
+
signal,
|
32 |
+
s,
|
33 |
+
int(s * (1 - overlap)),
|
34 |
+
s,
|
35 |
+
torch.hann_window(s).to(signal),
|
36 |
+
True,
|
37 |
+
normalized=True,
|
38 |
+
return_complex=True,
|
39 |
+
).abs()
|
40 |
+
stfts.append(S)
|
41 |
+
return stfts
|
42 |
+
|
43 |
+
|
44 |
+
def resample(x, factor: int):
|
45 |
+
batch, frame, channel = x.shape
|
46 |
+
x = x.permute(0, 2, 1).reshape(batch * channel, 1, frame)
|
47 |
+
|
48 |
+
window = torch.hann_window(
|
49 |
+
factor * 2,
|
50 |
+
dtype=x.dtype,
|
51 |
+
device=x.device,
|
52 |
+
).reshape(1, 1, -1)
|
53 |
+
y = torch.zeros(x.shape[0], x.shape[1], factor * x.shape[2]).to(x)
|
54 |
+
y[..., ::factor] = x
|
55 |
+
y[..., -1:] = x[..., -1:]
|
56 |
+
y = torch.nn.functional.pad(y, [factor, factor])
|
57 |
+
y = torch.nn.functional.conv1d(y, window)[..., :-1]
|
58 |
+
|
59 |
+
y = y.reshape(batch, channel, factor * frame).permute(0, 2, 1)
|
60 |
+
|
61 |
+
return y
|
62 |
+
|
63 |
+
|
64 |
+
def upsample(signal, factor):
|
65 |
+
signal = signal.permute(0, 2, 1)
|
66 |
+
signal = nn.functional.interpolate(signal, size=signal.shape[-1] * factor)
|
67 |
+
return signal.permute(0, 2, 1)
|
68 |
+
|
69 |
+
|
70 |
+
def remove_above_nyquist(amplitudes, pitch, sampling_rate):
|
71 |
+
n_harm = amplitudes.shape[-1]
|
72 |
+
pitches = pitch * torch.arange(1, n_harm + 1).to(pitch)
|
73 |
+
aa = (pitches < sampling_rate / 2).float() + 1e-4
|
74 |
+
return amplitudes * aa
|
75 |
+
|
76 |
+
|
77 |
+
def scale_function(x):
|
78 |
+
return 2 * torch.sigmoid(x) ** (math.log(10)) + 1e-7
|
79 |
+
|
80 |
+
|
81 |
+
def extract_loudness(signal, sampling_rate, block_size, n_fft=2048):
|
82 |
+
S = li.stft(
|
83 |
+
signal,
|
84 |
+
n_fft=n_fft,
|
85 |
+
hop_length=block_size,
|
86 |
+
win_length=n_fft,
|
87 |
+
center=True,
|
88 |
+
)
|
89 |
+
S = np.log(abs(S) + 1e-7)
|
90 |
+
f = li.fft_frequencies(sampling_rate, n_fft)
|
91 |
+
a_weight = li.A_weighting(f)
|
92 |
+
|
93 |
+
S = S + a_weight.reshape(-1, 1)
|
94 |
+
|
95 |
+
S = np.mean(S, 0)[..., :-1]
|
96 |
+
|
97 |
+
return S
|
98 |
+
|
99 |
+
|
100 |
+
def extract_pitch(signal, sampling_rate, block_size):
|
101 |
+
length = signal.shape[-1] // block_size
|
102 |
+
f0 = crepe.predict(
|
103 |
+
signal,
|
104 |
+
sampling_rate,
|
105 |
+
step_size=int(1000 * block_size / sampling_rate),
|
106 |
+
verbose=1,
|
107 |
+
center=True,
|
108 |
+
viterbi=True,
|
109 |
+
)
|
110 |
+
f0 = f0[1].reshape(-1)[:-1]
|
111 |
+
|
112 |
+
if f0.shape[-1] != length:
|
113 |
+
f0 = np.interp(
|
114 |
+
np.linspace(0, 1, length, endpoint=False),
|
115 |
+
np.linspace(0, 1, f0.shape[-1], endpoint=False),
|
116 |
+
f0,
|
117 |
+
)
|
118 |
+
|
119 |
+
return f0
|
120 |
+
|
121 |
+
|
122 |
+
def mlp(in_size, hidden_size, n_layers):
|
123 |
+
channels = [in_size] + (n_layers) * [hidden_size]
|
124 |
+
net = []
|
125 |
+
for i in range(n_layers):
|
126 |
+
net.append(nn.Linear(channels[i], channels[i + 1]))
|
127 |
+
net.append(nn.LayerNorm(channels[i + 1]))
|
128 |
+
net.append(nn.LeakyReLU())
|
129 |
+
return nn.Sequential(*net)
|
130 |
+
|
131 |
+
|
132 |
+
def gru(n_input, hidden_size):
|
133 |
+
return nn.GRU(n_input * hidden_size, hidden_size, batch_first=True)
|
134 |
+
|
135 |
+
|
136 |
+
def harmonic_synth(pitch, amplitudes, sampling_rate):
|
137 |
+
n_harmonic = amplitudes.shape[-1]
|
138 |
+
omega = torch.cumsum(2 * math.pi * pitch / sampling_rate, 1)
|
139 |
+
omegas = omega * torch.arange(1, n_harmonic + 1).to(omega)
|
140 |
+
signal = (torch.sin(omegas) * amplitudes).sum(-1, keepdim=True)
|
141 |
+
return signal
|
142 |
+
|
143 |
+
|
144 |
+
def amp_to_impulse_response(amp, target_size):
|
145 |
+
amp = torch.stack([amp, torch.zeros_like(amp)], -1)
|
146 |
+
amp = torch.view_as_complex(amp)
|
147 |
+
amp = fft.irfft(amp)
|
148 |
+
|
149 |
+
filter_size = amp.shape[-1]
|
150 |
+
|
151 |
+
amp = torch.roll(amp, filter_size // 2, -1)
|
152 |
+
win = torch.hann_window(filter_size, dtype=amp.dtype, device=amp.device)
|
153 |
+
|
154 |
+
amp = amp * win
|
155 |
+
|
156 |
+
amp = nn.functional.pad(amp, (0, int(target_size) - int(filter_size)))
|
157 |
+
amp = torch.roll(amp, -filter_size // 2, -1)
|
158 |
+
|
159 |
+
return amp
|
160 |
+
|
161 |
+
|
162 |
+
def fft_convolve(signal, kernel):
|
163 |
+
signal = nn.functional.pad(signal, (0, signal.shape[-1]))
|
164 |
+
kernel = nn.functional.pad(kernel, (kernel.shape[-1], 0))
|
165 |
+
|
166 |
+
output = fft.irfft(fft.rfft(signal) * fft.rfft(kernel))
|
167 |
+
output = output[..., output.shape[-1] // 2:]
|
168 |
+
|
169 |
+
return output
|
170 |
+
|
171 |
+
|
172 |
+
def init_kernels(win_len, win_inc, fft_len, win_type=None, invers=False):
|
173 |
+
if win_type == 'None' or win_type is None:
|
174 |
+
window = np.ones(win_len)
|
175 |
+
else:
|
176 |
+
window = get_window(win_type, win_len, fftbins=True) # **0.5
|
177 |
+
|
178 |
+
N = fft_len
|
179 |
+
fourier_basis = np.fft.rfft(np.eye(N))[:win_len]
|
180 |
+
real_kernel = np.real(fourier_basis)
|
181 |
+
imag_kernel = np.imag(fourier_basis)
|
182 |
+
kernel = np.concatenate([real_kernel, imag_kernel], 1).T
|
183 |
+
|
184 |
+
if invers:
|
185 |
+
kernel = np.linalg.pinv(kernel).T
|
186 |
+
|
187 |
+
kernel = kernel * window
|
188 |
+
kernel = kernel[:, None, :]
|
189 |
+
return torch.from_numpy(kernel.astype(np.float32)), torch.from_numpy(window[None, :, None].astype(np.float32))
|
190 |
+
|
modules/losses.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from torch.nn import functional as F
|
3 |
+
|
4 |
+
import modules.commons as commons
|
5 |
+
|
6 |
+
|
7 |
+
def feature_loss(fmap_r, fmap_g):
|
8 |
+
loss = 0
|
9 |
+
for dr, dg in zip(fmap_r, fmap_g):
|
10 |
+
for rl, gl in zip(dr, dg):
|
11 |
+
rl = rl.float().detach()
|
12 |
+
gl = gl.float()
|
13 |
+
loss += torch.mean(torch.abs(rl - gl))
|
14 |
+
|
15 |
+
return loss * 2
|
16 |
+
|
17 |
+
|
18 |
+
def discriminator_loss(disc_real_outputs, disc_generated_outputs):
|
19 |
+
loss = 0
|
20 |
+
r_losses = []
|
21 |
+
g_losses = []
|
22 |
+
for dr, dg in zip(disc_real_outputs, disc_generated_outputs):
|
23 |
+
dr = dr.float()
|
24 |
+
dg = dg.float()
|
25 |
+
r_loss = torch.mean((1-dr)**2)
|
26 |
+
g_loss = torch.mean(dg**2)
|
27 |
+
loss += (r_loss + g_loss)
|
28 |
+
r_losses.append(r_loss.item())
|
29 |
+
g_losses.append(g_loss.item())
|
30 |
+
|
31 |
+
return loss, r_losses, g_losses
|
32 |
+
|
33 |
+
|
34 |
+
def generator_loss(disc_outputs):
|
35 |
+
loss = 0
|
36 |
+
gen_losses = []
|
37 |
+
for dg in disc_outputs:
|
38 |
+
dg = dg.float()
|
39 |
+
l = torch.mean((1-dg)**2)
|
40 |
+
gen_losses.append(l)
|
41 |
+
loss += l
|
42 |
+
|
43 |
+
return loss, gen_losses
|
44 |
+
|
45 |
+
|
46 |
+
def kl_loss(z_p, logs_q, m_p, logs_p, z_mask):
|
47 |
+
"""
|
48 |
+
z_p, logs_q: [b, h, t_t]
|
49 |
+
m_p, logs_p: [b, h, t_t]
|
50 |
+
"""
|
51 |
+
z_p = z_p.float()
|
52 |
+
logs_q = logs_q.float()
|
53 |
+
m_p = m_p.float()
|
54 |
+
logs_p = logs_p.float()
|
55 |
+
z_mask = z_mask.float()
|
56 |
+
#print(logs_p)
|
57 |
+
kl = logs_p - logs_q - 0.5
|
58 |
+
kl += 0.5 * ((z_p - m_p)**2) * torch.exp(-2. * logs_p)
|
59 |
+
kl = torch.sum(kl * z_mask)
|
60 |
+
l = kl / torch.sum(z_mask)
|
61 |
+
return l
|