Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
052d329c
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看板
提交
052d329c
编写于
3月 11, 2022
作者:
K
KP
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add benchmark.
上级
7c3a11cc
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
142 addition
and
193 deletion
+142
-193
paddleaudio/tests/benchmark/README.md
paddleaudio/tests/benchmark/README.md
+25
-30
paddleaudio/tests/benchmark/features.py
paddleaudio/tests/benchmark/features.py
+117
-0
paddleaudio/tests/benchmark/features/__init__.py
paddleaudio/tests/benchmark/features/__init__.py
+0
-13
paddleaudio/tests/benchmark/features/log_mel_spectrogram.py
paddleaudio/tests/benchmark/features/log_mel_spectrogram.py
+0
-50
paddleaudio/tests/benchmark/features/mel_spectrogram.py
paddleaudio/tests/benchmark/features/mel_spectrogram.py
+0
-50
paddleaudio/tests/benchmark/features/mfcc.py
paddleaudio/tests/benchmark/features/mfcc.py
+0
-50
未找到文件。
paddleaudio/tests/benchmark/README.md
浏览文件 @
052d329c
# 1. Prepare
# 1. Prepare
First, install
`
line_profiler
`
via pip.
First, install
`
pytest-benchmark
`
via pip.
```
sh
```
sh
pip
install
line_profiler
pip
install
pytest-benchmark
```
```
# 2. Run
# 2. Run
Run the specific script for profiling.
Run the specific script for profiling.
```
sh
```
sh
kernprof
-l
features/mel_spectrogram.py
pytest features.py
python
-m
line_profiler
-u
1e-3 mel_spectrogram.py.lprof
```
```
Result:
Result:
```
sh
```
sh
Timer unit: 0.001 s
==========================================================================
test
session starts
==========================================================================
platform linux
--
Python 3.7.7, pytest-7.0.1, pluggy-1.0.0
benchmark: 3.4.1
(
defaults:
timer
=
time.perf_counter
disable_gc
=
False
min_rounds
=
5
min_time
=
0.000005
max_time
=
1.0
calibration_precision
=
10
warmup
=
False
warmup_iterations
=
100000
)
rootdir: /ssd3/chenxiaojie06/PaddleSpeech/DeepSpeech/paddleaudio
plugins: typeguard-2.12.1, benchmark-3.4.1, anyio-3.5.0
collected 6 items
Total
time
: 22.1208 s
features.py ......
[
100%]
File: features/mel_spectrogram.py
Function: test_melspect_cpu at line 13
Line
# Hits Time Per Hit % Time Line Contents
==============================================================
13 @profile
14 def test_melspect_cpu
(
input_shape,
times
)
:
15 1 0.1 0.1 0.0 paddle.set_device
(
'cpu'
)
16 1 234.5 234.5 1.1 x
=
paddle.randn
(
input_shape
)
17 1 85.3 85.3 0.4 feature_extractor
=
paddleaudio.features.MelSpectrogram
(
**
feat_conf,
dtype
=
x.dtype
)
18 101 0.5 0.0 0.0
for
i
in
range
(
times
)
:
19 100 21800.5 218.0 98.6 y
=
feature_extractor
(
x
)
Total
time
: 4.80543 s
-------------------------------------------------------------------------------------------------
benchmark: 6 tests
------------------------------------------------------------------------------------------------
File: features/mel_spectrogram.py
Name
(
time
in
us
)
Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
Function: test_melspect_gpu at line 22
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_melspect_gpu 632.2041
(
1.0
)
898.7449
(
1.0
)
709.3824
(
1.0
)
109.7022
(
6.91
)
676.1923
(
1.0
)
115.2642
(
22.19
)
1
;
0 1,409.6768
(
1.0
)
5 1
test_log_melspect_gpu 912.9159
(
1.44
)
1,222.0535
(
1.36
)
931.2489
(
1.31
)
34.4270
(
2.17
)
924.9896
(
1.37
)
5.1949
(
1.0
)
4
;
13 1,073.8268
(
0.76
)
82 1
test_mfcc_gpu 1,244.8374
(
1.97
)
1,321.3232
(
1.47
)
1,262.1319
(
1.78
)
15.8698
(
1.0
)
1,258.3155
(
1.86
)
14.1086
(
2.72
)
17
;
9 792.3102
(
0.56
)
91 1
test_melspect_cpu 19,106.5744
(
30.22
)
46,194.2125
(
51.40
)
27,458.7850
(
38.71
)
9,786.1071
(
616.65
)
23,830.0692
(
35.24
)
14,344.4724
(>
1000.0
)
3
;
0 36.4182
(
0.03
)
14 1
test_log_melspect_cpu 19,513.7132
(
30.87
)
20,367.2443
(
22.66
)
19,765.4018
(
27.86
)
167.1289
(
10.53
)
19,750.2729
(
29.21
)
188.9346
(
36.37
)
16
;
1 50.5935
(
0.04
)
49 1
test_mfcc_cpu 19,881.3528
(
31.45
)
20,427.2158
(
22.73
)
20,104.6574
(
28.34
)
129.5621
(
8.16
)
20,075.8977
(
29.69
)
150.9022
(
29.05
)
12
;
2 49.7397
(
0.04
)
48 1
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line
# Hits Time Per Hit % Time Line Contents
Legend:
==============================================================
Outliers: 1 Standard Deviation from Mean
;
1.5 IQR
(
InterQuartile Range
)
from 1st Quartile and 3rd Quartile.
22 @profile
OPS: Operations Per Second, computed as 1 / Mean
23 def test_melspect_gpu
(
input_shape,
times
)
:
==========================================================================
6 passed
in
20.51s
===========================================================================
24 1 0.5 0.5 0.0 paddle.set_device
(
'gpu'
)
25 1 4144.8 4144.8 86.3 x
=
paddle.randn
(
input_shape
)
26 1 41.9 41.9 0.9 feature_extractor
=
paddleaudio.features.MelSpectrogram
(
**
feat_conf,
dtype
=
x.dtype
)
27 101 0.2 0.0 0.0
for
i
in
range
(
times
)
:
28 100 618.1 6.2 12.9 y
=
feature_extractor
(
x
)
```
```
paddleaudio/tests/benchmark/features.py
0 → 100644
浏览文件 @
052d329c
# Copyright (c) 2022 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
librosa
import
numpy
as
np
import
paddle
import
paddleaudio
# Feature conf
mel_conf
=
{
'sr'
:
16000
,
'n_fft'
:
512
,
'hop_length'
:
128
,
'n_mels'
:
40
,
}
mfcc_conf
=
{
'n_mfcc'
:
20
,
'top_db'
:
80.0
,
}
mfcc_conf
.
update
(
mel_conf
)
input_shape
=
(
48000
)
waveform
=
np
.
random
.
random
(
size
=
input_shape
)
waveform_tensor
=
paddle
.
to_tensor
(
waveform
).
unsqueeze
(
0
)
def
enable_cpu_device
():
paddle
.
set_device
(
'cpu'
)
def
enable_gpu_device
():
paddle
.
set_device
(
'gpu'
)
mel_extractor
=
paddleaudio
.
features
.
MelSpectrogram
(
**
mel_conf
,
f_min
=
0.0
,
dtype
=
waveform_tensor
.
dtype
)
def
melspectrogram
():
return
mel_extractor
(
waveform_tensor
).
squeeze
(
0
)
def
test_melspect_cpu
(
benchmark
):
enable_cpu_device
()
feature_paddleaudio
=
benchmark
(
melspectrogram
)
feature_librosa
=
librosa
.
feature
.
melspectrogram
(
waveform
,
**
mel_conf
)
np
.
testing
.
assert_array_almost_equal
(
feature_librosa
,
feature_paddleaudio
,
decimal
=
4
)
def
test_melspect_gpu
(
benchmark
):
enable_gpu_device
()
feature_paddleaudio
=
benchmark
(
melspectrogram
)
feature_librosa
=
librosa
.
feature
.
melspectrogram
(
waveform
,
**
mel_conf
)
np
.
testing
.
assert_array_almost_equal
(
feature_librosa
,
feature_paddleaudio
,
decimal
=
4
)
log_mel_extractor
=
paddleaudio
.
features
.
LogMelSpectrogram
(
**
mel_conf
,
f_min
=
0.0
,
dtype
=
waveform_tensor
.
dtype
)
def
log_melspectrogram
():
return
log_mel_extractor
(
waveform_tensor
).
squeeze
(
0
)
def
test_log_melspect_cpu
(
benchmark
):
enable_cpu_device
()
feature_paddleaudio
=
benchmark
(
log_melspectrogram
)
feature_librosa
=
librosa
.
feature
.
melspectrogram
(
waveform
,
**
mel_conf
)
feature_librosa
=
librosa
.
power_to_db
(
feature_librosa
,
top_db
=
None
)
np
.
testing
.
assert_array_almost_equal
(
feature_librosa
,
feature_paddleaudio
,
decimal
=
4
)
def
test_log_melspect_gpu
(
benchmark
):
enable_gpu_device
()
feature_paddleaudio
=
benchmark
(
log_melspectrogram
)
feature_librosa
=
librosa
.
feature
.
melspectrogram
(
waveform
,
**
mel_conf
)
feature_librosa
=
librosa
.
power_to_db
(
feature_librosa
,
top_db
=
None
)
np
.
testing
.
assert_array_almost_equal
(
feature_librosa
,
feature_paddleaudio
,
decimal
=
4
)
mfcc_extractor
=
paddleaudio
.
features
.
MFCC
(
**
mfcc_conf
,
f_min
=
0.0
,
dtype
=
waveform_tensor
.
dtype
)
def
mfcc
():
return
mfcc_extractor
(
waveform_tensor
).
squeeze
(
0
)
def
test_mfcc_cpu
(
benchmark
):
enable_cpu_device
()
feature_paddleaudio
=
benchmark
(
mfcc
)
feature_librosa
=
librosa
.
feature
.
mfcc
(
waveform
,
**
mel_conf
)
np
.
testing
.
assert_array_almost_equal
(
feature_librosa
,
feature_paddleaudio
,
decimal
=
4
)
def
test_mfcc_gpu
(
benchmark
):
enable_gpu_device
()
feature_paddleaudio
=
benchmark
(
mfcc
)
feature_librosa
=
librosa
.
feature
.
mfcc
(
waveform
,
**
mel_conf
)
np
.
testing
.
assert_array_almost_equal
(
feature_librosa
,
feature_paddleaudio
,
decimal
=
4
)
paddleaudio/tests/benchmark/features/__init__.py
已删除
100644 → 0
浏览文件 @
7c3a11cc
# Copyright (c) 2022 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.
paddleaudio/tests/benchmark/features/log_mel_spectrogram.py
已删除
100644 → 0
浏览文件 @
7c3a11cc
# Copyright (c) 2022 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
paddle
import
paddleaudio
feat_conf
=
{
'sr'
:
16000
,
'n_fft'
:
512
,
'hop_length'
:
128
,
'n_mels'
:
40
,
'f_min'
:
0.0
,
}
@
profile
def
test_log_melspect_cpu
(
input_shape
,
times
):
paddle
.
set_device
(
'cpu'
)
x
=
paddle
.
randn
(
input_shape
)
feature_extractor
=
paddleaudio
.
features
.
LogMelSpectrogram
(
**
feat_conf
,
dtype
=
x
.
dtype
)
for
i
in
range
(
times
):
y
=
feature_extractor
(
x
)
@
profile
def
test_log_melspect_gpu
(
input_shape
,
times
):
paddle
.
set_device
(
'gpu'
)
x
=
paddle
.
randn
(
input_shape
)
feature_extractor
=
paddleaudio
.
features
.
LogMelSpectrogram
(
**
feat_conf
,
dtype
=
x
.
dtype
)
for
i
in
range
(
times
):
y
=
feature_extractor
(
x
)
input_shape
=
(
16
,
48000
)
# (N, T)
times
=
100
test_log_melspect_cpu
(
input_shape
,
times
)
test_log_melspect_gpu
(
input_shape
,
times
)
paddleaudio/tests/benchmark/features/mel_spectrogram.py
已删除
100644 → 0
浏览文件 @
7c3a11cc
# Copyright (c) 2022 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
paddle
import
paddleaudio
feat_conf
=
{
'sr'
:
16000
,
'n_fft'
:
512
,
'hop_length'
:
128
,
'n_mels'
:
40
,
'f_min'
:
0.0
,
}
@
profile
def
test_melspect_cpu
(
input_shape
,
times
):
paddle
.
set_device
(
'cpu'
)
x
=
paddle
.
randn
(
input_shape
)
feature_extractor
=
paddleaudio
.
features
.
MelSpectrogram
(
**
feat_conf
,
dtype
=
x
.
dtype
)
for
i
in
range
(
times
):
y
=
feature_extractor
(
x
)
@
profile
def
test_melspect_gpu
(
input_shape
,
times
):
paddle
.
set_device
(
'gpu'
)
x
=
paddle
.
randn
(
input_shape
)
feature_extractor
=
paddleaudio
.
features
.
MelSpectrogram
(
**
feat_conf
,
dtype
=
x
.
dtype
)
for
i
in
range
(
times
):
y
=
feature_extractor
(
x
)
input_shape
=
(
16
,
48000
)
# (N, T)
times
=
100
test_melspect_cpu
(
input_shape
,
times
)
test_melspect_gpu
(
input_shape
,
times
)
paddleaudio/tests/benchmark/features/mfcc.py
已删除
100644 → 0
浏览文件 @
7c3a11cc
# Copyright (c) 2022 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
paddle
import
paddleaudio
feat_conf
=
{
'sr'
:
16000
,
'n_mfcc'
:
20
,
'n_fft'
:
512
,
'hop_length'
:
128
,
'n_mels'
:
40
,
'f_min'
:
0.0
,
'top_db'
:
80.0
,
}
@
profile
def
test_mfcc_cpu
(
input_shape
,
times
):
paddle
.
set_device
(
'cpu'
)
x
=
paddle
.
randn
(
input_shape
)
feature_extractor
=
paddleaudio
.
features
.
MFCC
(
**
feat_conf
,
dtype
=
x
.
dtype
)
for
i
in
range
(
times
):
y
=
feature_extractor
(
x
)
@
profile
def
test_mfcc_gpu
(
input_shape
,
times
):
paddle
.
set_device
(
'gpu'
)
x
=
paddle
.
randn
(
input_shape
)
feature_extractor
=
paddleaudio
.
features
.
MFCC
(
**
feat_conf
,
dtype
=
x
.
dtype
)
for
i
in
range
(
times
):
y
=
feature_extractor
(
x
)
input_shape
=
(
16
,
48000
)
# (N, T)
times
=
100
test_mfcc_cpu
(
input_shape
,
times
)
test_mfcc_gpu
(
input_shape
,
times
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录