Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Parakeet
提交
44e61e07
P
Parakeet
项目概览
PaddlePaddle
/
Parakeet
通知
11
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Parakeet
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
44e61e07
编写于
2月 28, 2020
作者:
C
chenfeiyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add missing parallel_wavenet, and fix python2 compatability
上级
6a5c2208
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
74 addition
and
5 deletion
+74
-5
parakeet/models/clarinet/parallel_wavenet.py
parakeet/models/clarinet/parallel_wavenet.py
+69
-0
parakeet/models/wavenet/net.py
parakeet/models/wavenet/net.py
+2
-2
parakeet/models/wavenet/wavenet.py
parakeet/models/wavenet/wavenet.py
+3
-3
未找到文件。
parakeet/models/clarinet/parallel_wavenet.py
0 → 100644
浏览文件 @
44e61e07
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
math
import
time
import
itertools
import
numpy
as
np
import
paddle.fluid.layers
as
F
import
paddle.fluid.dygraph
as
dg
import
paddle.fluid.initializer
as
I
import
paddle.fluid.layers.distributions
as
D
from
parakeet.modules.weight_norm
import
Linear
,
Conv1D
,
Conv1DCell
,
Conv2DTranspose
from
parakeet.models.wavenet
import
WaveNet
class
ParallelWaveNet
(
dg
.
Layer
):
def
__init__
(
self
,
n_loops
,
n_layers
,
residual_channels
,
condition_dim
,
filter_size
):
super
(
ParallelWaveNet
,
self
).
__init__
()
self
.
flows
=
dg
.
LayerList
()
for
n_loop
,
n_layer
in
zip
(
n_loops
,
n_layers
):
# teacher's log_scale_min does not matter herem, -100 is a dummy value
self
.
flows
.
append
(
WaveNet
(
n_loop
,
n_layer
,
residual_channels
,
3
,
condition_dim
,
filter_size
,
"mog"
,
-
100.0
))
def
forward
(
self
,
z
,
condition
=
None
):
"""Inverse Autoregressive Flow. Several wavenets.
Arguments:
z {Variable} -- shape(batch_size, time_steps), hidden variable, sampled from a standard normal distribution.
Keyword Arguments:
condition {Variable} -- shape(batch_size, condition_dim, time_steps), condition, basically upsampled mel spectrogram. (default: {None})
Returns:
Variable -- shape(batch_size, time_steps), transformed z.
Variable -- shape(batch_size, time_steps), output distribution's mu.
Variable -- shape(batch_size, time_steps), output distribution's log_std.
"""
for
i
,
flow
in
enumerate
(
self
.
flows
):
theta
=
flow
(
z
,
condition
)
# w, mu, log_std [0: T]
w
,
mu
,
log_std
=
F
.
split
(
theta
,
3
,
dim
=-
1
)
# (B, T, 1) for each
mu
=
F
.
squeeze
(
mu
,
[
-
1
])
#[0: T]
log_std
=
F
.
squeeze
(
log_std
,
[
-
1
])
#[0: T]
z
=
z
*
F
.
exp
(
log_std
)
+
mu
#[0: T]
if
i
==
0
:
out_mu
=
mu
out_log_std
=
log_std
else
:
out_mu
=
out_mu
*
F
.
exp
(
log_std
)
+
mu
out_log_std
+=
log_std
return
z
,
out_mu
,
out_log_std
parakeet/models/wavenet/net.py
浏览文件 @
44e61e07
...
...
@@ -57,7 +57,7 @@ class UpsampleNet(dg.Layer):
"""
def
__init__
(
self
,
upscale_factors
=
[
16
,
16
]):
super
().
__init__
()
super
(
UpsampleNet
,
self
).
__init__
()
self
.
upscale_factors
=
list
(
upscale_factors
)
self
.
upsample_convs
=
dg
.
LayerList
()
for
i
,
factor
in
enumerate
(
upscale_factors
):
...
...
@@ -92,7 +92,7 @@ class UpsampleNet(dg.Layer):
# AutoRegressive Model
class
ConditionalWavenet
(
dg
.
Layer
):
def
__init__
(
self
,
encoder
:
UpsampleNet
,
decoder
:
WaveNet
):
super
().
__init__
()
super
(
ConditionalWavenet
,
self
).
__init__
()
self
.
encoder
=
encoder
self
.
decoder
=
decoder
...
...
parakeet/models/wavenet/wavenet.py
浏览文件 @
44e61e07
...
...
@@ -39,7 +39,7 @@ def dequantize(quantized, n_bands):
class
ResidualBlock
(
dg
.
Layer
):
def
__init__
(
self
,
residual_channels
,
condition_dim
,
filter_size
,
dilation
):
super
().
__init__
()
super
(
ResidualBlock
,
self
).
__init__
()
dilated_channels
=
2
*
residual_channels
# following clarinet's implementation, we do not have parametric residual
# & skip connection.
...
...
@@ -135,7 +135,7 @@ class ResidualBlock(dg.Layer):
class
ResidualNet
(
dg
.
Layer
):
def
__init__
(
self
,
n_loop
,
n_layer
,
residual_channels
,
condition_dim
,
filter_size
):
super
().
__init__
()
super
(
ResidualNet
,
self
).
__init__
()
# double the dilation at each layer in a loop(n_loop layers)
dilations
=
[
2
**
i
for
i
in
range
(
n_loop
)]
*
n_layer
self
.
context_size
=
1
+
sum
(
dilations
)
...
...
@@ -198,7 +198,7 @@ class ResidualNet(dg.Layer):
class
WaveNet
(
dg
.
Layer
):
def
__init__
(
self
,
n_loop
,
n_layer
,
residual_channels
,
output_dim
,
condition_dim
,
filter_size
,
loss_type
,
log_scale_min
):
super
().
__init__
()
super
(
WaveNet
,
self
).
__init__
()
if
loss_type
not
in
[
"softmax"
,
"mog"
]:
raise
ValueError
(
"loss_type {} is not supported"
.
format
(
loss_type
))
if
loss_type
==
"softmax"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录