Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
14214566
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
14214566
编写于
7月 26, 2021
作者:
R
ranchlai
提交者:
GitHub
7月 26, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update example to use new functionals (#5330)
上级
4f1462d7
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
62 addition
and
52 deletion
+62
-52
PaddleAudio/examples/audioset_training/dataset.py
PaddleAudio/examples/audioset_training/dataset.py
+7
-5
PaddleAudio/examples/audioset_training/evaluate.py
PaddleAudio/examples/audioset_training/evaluate.py
+2
-1
PaddleAudio/examples/audioset_training/inference.py
PaddleAudio/examples/audioset_training/inference.py
+17
-16
PaddleAudio/examples/audioset_training/train.py
PaddleAudio/examples/audioset_training/train.py
+2
-2
PaddleAudio/examples/audioset_training/wav2mel.py
PaddleAudio/examples/audioset_training/wav2mel.py
+34
-28
未找到文件。
PaddleAudio/examples/audioset_training/dataset.py
浏览文件 @
14214566
...
...
@@ -26,7 +26,7 @@ import paddle
import
paddleaudio
import
yaml
from
paddle.io
import
DataLoader
,
Dataset
,
IterableDataset
from
paddleaudio
import
augment
from
paddleaudio
.utils
import
augments
from
utils
import
get_labels
,
get_ytid_clsidx_mapping
...
...
@@ -108,12 +108,14 @@ class H5AudioSet(Dataset):
x
=
x
[:,
:
target_len
]
if
self
.
training
and
self
.
augment
:
x
=
augment
.
random_crop2d
(
x
,
self
.
config
[
'mel_crop_len'
],
tempo_axis
=
1
)
x
=
augment
s
.
random_crop2d
(
x
,
self
.
config
[
'mel_crop_len'
],
tempo_axis
=
1
)
x
=
spect_permute
(
x
,
tempo_axis
=
1
,
nblocks
=
random_choice
([
0
,
2
,
3
]))
aug_level
=
random_choice
([
0.2
,
0.1
,
0
])
x
=
augment
.
adaptive_spect_augment
(
x
,
tempo_axis
=
1
,
level
=
aug_level
)
x
=
augments
.
adaptive_spect_augment
(
x
,
tempo_axis
=
1
,
level
=
aug_level
)
return
x
.
T
def
__getitem__
(
self
,
idx
):
...
...
PaddleAudio/examples/audioset_training/evaluate.py
浏览文件 @
14214566
...
...
@@ -24,10 +24,11 @@ from dataset import get_val_loader
from
model
import
resnet50
from
paddle.utils
import
download
from
sklearn.metrics
import
average_precision_score
,
roc_auc_score
from
utils
import
compute_dprime
,
download_assets
from
utils
import
compute_dprime
,
download_assets
checkpoint_url
=
'https://bj.bcebos.com/paddleaudio/paddleaudio/resnet50_weight_averaging_mAP0.416.pdparams'
def
evaluate
(
epoch
,
val_loader
,
model
,
loss_fn
):
model
.
eval
()
avg_loss
=
0.0
...
...
PaddleAudio/examples/audioset_training/inference.py
浏览文件 @
14214566
...
...
@@ -22,6 +22,7 @@ import paddleaudio as pa
import
yaml
from
model
import
resnet50
from
paddle.utils
import
download
from
paddleaudio.functional
import
melspectrogram
from
utils
import
(
download_assets
,
get_label_name_mapping
,
get_labels
,
get_metrics
)
...
...
@@ -32,22 +33,22 @@ checkpoint_url = 'https://bj.bcebos.com/paddleaudio/paddleaudio/resnet50_weight_
def
load_and_extract_feature
(
file
,
c
):
s
,
_
=
pa
.
load
(
file
,
sr
=
c
[
'sample_rate'
])
x
=
pa
.
features
.
melspectrogram
(
s
,
sr
=
c
[
'sample_rate'
],
window_size
=
c
[
'window_size'
],
hop_length
=
c
[
'hop
_size'
],
n_mels
=
c
[
'mel_bins
'
],
fmin
=
c
[
'fmin
'
],
fmax
=
c
[
'fmax
'
],
window
=
'hann'
,
center
=
True
,
pad_mode
=
'reflect'
,
ref
=
1.0
,
amin
=
1e-10
,
top_db
=
None
)
x
=
x
.
T
# !!
x
=
paddle
.
Tensor
(
x
).
unsqueeze
((
0
,
1
))
x
=
melspectrogram
(
paddle
.
to_tensor
(
s
)
,
sr
=
c
[
'sample_rate'
],
win_length
=
c
[
'window_size'
],
n_fft
=
c
[
'window
_size'
],
hop_length
=
c
[
'hop_size
'
],
n_mels
=
c
[
'mel_bins
'
],
f_min
=
c
[
'fmin
'
],
f_max
=
c
[
'fmax'
]
,
window
=
'hann'
,
center
=
True
,
pad_mode
=
'reflect'
,
to_db
=
True
,
amin
=
1e-3
,
top_db
=
None
)
x
=
x
.
transpose
((
0
,
2
,
1
))
x
=
x
.
unsqueeze
((
0
,
))
return
x
...
...
PaddleAudio/examples/audioset_training/train.py
浏览文件 @
14214566
...
...
@@ -129,7 +129,7 @@ if __name__ == '__main__':
model
.
train
()
model
.
clear_gradients
()
t0
=
time
.
time
()
for
batch_id
,
(
x
,
y
)
in
enumerate
(
train_loader
()):
for
batch_id
,
(
x
,
y
)
in
enumerate
(
train_loader
()):
if
step
<
warm_steps
:
optimizer
.
set_lr
(
lrs
[
step
])
x
.
stop_gradient
=
False
...
...
@@ -215,4 +215,4 @@ if __name__ == '__main__':
else
:
factor
=
0.8
optimizer
.
set_lr
(
optimizer
.
get_lr
()
*
factor
)
print
(
'decreased lr to {}'
.
format
(
optimizer
.
get_lr
()))
\ No newline at end of file
print
(
'decreased lr to {}'
.
format
(
optimizer
.
get_lr
()))
PaddleAudio/examples/audioset_training/wav2mel.py
浏览文件 @
14214566
...
...
@@ -4,8 +4,10 @@ import os
import
h5py
import
numpy
as
np
import
paddle
import
paddleaudio
as
pa
import
tqdm
from
paddleaudio.functional
import
melspectrogram
parser
=
argparse
.
ArgumentParser
(
description
=
'wave2mel'
)
parser
.
add_argument
(
'--wav_file'
,
type
=
str
,
required
=
False
,
default
=
''
)
...
...
@@ -64,20 +66,23 @@ if len(h5_files) > 0:
s
=
src_h5
[
key
][:]
s
=
pa
.
depth_convert
(
s
,
'float32'
)
# s = pa.resample(s,32000,args.sample_rate)
x
=
pa
.
features
.
melspectrogram
(
s
,
sr
=
args
.
sample_rate
,
window_size
=
args
.
window_size
,
hop_length
=
args
.
hop_length
,
n_mels
=
args
.
mel_bins
,
fmin
=
args
.
fmin
,
fmax
=
args
.
fmax
,
window
=
'hann'
,
center
=
True
,
pad_mode
=
'reflect'
,
ref
=
1.0
,
amin
=
1e-10
,
top_db
=
None
)
dst_h5
.
create_dataset
(
key
,
data
=
x
)
x
=
melspectrogram
(
paddle
.
to_tensor
(
s
),
sr
=
args
.
sample_rate
,
win_length
=
args
.
window_size
,
n_fft
=
args
.
window_size
,
hop_length
=
args
.
hop_length
,
n_mels
=
args
.
mel_bins
,
f_min
=
args
.
fmin
,
f_max
=
args
.
fmax
,
window
=
'hann'
,
center
=
True
,
pad_mode
=
'reflect'
,
to_db
=
True
,
amin
=
1e-3
,
top_db
=
None
)
dst_h5
.
create_dataset
(
key
,
data
=
x
[
0
].
numpy
())
src_h5
.
close
()
dst_h5
.
close
()
...
...
@@ -91,23 +96,24 @@ if len(wav_files) > 0:
print
(
f
'
{
len
(
wav_files
)
}
wav files listed'
)
for
f
in
tqdm
.
tqdm
(
wav_files
):
s
,
_
=
pa
.
load
(
f
,
sr
=
args
.
sample_rate
)
x
=
pa
.
melspectrogram
(
s
,
sr
=
args
.
sample_rate
,
window_size
=
args
.
window_size
,
hop_length
=
args
.
hop_length
,
n_mels
=
args
.
mel_bins
,
fmin
=
args
.
fmin
,
fmax
=
args
.
fmax
,
window
=
'hann'
,
center
=
True
,
pad_mode
=
'reflect'
,
ref
=
1.0
,
amin
=
1e-10
,
top_db
=
None
)
x
=
melspectrogram
(
paddle
.
to_tensor
(
s
),
sr
=
args
.
sample_rate
,
win_length
=
args
.
window_size
,
n_fft
=
args
.
window_size
,
hop_length
=
args
.
hop_length
,
n_mels
=
args
.
mel_bins
,
f_min
=
args
.
fmin
,
f_max
=
args
.
fmax
,
window
=
'hann'
,
center
=
True
,
pad_mode
=
'reflect'
,
to_db
=
True
,
amin
=
1e-3
,
top_db
=
None
)
# figure(figsize=(8,8))
# imshow(x)
# show()
# print(x.shape)
key
=
f
.
split
(
'/'
)[
-
1
][:
11
]
dst_h5
.
create_dataset
(
key
,
data
=
x
)
dst_h5
.
create_dataset
(
key
,
data
=
x
[
0
].
numpy
()
)
dst_h5
.
close
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录