Files
spleeter/tests/test_eval.py

85 lines
2.1 KiB
Python
Raw Normal View History

2020-06-05 12:27:06 +02:00
#!/usr/bin/env python
# coding: utf8
""" Unit testing for Separator class. """
2020-07-17 13:30:42 +02:00
__email__ = 'spleeter@deezer.com'
2020-06-05 12:27:06 +02:00
__author__ = 'Deezer Research'
__license__ = 'MIT License'
from os import makedirs
2020-12-08 12:31:08 +01:00
from os.path import join
2020-06-05 12:27:06 +02:00
from tempfile import TemporaryDirectory
import pytest
import numpy as np
2020-12-08 12:31:08 +01:00
from spleeter.__main__ import evaluate
from spleeter.audio.adapter import AudioAdapter
2020-06-05 12:27:06 +02:00
2020-12-08 12:31:08 +01:00
BACKENDS = ['tensorflow', 'librosa']
TEST_CONFIGURATIONS = {el: el for el in BACKENDS}
2020-07-24 15:02:34 +02:00
res_4stems = {
2020-12-08 12:31:08 +01:00
'vocals': {
'SDR': 3.25e-05,
'SAR': -11.153575,
'SIR': -1.3849,
'ISR': 2.75e-05
},
'drums': {
'SDR': -0.079505,
'SAR': -15.7073575,
'SIR': -4.972755,
'ISR': 0.0013575
},
'bass': {
'SDR': 2.5e-06,
'SAR': -10.3520575,
'SIR': -4.272325,
'ISR': 2.5e-06
},
'other': {
'SDR': -1.359175,
'SAR': -14.7076775,
'SIR': -4.761505,
'ISR': -0.01528
}
}
2020-06-05 12:27:06 +02:00
def generate_fake_eval_dataset(path):
"""
generate fake evaluation dataset
"""
2020-12-08 12:31:08 +01:00
aa = AudioAdapter.default()
2020-06-05 12:27:06 +02:00
n_songs = 2
fs = 44100
duration = 3
n_channels = 2
2020-06-05 13:42:52 +02:00
rng = np.random.RandomState(seed=0)
2020-06-05 12:27:06 +02:00
for song in range(n_songs):
2020-12-08 12:31:08 +01:00
song_path = join(path, 'test', f'song{song}')
2020-06-05 12:27:06 +02:00
makedirs(song_path, exist_ok=True)
2020-12-08 12:31:08 +01:00
for instr in ['mixture', 'vocals', 'bass', 'drums', 'other']:
filename = join(song_path, f'{instr}.wav')
2020-06-05 12:27:06 +02:00
data = rng.rand(duration*fs, n_channels)-0.5
aa.save(filename, data, fs)
2020-07-24 15:39:43 +02:00
@pytest.mark.parametrize('backend', TEST_CONFIGURATIONS)
def test_evaluate(backend):
with TemporaryDirectory() as directory:
generate_fake_eval_dataset(directory)
2020-12-08 12:31:08 +01:00
metrics = evaluate(
stft_backend=backend,
params_filename='spleeter:4stems',
mus_dir=directory,
)
for instrument, metric in metrics.items():
2020-07-24 15:39:43 +02:00
for m, value in metric.items():
2020-12-08 12:31:08 +01:00
assert np.allclose(
np.median(value),
res_4stems[instrument][m],
atol=1e-3)