Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Parakeet
提交
6908ec52
P
Parakeet
项目概览
PaddlePaddle
/
Parakeet
通知
10
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看板
提交
6908ec52
编写于
2月 11, 2020
作者:
L
lifuchen
提交者:
chenfeiyu
2月 11, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adjust the directory structure
上级
fc84ca2d
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
115 addition
and
439 deletion
+115
-439
examples/FastSpeech/config/fastspeech.yaml
examples/FastSpeech/config/fastspeech.yaml
+1
-1
parakeet/models/fastspeech/FFTBlock.py
parakeet/models/fastspeech/FFTBlock.py
+1
-1
parakeet/models/fastspeech/LengthRegulator.py
parakeet/models/fastspeech/LengthRegulator.py
+15
-4
parakeet/models/fastspeech/decoder.py
parakeet/models/fastspeech/decoder.py
+0
-3
parakeet/models/fastspeech/encoder.py
parakeet/models/fastspeech/encoder.py
+0
-3
parakeet/models/fastspeech/fastspeech.py
parakeet/models/fastspeech/fastspeech.py
+9
-5
parakeet/models/transformerTTS/CBHG.py
parakeet/models/transformerTTS/CBHG.py
+38
-13
parakeet/models/transformerTTS/decoder.py
parakeet/models/transformerTTS/decoder.py
+15
-8
parakeet/models/transformerTTS/encoder.py
parakeet/models/transformerTTS/encoder.py
+1
-2
parakeet/models/transformerTTS/encoderprenet.py
parakeet/models/transformerTTS/encoderprenet.py
+13
-4
parakeet/models/transformerTTS/vocoder.py
parakeet/models/transformerTTS/vocoder.py
+1
-1
parakeet/modules/dynamicGRU.py
parakeet/modules/dynamicGRU.py
+0
-52
parakeet/modules/feed_forward.py
parakeet/modules/feed_forward.py
+0
-52
parakeet/modules/layers.py
parakeet/modules/layers.py
+0
-177
parakeet/modules/multihead_attention.py
parakeet/modules/multihead_attention.py
+21
-1
parakeet/modules/post_convnet.py
parakeet/modules/post_convnet.py
+0
-80
parakeet/modules/prenet.py
parakeet/modules/prenet.py
+0
-32
未找到文件。
examples/FastSpeech/config/fastspeech.yaml
浏览文件 @
6908ec52
...
...
@@ -35,7 +35,7 @@ epochs: 10000
lr
:
0.001
save_step
:
500
use_gpu
:
True
use_data_parallel
:
Tru
e
use_data_parallel
:
Fals
e
data_path
:
../../dataset/LJSpeech-1.1
transtts_path
:
../TransformerTTS/checkpoint/
...
...
parakeet/models/fastspeech/FFTBlock.py
浏览文件 @
6908ec52
...
...
@@ -4,7 +4,7 @@ import paddle.fluid.dygraph as dg
import
paddle.fluid.layers
as
layers
import
paddle.fluid
as
fluid
from
parakeet.modules.multihead_attention
import
MultiheadAttention
from
parakeet.modules.f
eed_forward
import
PositionwiseFeedForward
from
parakeet.modules.f
fn
import
PositionwiseFeedForward
class
FFTBlock
(
dg
.
Layer
):
def
__init__
(
self
,
d_model
,
d_inner
,
n_head
,
d_k
,
d_v
,
filter_size
,
padding
,
dropout
=
0.2
):
...
...
parakeet/models/fastspeech/LengthRegulator.py
浏览文件 @
6908ec52
...
...
@@ -4,7 +4,7 @@ import parakeet.models.fastspeech.utils
import
paddle.fluid.dygraph
as
dg
import
paddle.fluid.layers
as
layers
import
paddle.fluid
as
fluid
from
parakeet.modules.
layers
import
Conv
,
Linear
from
parakeet.modules.
customized
import
Conv1D
class
LengthRegulator
(
dg
.
Layer
):
def
__init__
(
self
,
input_size
,
out_channels
,
filter_size
,
dropout
=
0.1
):
...
...
@@ -82,20 +82,31 @@ class DurationPredictor(dg.Layer):
self
.
filter_size
=
filter_size
self
.
dropout
=
dropout
self
.
conv1
=
Conv
(
in_channels
=
self
.
input_size
,
k
=
math
.
sqrt
(
1
/
self
.
input_size
)
self
.
conv1
=
Conv1D
(
in_channels
=
self
.
input_size
,
out_channels
=
self
.
out_channels
,
filter_size
=
self
.
filter_size
,
padding
=
1
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
)),
data_format
=
'NTC'
)
self
.
conv2
=
Conv
(
in_channels
=
self
.
out_channels
,
k
=
math
.
sqrt
(
1
/
self
.
out_channels
)
self
.
conv2
=
Conv1D
(
in_channels
=
self
.
out_channels
,
out_channels
=
self
.
out_channels
,
filter_size
=
self
.
filter_size
,
padding
=
1
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
)),
data_format
=
'NTC'
)
self
.
layer_norm1
=
dg
.
LayerNorm
(
self
.
out_channels
)
self
.
layer_norm2
=
dg
.
LayerNorm
(
self
.
out_channels
)
self
.
linear
=
Linear
(
self
.
out_channels
,
1
)
self
.
weight
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
())
k
=
math
.
sqrt
(
1
/
self
.
out_channels
)
self
.
bias
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
))
self
.
linear
=
dg
.
Linear
(
self
.
out_channels
,
1
,
param_attr
=
self
.
weight
,
bias_attr
=
self
.
bias
)
def
forward
(
self
,
encoder_output
):
"""
...
...
parakeet/models/fastspeech/decoder.py
浏览文件 @
6908ec52
import
paddle.fluid.dygraph
as
dg
import
paddle.fluid
as
fluid
from
parakeet.g2p.text.symbols
import
symbols
from
parakeet.modules.utils
import
*
from
parakeet.modules.post_convnet
import
PostConvNet
from
parakeet.modules.layers
import
Linear
from
parakeet.models.fastspeech.FFTBlock
import
FFTBlock
class
Decoder
(
dg
.
Layer
):
...
...
parakeet/models/fastspeech/encoder.py
浏览文件 @
6908ec52
import
paddle.fluid.dygraph
as
dg
import
paddle.fluid
as
fluid
from
parakeet.g2p.text.symbols
import
symbols
from
parakeet.modules.utils
import
*
from
parakeet.modules.post_convnet
import
PostConvNet
from
parakeet.modules.layers
import
Linear
from
parakeet.models.fastspeech.FFTBlock
import
FFTBlock
class
Encoder
(
dg
.
Layer
):
...
...
parakeet/models/fastspeech/fastspeech.py
浏览文件 @
6908ec52
import
math
import
paddle.fluid.dygraph
as
dg
import
paddle.fluid
as
fluid
from
parakeet.g2p.text.symbols
import
symbols
from
parakeet.modules.utils
import
*
from
parakeet.modules.post_convnet
import
PostConvNet
from
parakeet.modules.layers
import
Linear
from
parakeet.models.fastspeech.utils
import
*
from
parakeet.models.transformerTTS.post_convnet
import
PostConvNet
from
parakeet.models.fastspeech.LengthRegulator
import
LengthRegulator
from
parakeet.models.fastspeech.encoder
import
Encoder
from
parakeet.models.fastspeech.decoder
import
Decoder
...
...
@@ -39,7 +37,13 @@ class FastSpeech(dg.Layer):
fft_conv1d_kernel
=
cfg
.
fft_conv1d_filter
,
fft_conv1d_padding
=
cfg
.
fft_conv1d_padding
,
dropout
=
0.1
)
self
.
mel_linear
=
Linear
(
cfg
.
fs_hidden_size
,
cfg
.
audio
.
num_mels
*
cfg
.
audio
.
outputs_per_step
)
self
.
weight
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
())
k
=
math
.
sqrt
(
1
/
cfg
.
fs_hidden_size
)
self
.
bias
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
))
self
.
mel_linear
=
dg
.
Linear
(
cfg
.
fs_hidden_size
,
cfg
.
audio
.
num_mels
*
cfg
.
audio
.
outputs_per_step
,
param_attr
=
self
.
weight
,
bias_attr
=
self
.
bias
,)
self
.
postnet
=
PostConvNet
(
n_mels
=
cfg
.
audio
.
num_mels
,
num_hidden
=
512
,
filter_size
=
5
,
...
...
parakeet/models/transformerTTS/CBHG.py
浏览文件 @
6908ec52
...
...
@@ -3,8 +3,8 @@ from parakeet.g2p.text.symbols import symbols
import
paddle.fluid.dygraph
as
dg
import
paddle.fluid
as
fluid
import
paddle.fluid.layers
as
layers
from
parakeet.modules.
layers
import
Conv
,
Pool1D
,
Linear
from
parakeet.modules.dynamic
GRU
import
DynamicGRU
from
parakeet.modules.
customized
import
Pool1D
,
Conv1D
from
parakeet.modules.dynamic
_gru
import
DynamicGRU
import
numpy
as
np
class
CBHG
(
dg
.
Layer
):
...
...
@@ -23,16 +23,22 @@ class CBHG(dg.Layer):
self
.
hidden_size
=
hidden_size
self
.
projection_size
=
projection_size
self
.
conv_list
=
[]
self
.
conv_list
.
append
(
Conv
(
in_channels
=
projection_size
,
k
=
math
.
sqrt
(
1
/
projection_size
)
self
.
conv_list
.
append
(
Conv1D
(
in_channels
=
projection_size
,
out_channels
=
hidden_size
,
filter_size
=
1
,
padding
=
int
(
np
.
floor
(
1
/
2
)),
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
)),
data_format
=
"NCT"
))
k
=
math
.
sqrt
(
1
/
hidden_size
)
for
i
in
range
(
2
,
K
+
1
):
self
.
conv_list
.
append
(
Conv
(
in_channels
=
hidden_size
,
self
.
conv_list
.
append
(
Conv
1D
(
in_channels
=
hidden_size
,
out_channels
=
hidden_size
,
filter_size
=
i
,
padding
=
int
(
np
.
floor
(
i
/
2
)),
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
)),
data_format
=
"NCT"
))
for
i
,
layer
in
enumerate
(
self
.
conv_list
):
...
...
@@ -48,16 +54,22 @@ class CBHG(dg.Layer):
conv_outdim
=
hidden_size
*
K
self
.
conv_projection_1
=
Conv
(
in_channels
=
conv_outdim
,
k
=
math
.
sqrt
(
1
/
conv_outdim
)
self
.
conv_projection_1
=
Conv1D
(
in_channels
=
conv_outdim
,
out_channels
=
hidden_size
,
filter_size
=
3
,
padding
=
int
(
np
.
floor
(
3
/
2
)),
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
)),
data_format
=
"NCT"
)
self
.
conv_projection_2
=
Conv
(
in_channels
=
hidden_size
,
k
=
math
.
sqrt
(
1
/
hidden_size
)
self
.
conv_projection_2
=
Conv1D
(
in_channels
=
hidden_size
,
out_channels
=
projection_size
,
filter_size
=
3
,
padding
=
int
(
np
.
floor
(
3
/
2
)),
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
)),
data_format
=
"NCT"
)
self
.
batchnorm_proj_1
=
dg
.
BatchNorm
(
hidden_size
,
...
...
@@ -73,8 +85,13 @@ class CBHG(dg.Layer):
h_0
=
np
.
zeros
((
batch_size
,
hidden_size
//
2
),
dtype
=
"float32"
)
h_0
=
dg
.
to_variable
(
h_0
)
self
.
fc_forward1
=
Linear
(
hidden_size
,
hidden_size
//
2
*
3
)
self
.
fc_reverse1
=
Linear
(
hidden_size
,
hidden_size
//
2
*
3
)
k
=
math
.
sqrt
(
1
/
hidden_size
)
self
.
fc_forward1
=
dg
.
Linear
(
hidden_size
,
hidden_size
//
2
*
3
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
)))
self
.
fc_reverse1
=
dg
.
Linear
(
hidden_size
,
hidden_size
//
2
*
3
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
)))
self
.
gru_forward1
=
DynamicGRU
(
size
=
self
.
hidden_size
//
2
,
is_reverse
=
False
,
origin_mode
=
True
,
...
...
@@ -84,8 +101,12 @@ class CBHG(dg.Layer):
origin_mode
=
True
,
h_0
=
h_0
)
self
.
fc_forward2
=
Linear
(
hidden_size
,
hidden_size
//
2
*
3
)
self
.
fc_reverse2
=
Linear
(
hidden_size
,
hidden_size
//
2
*
3
)
self
.
fc_forward2
=
dg
.
Linear
(
hidden_size
,
hidden_size
//
2
*
3
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
)))
self
.
fc_reverse2
=
dg
.
Linear
(
hidden_size
,
hidden_size
//
2
*
3
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
)))
self
.
gru_forward2
=
DynamicGRU
(
size
=
self
.
hidden_size
//
2
,
is_reverse
=
False
,
origin_mode
=
True
,
...
...
@@ -145,10 +166,14 @@ class Highwaynet(dg.Layer):
self
.
gates
=
[]
self
.
linears
=
[]
k
=
math
.
sqrt
(
1
/
num_units
)
for
i
in
range
(
num_layers
):
self
.
linears
.
append
(
Linear
(
num_units
,
num_units
))
self
.
gates
.
append
(
Linear
(
num_units
,
num_units
))
self
.
linears
.
append
(
dg
.
Linear
(
num_units
,
num_units
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
))))
self
.
gates
.
append
(
dg
.
Linear
(
num_units
,
num_units
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
))))
for
i
,
(
linear
,
gate
)
in
enumerate
(
zip
(
self
.
linears
,
self
.
gates
)):
self
.
add_sublayer
(
"linears_{}"
.
format
(
i
),
linear
)
...
...
parakeet/models/transformerTTS/decoder.py
浏览文件 @
6908ec52
import
math
import
paddle.fluid.dygraph
as
dg
import
paddle.fluid
as
fluid
from
parakeet.modules.layers
import
Conv1D
,
Linear
from
parakeet.modules.utils
import
*
from
parakeet.modules.multihead_attention
import
MultiheadAttention
from
parakeet.modules.f
eed_forward
import
PositionwiseFeedForward
from
parakeet.mod
ules
.prenet
import
PreNet
from
parakeet.mod
ules
.post_convnet
import
PostConvNet
from
parakeet.modules.f
fn
import
PositionwiseFeedForward
from
parakeet.mod
els.transformerTTS
.prenet
import
PreNet
from
parakeet.mod
els.transformerTTS
.post_convnet
import
PostConvNet
class
Decoder
(
dg
.
Layer
):
def
__init__
(
self
,
num_hidden
,
config
,
num_head
=
4
):
super
(
Decoder
,
self
).
__init__
()
...
...
@@ -24,7 +24,10 @@ class Decoder(dg.Layer):
hidden_size
=
num_hidden
*
2
,
output_size
=
num_hidden
,
dropout_rate
=
0.2
)
self
.
linear
=
Linear
(
num_hidden
,
num_hidden
)
k
=
math
.
sqrt
(
1
/
num_hidden
)
self
.
linear
=
dg
.
Linear
(
num_hidden
,
num_hidden
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
)))
self
.
selfattn_layers
=
[
MultiheadAttention
(
num_hidden
,
num_hidden
//
num_head
,
num_hidden
//
num_head
)
for
_
in
range
(
3
)]
for
i
,
layer
in
enumerate
(
self
.
selfattn_layers
):
...
...
@@ -35,8 +38,12 @@ class Decoder(dg.Layer):
self
.
ffns
=
[
PositionwiseFeedForward
(
num_hidden
,
num_hidden
*
num_head
,
filter_size
=
1
)
for
_
in
range
(
3
)]
for
i
,
layer
in
enumerate
(
self
.
ffns
):
self
.
add_sublayer
(
"ffns_{}"
.
format
(
i
),
layer
)
self
.
mel_linear
=
Linear
(
num_hidden
,
config
.
audio
.
num_mels
*
config
.
audio
.
outputs_per_step
)
self
.
stop_linear
=
Linear
(
num_hidden
,
1
)
self
.
mel_linear
=
dg
.
Linear
(
num_hidden
,
config
.
audio
.
num_mels
*
config
.
audio
.
outputs_per_step
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
)))
self
.
stop_linear
=
dg
.
Linear
(
num_hidden
,
1
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
)))
self
.
postconvnet
=
PostConvNet
(
config
.
audio
.
num_mels
,
config
.
hidden_size
,
filter_size
=
5
,
padding
=
4
,
num_conv
=
5
,
...
...
parakeet/models/transformerTTS/encoder.py
浏览文件 @
6908ec52
import
paddle.fluid.dygraph
as
dg
import
paddle.fluid
as
fluid
from
parakeet.modules.layers
import
Conv1D
,
Linear
from
parakeet.modules.utils
import
*
from
parakeet.modules.multihead_attention
import
MultiheadAttention
from
parakeet.modules.f
eed_forward
import
PositionwiseFeedForward
from
parakeet.modules.f
fn
import
PositionwiseFeedForward
from
parakeet.models.transformerTTS.encoderprenet
import
EncoderPrenet
class
Encoder
(
dg
.
Layer
):
...
...
parakeet/models/transformerTTS/encoderprenet.py
浏览文件 @
6908ec52
...
...
@@ -3,7 +3,7 @@ from parakeet.g2p.text.symbols import symbols
import
paddle.fluid.dygraph
as
dg
import
paddle.fluid
as
fluid
import
paddle.fluid.layers
as
layers
from
parakeet.modules.
layers
import
Conv
,
Linear
from
parakeet.modules.
customized
import
Conv1D
import
numpy
as
np
...
...
@@ -16,17 +16,23 @@ class EncoderPrenet(dg.Layer):
self
.
embedding
=
dg
.
Embedding
(
size
=
[
len
(
symbols
),
embedding_size
],
padding_idx
=
None
)
self
.
conv_list
=
[]
self
.
conv_list
.
append
(
Conv
(
in_channels
=
embedding_size
,
k
=
math
.
sqrt
(
1
/
embedding_size
)
self
.
conv_list
.
append
(
Conv1D
(
in_channels
=
embedding_size
,
out_channels
=
num_hidden
,
filter_size
=
5
,
padding
=
int
(
np
.
floor
(
5
/
2
)),
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
)),
use_cudnn
=
use_cudnn
,
data_format
=
"NCT"
))
k
=
math
.
sqrt
(
1
/
num_hidden
)
for
_
in
range
(
2
):
self
.
conv_list
.
append
(
Conv
(
in_channels
=
num_hidden
,
self
.
conv_list
.
append
(
Conv
1D
(
in_channels
=
num_hidden
,
out_channels
=
num_hidden
,
filter_size
=
5
,
padding
=
int
(
np
.
floor
(
5
/
2
)),
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
)),
use_cudnn
=
use_cudnn
,
data_format
=
"NCT"
))
...
...
@@ -39,7 +45,10 @@ class EncoderPrenet(dg.Layer):
for
i
,
layer
in
enumerate
(
self
.
batch_norm_list
):
self
.
add_sublayer
(
"batch_norm_list_{}"
.
format
(
i
),
layer
)
self
.
projection
=
Linear
(
num_hidden
,
num_hidden
)
k
=
math
.
sqrt
(
1
/
num_hidden
)
self
.
projection
=
dg
.
Linear
(
num_hidden
,
num_hidden
,
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
()),
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
)))
def
forward
(
self
,
x
):
x
=
self
.
embedding
(
x
)
#(batch_size, seq_len, embending_size)
...
...
parakeet/models/transformerTTS/vocoder.py
浏览文件 @
6908ec52
import
paddle.fluid.dygraph
as
dg
import
paddle.fluid
as
fluid
from
parakeet.modules.
layers
import
Conv1D
,
Linear
from
parakeet.modules.
customized
import
Conv1D
from
parakeet.modules.utils
import
*
from
parakeet.models.transformerTTS.CBHG
import
CBHG
...
...
parakeet/modules/dynamicGRU.py
已删除
100644 → 0
浏览文件 @
fc84ca2d
import
paddle.fluid.dygraph
as
dg
import
paddle.fluid.layers
as
layers
class
DynamicGRU
(
dg
.
Layer
):
def
__init__
(
self
,
size
,
param_attr
=
None
,
bias_attr
=
None
,
is_reverse
=
False
,
gate_activation
=
'sigmoid'
,
candidate_activation
=
'tanh'
,
h_0
=
None
,
origin_mode
=
False
,
init_size
=
None
):
super
(
DynamicGRU
,
self
).
__init__
()
self
.
gru_unit
=
dg
.
GRUUnit
(
size
*
3
,
param_attr
=
param_attr
,
bias_attr
=
bias_attr
,
activation
=
candidate_activation
,
gate_activation
=
gate_activation
,
origin_mode
=
origin_mode
)
self
.
size
=
size
self
.
h_0
=
h_0
self
.
is_reverse
=
is_reverse
def
forward
(
self
,
inputs
):
"""
Dynamic GRU block.
Args:
input (Variable): Shape(B, T, C), dtype: float32. The input value.
Returns:
output (Variable), Shape(B, T, C), the result compute by GRU.
"""
hidden
=
self
.
h_0
res
=
[]
for
i
in
range
(
inputs
.
shape
[
1
]):
if
self
.
is_reverse
:
i
=
inputs
.
shape
[
1
]
-
1
-
i
input_
=
inputs
[:,
i
:
i
+
1
,
:]
input_
=
layers
.
reshape
(
input_
,
[
-
1
,
input_
.
shape
[
2
]],
inplace
=
False
)
hidden
,
reset
,
gate
=
self
.
gru_unit
(
input_
,
hidden
)
hidden_
=
layers
.
reshape
(
hidden
,
[
-
1
,
1
,
hidden
.
shape
[
1
]],
inplace
=
False
)
res
.
append
(
hidden_
)
if
self
.
is_reverse
:
res
=
res
[::
-
1
]
res
=
layers
.
concat
(
res
,
axis
=
1
)
return
res
parakeet/modules/feed_forward.py
已删除
100644 → 0
浏览文件 @
fc84ca2d
import
paddle.fluid.dygraph
as
dg
import
paddle.fluid.layers
as
layers
import
paddle.fluid
as
fluid
import
math
from
parakeet.modules.layers
import
Conv
class
PositionwiseFeedForward
(
dg
.
Layer
):
''' A two-feed-forward-layer module '''
def
__init__
(
self
,
d_in
,
num_hidden
,
filter_size
,
padding
=
0
,
use_cudnn
=
True
,
dropout
=
0.1
):
super
(
PositionwiseFeedForward
,
self
).
__init__
()
self
.
num_hidden
=
num_hidden
self
.
use_cudnn
=
use_cudnn
self
.
dropout
=
dropout
self
.
w_1
=
Conv
(
in_channels
=
d_in
,
out_channels
=
num_hidden
,
filter_size
=
filter_size
,
padding
=
padding
,
use_cudnn
=
use_cudnn
,
data_format
=
"NTC"
)
self
.
w_2
=
Conv
(
in_channels
=
num_hidden
,
out_channels
=
d_in
,
filter_size
=
filter_size
,
padding
=
padding
,
use_cudnn
=
use_cudnn
,
data_format
=
"NTC"
)
self
.
layer_norm
=
dg
.
LayerNorm
(
d_in
)
def
forward
(
self
,
input
):
"""
Feed Forward Network.
Args:
input (Variable): Shape(B, T, C), dtype: float32. The input value.
Returns:
output (Variable), Shape(B, T, C), the result after FFN.
"""
#FFN Networt
x
=
self
.
w_2
(
layers
.
relu
(
self
.
w_1
(
input
)))
# dropout
x
=
layers
.
dropout
(
x
,
self
.
dropout
)
# residual connection
x
=
x
+
input
#layer normalization
output
=
self
.
layer_norm
(
x
)
return
output
\ No newline at end of file
parakeet/modules/layers.py
已删除
100644 → 0
浏览文件 @
fc84ca2d
import
math
import
numpy
as
np
import
paddle
from
paddle
import
fluid
import
paddle.fluid.dygraph
as
dg
class
Linear
(
dg
.
Layer
):
def
__init__
(
self
,
in_features
,
out_features
,
is_bias
=
True
,
dtype
=
"float32"
):
super
(
Linear
,
self
).
__init__
()
self
.
in_features
=
in_features
self
.
out_features
=
out_features
self
.
dtype
=
dtype
self
.
weight
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
())
self
.
bias
=
is_bias
if
is_bias
is
not
False
:
k
=
math
.
sqrt
(
1
/
in_features
)
self
.
bias
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
))
self
.
linear
=
dg
.
Linear
(
in_features
,
out_features
,
param_attr
=
self
.
weight
,
bias_attr
=
self
.
bias
,)
def
forward
(
self
,
x
):
x
=
self
.
linear
(
x
)
return
x
class
Conv
(
dg
.
Layer
):
def
__init__
(
self
,
in_channels
,
out_channels
,
filter_size
=
1
,
padding
=
0
,
dilation
=
1
,
stride
=
1
,
use_cudnn
=
True
,
data_format
=
"NCT"
,
is_bias
=
True
):
super
(
Conv
,
self
).
__init__
()
self
.
in_channels
=
in_channels
self
.
out_channels
=
out_channels
self
.
filter_size
=
filter_size
self
.
padding
=
padding
self
.
dilation
=
dilation
self
.
stride
=
stride
self
.
use_cudnn
=
use_cudnn
self
.
data_format
=
data_format
self
.
is_bias
=
is_bias
self
.
weight_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
())
self
.
bias_attr
=
None
if
is_bias
is
not
False
:
k
=
math
.
sqrt
(
1
/
in_channels
)
self
.
bias_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
))
self
.
conv
=
Conv1D
(
in_channels
=
in_channels
,
out_channels
=
out_channels
,
filter_size
=
filter_size
,
padding
=
padding
,
dilation
=
dilation
,
stride
=
stride
,
param_attr
=
self
.
weight_attr
,
bias_attr
=
self
.
bias_attr
,
use_cudnn
=
use_cudnn
,
data_format
=
data_format
)
def
forward
(
self
,
x
):
x
=
self
.
conv
(
x
)
return
x
class
Conv1D
(
dg
.
Layer
):
"""
A convolution 1D block implemented with Conv2D. Form simplicity and
ensuring the output has the same length as the input, it does not allow
stride > 1.
"""
def
__init__
(
self
,
in_channels
,
out_channels
,
filter_size
=
3
,
padding
=
0
,
dilation
=
1
,
stride
=
1
,
groups
=
None
,
param_attr
=
None
,
bias_attr
=
None
,
use_cudnn
=
True
,
act
=
None
,
data_format
=
'NCT'
,
dtype
=
"float32"
):
super
(
Conv1D
,
self
).
__init__
(
dtype
=
dtype
)
self
.
padding
=
padding
self
.
in_channels
=
in_channels
self
.
num_filters
=
out_channels
self
.
filter_size
=
filter_size
self
.
stride
=
stride
self
.
dilation
=
dilation
self
.
padding
=
padding
self
.
act
=
act
self
.
data_format
=
data_format
self
.
conv
=
dg
.
Conv2D
(
num_channels
=
in_channels
,
num_filters
=
out_channels
,
filter_size
=
(
1
,
filter_size
),
stride
=
(
1
,
stride
),
dilation
=
(
1
,
dilation
),
padding
=
(
0
,
padding
),
groups
=
groups
,
param_attr
=
param_attr
,
bias_attr
=
bias_attr
,
use_cudnn
=
use_cudnn
,
act
=
act
,
dtype
=
dtype
)
def
forward
(
self
,
x
):
"""
Args:
x (Variable): Shape(B, C_in, 1, T), the input, where C_in means
input channels.
Returns:
x (Variable): Shape(B, C_out, 1, T), the outputs, where C_out means
output channels (num_filters).
"""
if
self
.
data_format
==
'NTC'
:
x
=
fluid
.
layers
.
transpose
(
x
,
[
0
,
2
,
1
])
x
=
fluid
.
layers
.
unsqueeze
(
x
,
[
2
])
x
=
self
.
conv
(
x
)
x
=
fluid
.
layers
.
squeeze
(
x
,
[
2
])
if
self
.
data_format
==
'NTC'
:
x
=
fluid
.
layers
.
transpose
(
x
,
[
0
,
2
,
1
])
return
x
class
Pool1D
(
dg
.
Layer
):
"""
A Pool 1D block implemented with Pool2D.
"""
def
__init__
(
self
,
pool_size
=-
1
,
pool_type
=
'max'
,
pool_stride
=
1
,
pool_padding
=
0
,
global_pooling
=
False
,
use_cudnn
=
True
,
ceil_mode
=
False
,
exclusive
=
True
,
data_format
=
'NCT'
):
super
(
Pool1D
,
self
).
__init__
()
self
.
pool_size
=
pool_size
self
.
pool_type
=
pool_type
self
.
pool_stride
=
pool_stride
self
.
pool_padding
=
pool_padding
self
.
global_pooling
=
global_pooling
self
.
use_cudnn
=
use_cudnn
self
.
ceil_mode
=
ceil_mode
self
.
exclusive
=
exclusive
self
.
data_format
=
data_format
self
.
pool2d
=
dg
.
Pool2D
([
1
,
pool_size
],
pool_type
=
pool_type
,
pool_stride
=
[
1
,
pool_stride
],
pool_padding
=
[
0
,
pool_padding
],
global_pooling
=
global_pooling
,
use_cudnn
=
use_cudnn
,
ceil_mode
=
ceil_mode
,
exclusive
=
exclusive
)
def
forward
(
self
,
x
):
"""
Args:
x (Variable): Shape(B, C_in, 1, T), the input, where C_in means
input channels.
Returns:
x (Variable): Shape(B, C_out, 1, T), the outputs, where C_out means
output channels (num_filters).
"""
if
self
.
data_format
==
'NTC'
:
x
=
fluid
.
layers
.
transpose
(
x
,
[
0
,
2
,
1
])
x
=
fluid
.
layers
.
unsqueeze
(
x
,
[
2
])
x
=
self
.
pool2d
(
x
)
x
=
fluid
.
layers
.
squeeze
(
x
,
[
2
])
if
self
.
data_format
==
'NTC'
:
x
=
fluid
.
layers
.
transpose
(
x
,
[
0
,
2
,
1
])
return
x
parakeet/modules/multihead_attention.py
浏览文件 @
6908ec52
import
math
import
numpy
as
np
import
paddle.fluid
as
fluid
import
paddle.fluid.dygraph
as
dg
import
paddle.fluid.layers
as
layers
from
parakeet.modules.layers
import
Linear
class
Linear
(
dg
.
Layer
):
def
__init__
(
self
,
in_features
,
out_features
,
is_bias
=
True
,
dtype
=
"float32"
):
super
(
Linear
,
self
).
__init__
()
self
.
in_features
=
in_features
self
.
out_features
=
out_features
self
.
dtype
=
dtype
self
.
weight
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
XavierInitializer
())
self
.
bias
=
is_bias
if
is_bias
is
not
False
:
k
=
math
.
sqrt
(
1
/
in_features
)
self
.
bias
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
low
=-
k
,
high
=
k
))
self
.
linear
=
dg
.
Linear
(
in_features
,
out_features
,
param_attr
=
self
.
weight
,
bias_attr
=
self
.
bias
,)
def
forward
(
self
,
x
):
x
=
self
.
linear
(
x
)
return
x
class
ScaledDotProductAttention
(
dg
.
Layer
):
def
__init__
(
self
,
d_key
):
...
...
parakeet/modules/post_convnet.py
已删除
100644 → 0
浏览文件 @
fc84ca2d
import
paddle.fluid.dygraph
as
dg
import
paddle.fluid
as
fluid
import
paddle.fluid.layers
as
layers
from
parakeet.modules.layers
import
Conv
class
PostConvNet
(
dg
.
Layer
):
def
__init__
(
self
,
n_mels
=
80
,
num_hidden
=
512
,
filter_size
=
5
,
padding
=
0
,
num_conv
=
5
,
outputs_per_step
=
1
,
use_cudnn
=
True
,
dropout
=
0.1
,
batchnorm_last
=
False
):
super
(
PostConvNet
,
self
).
__init__
()
self
.
dropout
=
dropout
self
.
num_conv
=
num_conv
self
.
batchnorm_last
=
batchnorm_last
self
.
conv_list
=
[]
self
.
conv_list
.
append
(
Conv
(
in_channels
=
n_mels
*
outputs_per_step
,
out_channels
=
num_hidden
,
filter_size
=
filter_size
,
padding
=
padding
,
use_cudnn
=
use_cudnn
,
data_format
=
"NCT"
))
for
_
in
range
(
1
,
num_conv
-
1
):
self
.
conv_list
.
append
(
Conv
(
in_channels
=
num_hidden
,
out_channels
=
num_hidden
,
filter_size
=
filter_size
,
padding
=
padding
,
use_cudnn
=
use_cudnn
,
data_format
=
"NCT"
)
)
self
.
conv_list
.
append
(
Conv
(
in_channels
=
num_hidden
,
out_channels
=
n_mels
*
outputs_per_step
,
filter_size
=
filter_size
,
padding
=
padding
,
use_cudnn
=
use_cudnn
,
data_format
=
"NCT"
))
for
i
,
layer
in
enumerate
(
self
.
conv_list
):
self
.
add_sublayer
(
"conv_list_{}"
.
format
(
i
),
layer
)
self
.
batch_norm_list
=
[
dg
.
BatchNorm
(
num_hidden
,
data_layout
=
'NCHW'
)
for
_
in
range
(
num_conv
-
1
)]
if
self
.
batchnorm_last
:
self
.
batch_norm_list
.
append
(
dg
.
BatchNorm
(
n_mels
*
outputs_per_step
,
data_layout
=
'NCHW'
))
for
i
,
layer
in
enumerate
(
self
.
batch_norm_list
):
self
.
add_sublayer
(
"batch_norm_list_{}"
.
format
(
i
),
layer
)
def
forward
(
self
,
input
):
"""
Post Conv Net.
Args:
input (Variable): Shape(B, T, C), dtype: float32. The input value.
Returns:
output (Variable), Shape(B, T, C), the result after postconvnet.
"""
input
=
layers
.
transpose
(
input
,
[
0
,
2
,
1
])
len
=
input
.
shape
[
-
1
]
for
i
in
range
(
self
.
num_conv
-
1
):
batch_norm
=
self
.
batch_norm_list
[
i
]
conv
=
self
.
conv_list
[
i
]
input
=
layers
.
dropout
(
layers
.
tanh
(
batch_norm
(
conv
(
input
)[:,:,:
len
])),
self
.
dropout
)
conv
=
self
.
conv_list
[
self
.
num_conv
-
1
]
input
=
conv
(
input
)[:,:,:
len
]
if
self
.
batchnorm_last
:
batch_norm
=
self
.
batch_norm_list
[
self
.
num_conv
-
1
]
input
=
layers
.
dropout
(
batch_norm
(
input
),
self
.
dropout
)
output
=
layers
.
transpose
(
input
,
[
0
,
2
,
1
])
return
output
\ No newline at end of file
parakeet/modules/prenet.py
已删除
100644 → 0
浏览文件 @
fc84ca2d
import
paddle.fluid.dygraph
as
dg
import
paddle.fluid.layers
as
layers
from
parakeet.modules.layers
import
Linear
class
PreNet
(
dg
.
Layer
):
def
__init__
(
self
,
input_size
,
hidden_size
,
output_size
,
dropout_rate
=
0.2
):
"""
:param input_size: dimension of input
:param hidden_size: dimension of hidden unit
:param output_size: dimension of output
"""
super
(
PreNet
,
self
).
__init__
()
self
.
input_size
=
input_size
self
.
hidden_size
=
hidden_size
self
.
output_size
=
output_size
self
.
dropout_rate
=
dropout_rate
self
.
linear1
=
Linear
(
input_size
,
hidden_size
)
self
.
linear2
=
Linear
(
hidden_size
,
output_size
)
def
forward
(
self
,
x
):
"""
Pre Net before passing through the network.
Args:
x (Variable): Shape(B, T, C), dtype: float32. The input value.
Returns:
x (Variable), Shape(B, T, C), the result after pernet.
"""
x
=
layers
.
dropout
(
layers
.
relu
(
self
.
linear1
(
x
)),
self
.
dropout_rate
)
x
=
layers
.
dropout
(
layers
.
relu
(
self
.
linear2
(
x
)),
self
.
dropout_rate
)
return
x
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录