Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
28658cc1
D
DeepSpeech
项目概览
PaddlePaddle
/
DeepSpeech
大约 2 年 前同步成功
通知
210
Star
8425
Fork
1598
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
245
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
DeepSpeech
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
245
Issue
245
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
28658cc1
编写于
4月 16, 2021
作者:
H
Hui Zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix cmvn and print prarams
上级
48f4bda3
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
1593 addition
and
37 deletion
+1593
-37
.notebook/u2_model.ipynb
.notebook/u2_model.ipynb
+1555
-0
deepspeech/frontend/normalizer.py
deepspeech/frontend/normalizer.py
+11
-5
deepspeech/frontend/utility.py
deepspeech/frontend/utility.py
+2
-4
deepspeech/modules/mask.py
deepspeech/modules/mask.py
+1
-1
deepspeech/utils/layer_tools.py
deepspeech/utils/layer_tools.py
+24
-27
未找到文件。
.notebook/u2_model.ipynb
0 → 100644
浏览文件 @
28658cc1
此差异已折叠。
点击以展开。
deepspeech/frontend/normalizer.py
浏览文件 @
28658cc1
...
@@ -77,15 +77,19 @@ class FeatureNormalizer(object):
...
@@ -77,15 +77,19 @@ class FeatureNormalizer(object):
:param filepath: File to write mean and stddev.
:param filepath: File to write mean and stddev.
:type filepath: str
:type filepath: str
"""
"""
np
.
savez
(
filepath
,
mean
=
self
.
_mean
,
std
=
self
.
_
std
)
np
.
savez
(
filepath
,
mean
=
self
.
_mean
,
istd
=
self
.
_i
std
)
def
_read_mean_std_from_file
(
self
,
filepath
,
eps
=
1e-20
):
def
_read_mean_std_from_file
(
self
,
filepath
,
eps
=
1e-20
):
"""Load mean and std from file."""
"""Load mean and std from file."""
mean
,
std
=
load_cmvn
(
filepath
,
filetype
=
'npz'
)
mean
,
i
std
=
load_cmvn
(
filepath
,
filetype
=
'npz'
)
self
.
_mean
=
mean
.
T
self
.
_mean
=
mean
.
T
self
.
_istd
=
1.0
/
std
.
T
self
.
_istd
=
i
std
.
T
def
_compute_mean_std
(
self
,
manifest_path
,
featurize_func
,
num_samples
):
def
_compute_mean_std
(
self
,
manifest_path
,
featurize_func
,
num_samples
,
eps
=
1e-20
):
"""Compute mean and std from randomly sampled instances."""
"""Compute mean and std from randomly sampled instances."""
manifest
=
read_manifest
(
manifest_path
)
manifest
=
read_manifest
(
manifest_path
)
if
num_samples
==
-
1
:
if
num_samples
==
-
1
:
...
@@ -98,4 +102,6 @@ class FeatureNormalizer(object):
...
@@ -98,4 +102,6 @@ class FeatureNormalizer(object):
featurize_func
(
AudioSegment
.
from_file
(
instance
[
"feat"
])))
featurize_func
(
AudioSegment
.
from_file
(
instance
[
"feat"
])))
features
=
np
.
hstack
(
features
)
#(D, T)
features
=
np
.
hstack
(
features
)
#(D, T)
self
.
_mean
=
np
.
mean
(
features
,
axis
=
1
).
reshape
([
1
,
-
1
])
#(1, D)
self
.
_mean
=
np
.
mean
(
features
,
axis
=
1
).
reshape
([
1
,
-
1
])
#(1, D)
self
.
_std
=
np
.
std
(
features
,
axis
=
1
).
reshape
([
1
,
-
1
])
#(1, D)
std
=
np
.
std
(
features
,
axis
=
1
).
reshape
([
1
,
-
1
])
#(1, D)
std
=
np
.
clip
(
std
,
eps
,
None
)
self
.
_istd
=
1.0
/
std
deepspeech/frontend/utility.py
浏览文件 @
28658cc1
...
@@ -238,10 +238,8 @@ def _load_kaldi_cmvn(kaldi_cmvn_file):
...
@@ -238,10 +238,8 @@ def _load_kaldi_cmvn(kaldi_cmvn_file):
def
_load_npz_cmvn
(
npz_cmvn_file
,
eps
=
1e-20
):
def
_load_npz_cmvn
(
npz_cmvn_file
,
eps
=
1e-20
):
npzfile
=
np
.
load
(
npz_cmvn_file
)
npzfile
=
np
.
load
(
npz_cmvn_file
)
means
=
npzfile
[
"mean"
]
#(1, D)
means
=
npzfile
[
"mean"
]
#(1, D)
std
=
npzfile
[
"std"
]
#(1, D)
istd
=
npzfile
[
"istd"
]
#(1, D)
std
=
np
.
clip
(
std
,
eps
,
None
)
cmvn
=
np
.
array
([
means
,
istd
])
variance
=
1.0
/
std
cmvn
=
np
.
array
([
means
,
variance
])
return
cmvn
return
cmvn
...
...
deepspeech/modules/mask.py
浏览文件 @
28658cc1
...
@@ -25,7 +25,7 @@ __all__ = [
...
@@ -25,7 +25,7 @@ __all__ = [
def
sequence_mask
(
x_len
,
max_len
=
None
,
dtype
=
'float32'
):
def
sequence_mask
(
x_len
,
max_len
=
None
,
dtype
=
'float32'
):
"""
[summary]
"""
batch sequence mask.
Args:
Args:
x_len ([paddle.Tensor]): xs lenght, [B]
x_len ([paddle.Tensor]): xs lenght, [B]
...
...
deepspeech/utils/layer_tools.py
浏览文件 @
28658cc1
...
@@ -22,8 +22,6 @@ __all__ = [
...
@@ -22,8 +22,6 @@ __all__ = [
def
summary
(
layer
:
nn
.
Layer
,
print_func
=
print
):
def
summary
(
layer
:
nn
.
Layer
,
print_func
=
print
):
num_params
=
num_elements
=
0
num_params
=
num_elements
=
0
if
print_func
:
print_func
(
f
"
{
layer
.
__class__
.
__name__
}
summary:"
)
for
name
,
param
in
layer
.
state_dict
().
items
():
for
name
,
param
in
layer
.
state_dict
().
items
():
if
print_func
:
if
print_func
:
print_func
(
print_func
(
...
@@ -31,9 +29,7 @@ def summary(layer: nn.Layer, print_func=print):
...
@@ -31,9 +29,7 @@ def summary(layer: nn.Layer, print_func=print):
num_elements
+=
np
.
prod
(
param
.
shape
)
num_elements
+=
np
.
prod
(
param
.
shape
)
num_params
+=
1
num_params
+=
1
if
print_func
:
if
print_func
:
print_func
(
print_func
(
f
"Total parameters:
{
num_params
}
,
{
num_elements
}
elements."
)
f
"
{
layer
.
__class__
.
__name__
}
has
{
num_params
}
parameters,
{
num_elements
}
elements."
)
def
gradient_norm
(
layer
:
nn
.
Layer
):
def
gradient_norm
(
layer
:
nn
.
Layer
):
...
@@ -45,25 +41,6 @@ def gradient_norm(layer: nn.Layer):
...
@@ -45,25 +41,6 @@ def gradient_norm(layer: nn.Layer):
return
grad_norm_dict
return
grad_norm_dict
def
recursively_remove_weight_norm
(
layer
:
nn
.
Layer
):
for
layer
in
layer
.
sublayers
():
try
:
nn
.
utils
.
remove_weight_norm
(
layer
)
except
ValueError
as
e
:
# ther is not weight norm hoom in this layer
pass
def
freeze
(
layer
:
nn
.
Layer
):
for
param
in
layer
.
parameters
():
param
.
trainable
=
False
def
unfreeze
(
layer
:
nn
.
Layer
):
for
param
in
layer
.
parameters
():
param
.
trainable
=
True
def
print_grads
(
model
,
print_func
=
print
):
def
print_grads
(
model
,
print_func
=
print
):
if
print_func
is
None
:
if
print_func
is
None
:
return
return
...
@@ -75,12 +52,32 @@ def print_grads(model, print_func=print):
...
@@ -75,12 +52,32 @@ def print_grads(model, print_func=print):
def
print_params
(
model
,
print_func
=
print
):
def
print_params
(
model
,
print_func
=
print
):
if
print_func
is
None
:
if
print_func
is
None
:
return
return
total
=
0.0
total
=
0.0
num_params
=
0.0
for
n
,
p
in
model
.
named_parameters
():
for
n
,
p
in
model
.
named_parameters
():
msg
=
f
"
param:
{
n
}
: shape:
{
p
.
shape
}
stop_grad:
{
p
.
stop_gradient
}
"
msg
=
f
"
{
n
}
|
{
p
.
shape
}
|
{
np
.
prod
(
p
.
shape
)
}
|
{
not
p
.
stop_gradient
}
"
total
+=
np
.
prod
(
p
.
shape
)
total
+=
np
.
prod
(
p
.
shape
)
num_params
+=
1
if
print_func
:
if
print_func
:
print_func
(
msg
)
print_func
(
msg
)
if
print_func
:
if
print_func
:
print_func
(
f
"Total parameters:
{
total
}
!"
)
print_func
(
f
"Total parameters:
{
num_params
}
,
{
total
}
elements."
)
def
recursively_remove_weight_norm
(
layer
:
nn
.
Layer
):
for
layer
in
layer
.
sublayers
():
try
:
nn
.
utils
.
remove_weight_norm
(
layer
)
except
ValueError
as
e
:
# ther is not weight norm hoom in this layer
pass
def
freeze
(
layer
:
nn
.
Layer
):
for
param
in
layer
.
parameters
():
param
.
trainable
=
False
def
unfreeze
(
layer
:
nn
.
Layer
):
for
param
in
layer
.
parameters
():
param
.
trainable
=
True
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录