def test_metric(references, estimates, is_framewise, is_sources, nb_win, nb_hop): metrics.bss_eval(references, estimates, framewise_filters=is_framewise, bsseval_sources_version=is_sources, window=nb_win, hop=nb_hop)
def test_silent_input(references, estimates, is_framewise, is_sources, nb_win, nb_hop): estimates = np.zeros(references.shape) with pytest.raises(ValueError): metrics.bss_eval(references, estimates, framewise_filters=is_framewise, bsseval_sources_version=is_sources, window=nb_win, hop=nb_hop)
def eval_estimated(reference, ref_labels, estimated, est_labels, sampling_rate, win, hop, mode, compute_permutation=True): if len(reference) != len(estimated): raise Exception("You need the same amount of references as estimates!") reference_np, estimated_np = pad_or_truncate(reference, estimated) SDR, ISR, SIR, SAR, _ = bss_eval( reference_np, estimated_np, compute_permutation=compute_permutation, window=int(win*sampling_rate), hop=int(hop*sampling_rate), framewise_filters=(mode == "v3"), bsseval_sources_version=False ) source_results = [] for i, (ref_label, est_labels) in enumerate(zip(ref_labels, est_labels)): source_results.append({ "reference_name": ref_label, "estimated_name": est_labels, "SDR": SDR[i].tolist(), "SIR": SIR[i].tolist(), "ISR": ISR[i].tolist(), "SAR": SAR[i].tolist() }) return source_results
def test_window(self, audios, rate): from museval.metrics import bss_eval if len(audios) != 2: raise ValueError('BSSEval needs a reference and a test signals.') result = bss_eval(reference_sources=audios[0].T, estimated_sources=audios[1].T, window=self.bss_window * rate, hop=self.bss_hop * rate) return {'sdr': result[0], 'isr': result[1], 'sar': result[3]}
def test_empty_input(is_framewise, is_sources, nb_win, nb_hop): inputs = [np.array([]), np.array([])] with pytest.warns(UserWarning): output = metrics.bss_eval(*inputs, framewise_filters=is_framewise, bsseval_sources_version=is_sources, window=nb_win, hop=nb_hop) assert np.allclose(output, np.array([]))
import numpy as np from museval.metrics import bss_eval from spleeter.audio.adapter import get_default_audio_adapter parser = argparse.ArgumentParser() parser.add_argument('original') parser.add_argument('estimate') args = parser.parse_args() print("load audio") audio_loader = get_default_audio_adapter() sample_rate = 44100 tracks = [] estimates = [] for i in ['bass', 'drums', 'other', 'vocals']: filename = os.path.join(args.original, i+'.wav') track, _ = audio_loader.load(filename, sample_rate=sample_rate) a = np.sum(track, axis=1) print(np.all(a == 0)) tracks.append(track + 1e-7) filename2 = os.path.join(args.estimate, i+'.wav') estimate, _ = audio_loader.load(filename2, sample_rate=sample_rate) estimates.append(estimate + 1e-7) tracks = np.array(tracks) estimates = np.array(estimates) print(tracks.shape) print(estimates.shape) ans = bss_eval(tracks, estimates) SDR = ans[0] print(np.average(SDR, axis=1))