Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_36265860
spleeter
提交
9e611e11
S
spleeter
项目概览
qq_36265860
/
spleeter
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spleeter
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9e611e11
编写于
9月 25, 2020
作者:
R
romi1502
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added test for the train command
上级
3df2fa36
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
113 addition
and
0 deletion
+113
-0
tests/test_train.py
tests/test_train.py
+113
-0
未找到文件。
tests/test_train.py
0 → 100644
浏览文件 @
9e611e11
#!/usr/bin/env python
# coding: utf8
""" Unit testing for Separator class. """
__email__
=
'research@deezer.com'
__author__
=
'Deezer Research'
__license__
=
'MIT License'
import
filecmp
import
itertools
import
os
from
os
import
makedirs
from
os.path
import
splitext
,
basename
,
exists
,
join
from
tempfile
import
TemporaryDirectory
import
numpy
as
np
import
pandas
as
pd
import
json
import
tensorflow
as
tf
from
spleeter.audio.adapter
import
get_default_audio_adapter
from
spleeter.commands
import
create_argument_parser
from
spleeter.commands
import
train
from
spleeter.utils.configuration
import
load_configuration
TRAIN_CONFIG
=
{
"mix_name"
:
"mix"
,
"instrument_list"
:
[
"vocals"
,
"other"
],
"sample_rate"
:
44100
,
"frame_length"
:
4096
,
"frame_step"
:
1024
,
"T"
:
128
,
"F"
:
128
,
"n_channels"
:
2
,
"chunk_duration"
:
4
,
"n_chunks_per_song"
:
1
,
"separation_exponent"
:
2
,
"mask_extension"
:
"zeros"
,
"learning_rate"
:
1e-4
,
"batch_size"
:
2
,
"train_max_steps"
:
10
,
"throttle_secs"
:
20
,
"save_checkpoints_steps"
:
100
,
"save_summary_steps"
:
5
,
"random_seed"
:
0
,
"model"
:{
"type"
:
"unet.unet"
,
"params"
:{
"conv_activation"
:
"ELU"
,
"deconv_activation"
:
"ELU"
}
}
}
def
generate_fake_training_dataset
(
path
,
instrument_list
=
[
"vocals"
,
"other"
]):
"""
generates a fake training dataset in path:
- generates audio files
- generates a csv file describing the dataset
"""
aa
=
get_default_audio_adapter
()
n_songs
=
2
fs
=
44100
duration
=
6
n_channels
=
2
rng
=
np
.
random
.
RandomState
(
seed
=
0
)
dataset_df
=
pd
.
DataFrame
(
columns
=
[
"mix_path"
]
+
[
f
"
{
instr
}
_path"
for
instr
in
instrument_list
]
+
[
"duration"
])
for
song
in
range
(
n_songs
):
song_path
=
join
(
path
,
"train"
,
f
"song
{
song
}
"
)
makedirs
(
song_path
,
exist_ok
=
True
)
dataset_df
.
loc
[
song
,
f
"duration"
]
=
duration
for
instr
in
instrument_list
+
[
"mix"
]:
filename
=
join
(
song_path
,
f
"
{
instr
}
.wav"
)
data
=
rng
.
rand
(
duration
*
fs
,
n_channels
)
-
0.5
aa
.
save
(
filename
,
data
,
fs
)
dataset_df
.
loc
[
song
,
f
"
{
instr
}
_path"
]
=
join
(
"train"
,
f
"song
{
song
}
"
,
f
"
{
instr
}
.wav"
)
dataset_df
.
to_csv
(
join
(
path
,
"train"
,
"train.csv"
),
index
=
False
)
def
test_train
():
with
TemporaryDirectory
()
as
path
:
# generate training dataset
generate_fake_training_dataset
(
path
)
# set training command aruments
p
=
create_argument_parser
()
arguments
=
p
.
parse_args
([
"train"
,
"-p"
,
"useless_config.json"
,
"-d"
,
path
])
TRAIN_CONFIG
[
"train_csv"
]
=
join
(
path
,
"train"
,
"train.csv"
)
TRAIN_CONFIG
[
"validation_csv"
]
=
join
(
path
,
"train"
,
"train.csv"
)
TRAIN_CONFIG
[
"model_dir"
]
=
join
(
path
,
"model"
)
TRAIN_CONFIG
[
"training_cache"
]
=
join
(
path
,
"cache"
,
"training"
)
TRAIN_CONFIG
[
"validation_cache"
]
=
join
(
path
,
"cache"
,
"validation"
)
# execute training
res
=
train
.
entrypoint
(
arguments
,
TRAIN_CONFIG
)
# assert that model checkpoint was created.
assert
os
.
path
.
exists
(
join
(
path
,
'model'
,
'model.ckpt-10.index'
))
assert
os
.
path
.
exists
(
join
(
path
,
'model'
,
'checkpoint'
))
assert
os
.
path
.
exists
(
join
(
path
,
'model'
,
'model.ckpt-0.meta'
))
if
__name__
==
"__main__"
:
test_train
()
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录