Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
016ed6d6
D
DeepSpeech
项目概览
PaddlePaddle
/
DeepSpeech
大约 1 年 前同步成功
通知
207
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
016ed6d6
编写于
3月 04, 2022
作者:
X
xiongxinlei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
repair the code according to the part comment, test=doc
上级
97ec0126
变更
11
显示空白变更内容
内联
并排
Showing
11 changed file
with
182 addition
and
85 deletion
+182
-85
examples/voxceleb/sv0/local/speaker_verification_cosine.py
examples/voxceleb/sv0/local/speaker_verification_cosine.py
+55
-53
examples/voxceleb/sv0/local/train.py
examples/voxceleb/sv0/local/train.py
+10
-9
paddleaudio/datasets/voxceleb.py
paddleaudio/datasets/voxceleb.py
+3
-0
paddleaudio/utils/download.py
paddleaudio/utils/download.py
+13
-21
paddlespeech/vector/io/batch.py
paddlespeech/vector/io/batch.py
+0
-0
paddlespeech/vector/modules/loss.py
paddlespeech/vector/modules/loss.py
+1
-2
paddlespeech/vector/modules/lr.py
paddlespeech/vector/modules/lr.py
+0
-0
paddlespeech/vector/modules/sid_model.py
paddlespeech/vector/modules/sid_model.py
+0
-0
paddlespeech/vector/training/metrics.py
paddlespeech/vector/training/metrics.py
+28
-0
paddlespeech/vector/utils/download.py
paddlespeech/vector/utils/download.py
+72
-0
paddlespeech/vector/utils/time.py
paddlespeech/vector/utils/time.py
+0
-0
未找到文件。
examples/voxceleb/sv0/local/speaker_verification_cosine.py
浏览文件 @
016ed6d6
...
...
@@ -11,21 +11,21 @@
# 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
argparse
import
ast
import
os
import
numpy
as
np
import
paddle
import
paddle.nn.functional
as
F
from
paddle.io
import
BatchSampler
from
paddle.io
import
DataLoader
import
paddle.nn.functional
as
F
from
paddlespeech.vector.training.metrics
import
compute_eer
from
tqdm
import
tqdm
from
paddleaudio.datasets.voxceleb
import
VoxCeleb1
from
paddlespeech.vector.models.ecapa_tdnn
import
EcapaTdnn
from
paddlespeech.vector.
training
.sid_model
import
SpeakerIdetification
from
tqdm
import
tqdm
from
paddlespeech.vector.
modules
.sid_model
import
SpeakerIdetification
from
paddlespeech.vector.training.metrics
import
compute_eer
def
pad_right_2d
(
x
,
target_length
,
axis
=-
1
,
mode
=
'constant'
,
**
kwargs
):
...
...
@@ -44,7 +44,7 @@ def pad_right_2d(x, target_length, axis=-1, mode='constant', **kwargs):
return
np
.
pad
(
x
,
pad_width
,
mode
=
mode
,
**
kwargs
)
def
feature_normalize
(
batch
,
mean_norm
:
bool
=
True
,
std_norm
:
bool
=
True
):
def
feature_normalize
(
batch
,
mean_norm
:
bool
=
True
,
std_norm
:
bool
=
True
):
ids
=
[
item
[
'id'
]
for
item
in
batch
]
lengths
=
np
.
asarray
([
item
[
'feat'
].
shape
[
1
]
for
item
in
batch
])
feats
=
list
(
...
...
@@ -58,8 +58,8 @@ def feature_normalize(batch, mean_norm: bool = True, std_norm: bool = True):
mean
=
feat
.
mean
(
axis
=-
1
,
keepdims
=
True
)
if
mean_norm
else
0
std
=
feat
.
std
(
axis
=-
1
,
keepdims
=
True
)
if
std_norm
else
1
feats
[
i
][:,
:
lengths
[
i
]]
=
(
feat
-
mean
)
/
std
assert
feats
[
i
][:,
lengths
[
i
]:].
sum
(
)
==
0
# Padding valus should all be 0.
assert
feats
[
i
][:,
lengths
[
i
]:].
sum
(
)
==
0
# Padding valus should all be 0.
# Converts into ratios.
lengths
=
(
lengths
/
lengths
.
max
()).
astype
(
np
.
float32
)
...
...
@@ -98,15 +98,15 @@ def main(args):
print
(
f
'Checkpoint loaded from
{
args
.
load_checkpoint
}
'
)
# stage4: construct the enroll and test dataloader
enrol_ds
=
VoxCeleb1
(
subset
=
'enrol'
,
enrol_ds
=
VoxCeleb1
(
subset
=
'enrol'
,
feat_type
=
'melspectrogram'
,
random_chunk
=
False
,
n_mels
=
80
,
window_size
=
400
,
hop_length
=
160
)
enrol_sampler
=
BatchSampler
(
enrol_ds
,
batch_size
=
args
.
batch_size
,
enrol_ds
,
batch_size
=
args
.
batch_size
,
shuffle
=
True
)
# Shuffle to make embedding normalization more robust.
enrol_loader
=
DataLoader
(
enrol_ds
,
batch_sampler
=
enrol_sampler
,
...
...
@@ -115,16 +115,16 @@ def main(args):
num_workers
=
args
.
num_workers
,
return_list
=
True
,)
test_ds
=
VoxCeleb1
(
subset
=
'test'
,
test_ds
=
VoxCeleb1
(
subset
=
'test'
,
feat_type
=
'melspectrogram'
,
random_chunk
=
False
,
n_mels
=
80
,
window_size
=
400
,
hop_length
=
160
)
test_sampler
=
BatchSampler
(
test_ds
,
batch_size
=
args
.
batch_size
,
shuffle
=
True
)
test_sampler
=
BatchSampler
(
test_ds
,
batch_size
=
args
.
batch_size
,
shuffle
=
True
)
test_loader
=
DataLoader
(
test_ds
,
batch_sampler
=
test_sampler
,
collate_fn
=
lambda
x
:
feature_normalize
(
...
...
@@ -169,12 +169,13 @@ def main(args):
embedding_mean
,
embedding_std
=
mean
,
std
else
:
weight
=
1
/
batch_count
# Weight decay by batches.
embedding_mean
=
(
1
-
weight
)
*
embedding_mean
+
weight
*
mean
embedding_std
=
(
1
-
weight
)
*
embedding_std
+
weight
*
std
embedding_mean
=
(
1
-
weight
)
*
embedding_mean
+
weight
*
mean
embedding_std
=
(
1
-
weight
)
*
embedding_std
+
weight
*
std
# Apply global embedding normalization.
embeddings
=
(
embeddings
-
embedding_mean
)
/
embedding_std
embeddings
=
(
embeddings
-
embedding_mean
)
/
embedding_std
# Update embedding dict.
id2embedding
.
update
(
dict
(
zip
(
ids
,
embeddings
)))
...
...
@@ -201,6 +202,7 @@ def main(args):
f
'EER of verification test:
{
EER
*
100
:.
4
f
}
%, score threshold:
{
threshold
:.
5
f
}
'
)
if
__name__
==
"__main__"
:
# yapf: disable
parser
=
argparse
.
ArgumentParser
(
__doc__
)
...
...
examples/voxceleb/sv0/local/train.py
浏览文件 @
016ed6d6
...
...
@@ -22,22 +22,23 @@ from paddle.io import DistributedBatchSampler
from
paddleaudio.datasets.voxceleb
import
VoxCeleb1
from
paddleaudio.features.core
import
melspectrogram
from
paddlespeech.vector.training.time
import
Timer
from
paddlespeech.vector.datasets.batch
import
feature_normalize
from
paddlespeech.vector.datasets.batch
import
waveform_collate_fn
from
paddlespeech.vector.layers.loss
import
AdditiveAngularMargin
from
paddlespeech.vector.layers.loss
import
LogSoftmaxWrapper
from
paddlespeech.vector.layers.lr
import
CyclicLRScheduler
from
paddlespeech.vector.io.batch
import
feature_normalize
from
paddlespeech.vector.io.batch
import
waveform_collate_fn
from
paddlespeech.vector.models.ecapa_tdnn
import
EcapaTdnn
from
paddlespeech.vector.training.sid_model
import
SpeakerIdetification
from
paddlespeech.vector.modules.loss
import
AdditiveAngularMargin
from
paddlespeech.vector.modules.loss
import
LogSoftmaxWrapper
from
paddlespeech.vector.modules.lr
import
CyclicLRScheduler
from
paddlespeech.vector.modules.sid_model
import
SpeakerIdetification
from
paddlespeech.vector.utils.time
import
Timer
# feat configuration
cpu_feat_conf
=
{
'n_mels'
:
80
,
'window_size'
:
400
,
'hop_length'
:
160
,
'window_size'
:
400
,
#ms
'hop_length'
:
160
,
#ms
}
def
main
(
args
):
# stage0: set the training device, cpu or gpu
paddle
.
set_device
(
args
.
device
)
...
...
paddleaudio/datasets/voxceleb.py
浏览文件 @
016ed6d6
...
...
@@ -76,6 +76,9 @@ class VoxCeleb1(Dataset):
'META_INFO'
,
(
'id'
,
'duration'
,
'wav'
,
'start'
,
'stop'
,
'spk_id'
))
base_path
=
os
.
path
.
join
(
DATA_HOME
,
'vox1'
)
wav_path
=
os
.
path
.
join
(
base_path
,
'wav'
)
meta_path
=
os
.
path
.
join
(
base_path
,
'meta'
)
veri_test_file
=
os
.
path
.
join
(
meta_path
,
'veri_test2.txt'
)
csv_path
=
os
.
path
.
join
(
base_path
,
'csv'
)
subsets
=
[
'train'
,
'dev'
,
'enrol'
,
'test'
]
def
__init__
(
...
...
paddleaudio/utils/download.py
浏览文件 @
016ed6d6
...
...
@@ -22,30 +22,22 @@ from .log import logger
download
.
logger
=
logger
__all__
=
[
'decompress'
,
'download_and_decompress'
,
'load_state_dict_from_url'
,
]
def
decompress
(
file
:
str
,
path
:
str
=
os
.
PathLike
):
def
decompress
(
file
:
str
):
"""
Extracts all files from a compressed file
to specific path
.
Extracts all files from a compressed file.
"""
assert
os
.
path
.
isfile
(
file
),
"File: {} not exists."
.
format
(
file
)
if
path
is
None
:
print
(
"decompress the data: {}"
.
format
(
file
))
download
.
_decompress
(
file
)
else
:
print
(
"decompress the data: {} to {}"
.
format
(
file
,
path
))
if
not
os
.
path
.
isdir
(
path
):
os
.
makedirs
(
path
)
tmp_file
=
os
.
path
.
join
(
path
,
os
.
path
.
basename
(
file
))
os
.
rename
(
file
,
tmp_file
)
download
.
_decompress
(
tmp_file
)
os
.
rename
(
tmp_file
,
file
)
def
download_and_decompress
(
archives
:
List
[
Dict
[
str
,
str
]],
path
:
str
,
decompress
:
bool
=
True
):
def
download_and_decompress
(
archives
:
List
[
Dict
[
str
,
str
]],
path
:
str
):
"""
Download archieves and decompress to specific path.
"""
...
...
@@ -55,8 +47,8 @@ def download_and_decompress(archives: List[Dict[str, str]],
for
archive
in
archives
:
assert
'url'
in
archive
and
'md5'
in
archive
,
\
'Dictionary keys of "url" and "md5" are required in the archive, but got: {list(archieve.keys())}'
download
.
get_path_from_url
(
archive
[
'url'
],
path
,
archive
[
'md5'
],
decompress
=
decompress
)
download
.
get_path_from_url
(
archive
[
'url'
],
path
,
archive
[
'md5'
]
)
def
load_state_dict_from_url
(
url
:
str
,
path
:
str
,
md5
:
str
=
None
):
...
...
paddlespeech/vector/
datasets
/batch.py
→
paddlespeech/vector/
io
/batch.py
浏览文件 @
016ed6d6
文件已移动
paddlespeech/vector/
layer
s/loss.py
→
paddlespeech/vector/
module
s/loss.py
浏览文件 @
016ed6d6
...
...
@@ -11,7 +11,6 @@
# 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
paddle
...
...
paddlespeech/vector/
layer
s/lr.py
→
paddlespeech/vector/
module
s/lr.py
浏览文件 @
016ed6d6
文件已移动
paddlespeech/vector/
training
/sid_model.py
→
paddlespeech/vector/
modules
/sid_model.py
浏览文件 @
016ed6d6
文件已移动
paddlespeech/vector/training/metrics.py
0 → 100644
浏览文件 @
016ed6d6
# Copyright (c) 2021 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.
from
typing
import
List
import
numpy
as
np
from
sklearn.metrics
import
roc_curve
def
compute_eer
(
labels
:
np
.
ndarray
,
scores
:
np
.
ndarray
)
->
List
[
float
]:
'''
Compute EER and return score threshold.
'''
fpr
,
tpr
,
threshold
=
roc_curve
(
y_true
=
labels
,
y_score
=
scores
)
fnr
=
1
-
tpr
eer_threshold
=
threshold
[
np
.
nanargmin
(
np
.
absolute
((
fnr
-
fpr
)))]
eer
=
fpr
[
np
.
nanargmin
(
np
.
absolute
((
fnr
-
fpr
)))]
return
eer
,
eer_threshold
paddlespeech/vector/utils/download.py
0 → 100644
浏览文件 @
016ed6d6
# Copyright (c) 2021 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
os
from
typing
import
Dict
from
typing
import
List
from
paddle.framework
import
load
as
load_state_dict
from
paddle.utils
import
download
__all__
=
[
'decompress'
,
'download_and_decompress'
,
'load_state_dict_from_url'
,
]
def
decompress
(
file
:
str
,
path
:
str
=
os
.
PathLike
):
"""
Extracts all files from a compressed file to specific path.
"""
assert
os
.
path
.
isfile
(
file
),
"File: {} not exists."
.
format
(
file
)
if
path
is
None
:
print
(
"decompress the data: {}"
.
format
(
file
))
download
.
_decompress
(
file
)
else
:
print
(
"decompress the data: {} to {}"
.
format
(
file
,
path
))
if
not
os
.
path
.
isdir
(
path
):
os
.
makedirs
(
path
)
tmp_file
=
os
.
path
.
join
(
path
,
os
.
path
.
basename
(
file
))
os
.
rename
(
file
,
tmp_file
)
download
.
_decompress
(
tmp_file
)
os
.
rename
(
tmp_file
,
file
)
def
download_and_decompress
(
archives
:
List
[
Dict
[
str
,
str
]],
path
:
str
,
decompress
:
bool
=
True
):
"""
Download archieves and decompress to specific path.
"""
if
not
os
.
path
.
isdir
(
path
):
os
.
makedirs
(
path
)
for
archive
in
archives
:
assert
'url'
in
archive
and
'md5'
in
archive
,
\
'Dictionary keys of "url" and "md5" are required in the archive, but got: {list(archieve.keys())}'
download
.
get_path_from_url
(
archive
[
'url'
],
path
,
archive
[
'md5'
],
decompress
=
decompress
)
def
load_state_dict_from_url
(
url
:
str
,
path
:
str
,
md5
:
str
=
None
):
"""
Download and load a state dict from url
"""
if
not
os
.
path
.
isdir
(
path
):
os
.
makedirs
(
path
)
download
.
get_path_from_url
(
url
,
path
,
md5
)
return
load_state_dict
(
os
.
path
.
join
(
path
,
os
.
path
.
basename
(
url
)))
paddlespeech/vector/
training
/time.py
→
paddlespeech/vector/
utils
/time.py
浏览文件 @
016ed6d6
文件已移动
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录