Added additional unit tests for Duet benchmarking.
MODIFY
demos/demo_duet.py
demos/demo_duet.py
@@ -17,7 +17,6 @@ def main():
# and run
duet.run()
- print duet.stft_ch0
# plot histogram results
duet.plot(os.path.join('..', 'Output', 'duet_2d.png'))
duet.plot(os.path.join('..', 'Output', 'duet_3d.png'), three_d_plot=True)

DELETE
tests/duet_reference/duet_benchmarks/benchmark_delay.npy.REMOVED.git-id
-b8961c51100c8e3ccdba191febfd3c5a0c29b7c9
\ No newline at end of file

MODIFY
tests/duet_reference/duet_benchmarks/benchmark_stft_ch0.npy.REMOVED.git-id
tests/duet_reference/duet_benchmarks/benchmark_stft_ch0.npy.REMOVED.git-id
-2bf76ec3b3b56bae442bad5e3a01a8c6a71aea1f
\ No newline at end of file
+6d0d15e720bf359d444fd0a3e4b2a10c312ab7cd
\ No newline at end of file

MODIFY
tests/duet_reference/duet_benchmarks/benchmark_stft_ch1.npy.REMOVED.git-id
tests/duet_reference/duet_benchmarks/benchmark_stft_ch1.npy.REMOVED.git-id
-42996955d5e42a9b7d858c532ff6299c596dd565
\ No newline at end of file
+224318577eceffd14466c12dfe4121ceca3ca218
\ No newline at end of file

DELETE
tests/duet_reference/duet_benchmarks/benchmark_symmetric_atn.npy.REMOVED.git-id
-bdb5a75d2ffc4ad3e95b98bd776560560177d805
\ No newline at end of file

MODIFY
tests/test_duet.py
tests/test_duet.py
@@ -10,37 +10,24 @@ import scipy.io
import os
import warnings
-# import sys
-# sys.path.insert(1, 'C:\\Users\\danielfelixkim\\Documents\\GitHub\\InteractiveAudioLab\\nussl\\nussl')
class DuetUnitTests(unittest.TestCase):
-
- # def test_setup(self):
- # input_file_name = os.path.join('..', 'Input', 'dev1_female3_inst_mix.wav')
- # signal = nussl.AudioSignal(path_to_input_file=input_file_name)
-
- # duet = nussl.Duet(signal, 3)
- # duet.run()
-
- # def test_duet_outputs(self):
- # input_file_name = os.path.join('..', 'input', 'dev1_female3_inst_mix.wav')
- # signal = nussl.AudioSignal(path_to_input_file=input_file_name)
- # refact_duet = nussl.Duet(signal, num_sources=3)
- # refact_duet_result = refact_duet.run()
- # duet = nussl.Duet(signal, 3)
- # nussel_duet_result = duet.run()
- # assert refact_duet_result == nussel_duet_result
- #
- # @staticmethod
- # def _load_matlab_results():
- #
- # f_mat_path = os.path.join('duet_reference', 'rickard_duet', 'fmat')
- # tf1_path = os.path.join('duet_reference', 'rickard_duet', 'tf1')
- # tf2_path = os.path.join('duet_reference', 'rickard_duet', 'tf2')
+ def setUp(self):
+ # Use the same audio file that the benchmarks were run with
+ path = os.path.join('..', 'Input', 'dev1_female3_inst_mix.wav')
+ signal = nussl.AudioSignal(path)
+ self.duet = nussl.Duet(signal, 3)
+
+ # def test_duet_final_outputs(self):
+ # #Test final outputs
+ # source_estimates_path = os.path.join('duet_reference', 'duet_benchmarks', 'benchmark_source_estimates.npy')
+ # atn_delay_est_path = os.path.join('duet_reference', 'duet_benchmarks', 'benchmark_atn_delay_est.npy')
+ # benchmark_source_estimates = np.load(source_estimates_path)
+ # benchmark_atn_delay_est = np.load(atn_delay_est_path)
#
- # fmat = scipy.io.loadmat(f_mat_path)['back'].T
- # delay_mat = scipy.io.loadmat(delay_mat_path)['fore'].T
- # return sym_atn_mat, delay_mat
+ # duet_source_estimates, duet_atn_delay_est = self.duet.run()
+ # assert benchmark_source_estimates == duet_source_estimates
+ # assert benchmark_atn_delay_est == duet_atn_delay_est
def test_compute_spectrogram_1_channel(self):
# Test with one channel, should throw value error
@@ -52,34 +39,56 @@ class DuetUnitTests(unittest.TestCase):
duet._compute_spectrogram(duet.sample_rate)
def test_compute_spectrogram_wmat(self):
- # Load MATLAB values
- # f_mat_path = os.path.join('duet_reference', 'rickard_duet', 'fmat')
+ # Load Duet values to benchmark against
stft0_path = os.path.join('duet_reference', 'duet_benchmarks', 'benchmark_stft_ch0.npy')
stft1_path = os.path.join('duet_reference', 'duet_benchmarks', 'benchmark_stft_ch1.npy')
+ wmat_path = os.path.join('duet_reference', 'duet_benchmarks', 'benchmark_wmat.npy')
- # fmat = scipy.io.loadmat(f_mat_path)['fmat']
- benchmark_stft0 = np.load(stft0_path)
- benchmark_stft1 = np.load(stft1_path)
+ benchmark_stft_ch0 = np.load(stft0_path)
+ benchmark_stft_ch1 = np.load(stft1_path)
+ benchmark_wmat = np.load(wmat_path)
- path = os.path.join('..', 'Input', 'dev1_female3_inst_mix.wav')
- signal = nussl.AudioSignal(path)
- duet = nussl.Duet(signal, 3)
- # duet.stft_params.window_length = 1024
- # duet.stft_params.window_type = nussl.WINDOW_RECTANGULAR
- # duet.stft_params.hop_length = duet.stft_params.window_length
-
- duet_sft0, duet_sft1, duet_wmat = duet._compute_spectrogram(duet.sample_rate)
- assert np.all(benchmark_stft0 == duet_sft0)
- assert np.all(benchmark_stft0 == duet_sft1)
- # assert np.allclose(duet_wmat, fmat)
-
- # def test_compute_atn_delay(self):
- # sym_atn_mat_path = os.path.join('duet_reference', 'rickard_duet', 'alpha_duet')
- # delay_mat_path = os.path.join('duet_reference', 'rickard_duet', 'delta_duet')
- # sym_atn_mat = scipy.io.loadmat(sym_atn_mat_path)['sym'].T
- # delay_mat = scipy.io.loadmat(delay_mat_path)['delay'].T
-
- # def test_make_histogram(self):
+ duet_sft0, duet_sft1, duet_wmat = self.duet._compute_spectrogram(self.duet.sample_rate)
+ assert np.all(benchmark_stft_ch0 == duet_sft0)
+ assert np.all(benchmark_stft_ch1 == duet_sft1)
+ assert np.all(benchmark_wmat == duet_wmat)
+
+ def test_compute_atn_delay(self):
+ sym_atn_path = os.path.join('duet_reference', 'duet_benchmarks', 'benchmark_stft_ch0.npy')
+ delay_path = os.path.join('duet_reference', 'duet_benchmarks', 'benchmark_stft_ch0.npy')
+ benchmark_sym_atn = np.load(sym_atn_path)
+ benchmark_delay = np.load(delay_path)
+
+ symmetric_atn, delay = self.duet._compute_atn_delay()
+
+ assert np.all(benchmark_sym_atn == symmetric_atn)
+ assert np.all(benchmark_delay == delay)
+
+ def test_make_histogram(self):
+ #Load benchmarks
+ hist_path = os.path.join('duet_reference', 'duet_benchmarks', 'benchmark_hist.npy')
+ atn_bins_path = os.path.join('duet_reference', 'duet_benchmarks', 'atn_bins.npy')
+ delay_bins_path = os.path.join('duet_reference', 'duet_benchmarks', 'delay_bins.npy')
+ benchmark_hist = np.load(hist_path)
+ benchmark_atn_bins = np.load(atn_bins_path)
+ benchmark_delay_bins = np.load(delay_bins_path)
+
+ hist, atn_bins, delay_bins = self.duet.make_histogram(self.duet.p, self.duet.q)
+
+ assert np.all(benchmark_hist == hist)
+ assert np.all(benchmark_atn_bins == atn_bins)
+ assert np.all(benchmark_delay_bins == delay_bins)
+
+ def test_peak_indices(self):
+ hist_path = os.path.join('duet_reference', 'duet_benchmarks', 'benchmark_hist.npy')
+ peak_indices_path = os.path.join('duet_reference', 'duet_benchmarks', 'benchmark_peak_indices.npy')
+ benchmark_hist = np.load(hist_path)
+ benchmark_peak_indices = np.load(peak_indices_path)
+
+ duet_peak_indices = nussl.utils.find_peak_indices(benchmark_hist, self.duet.num_sources, threshold=self.duet.peak_threshold,
+ min_dist=[self.duet.attenuation_min_distance, self.duet.delay_min_distance])
+
+ assert np.all(benchmark_peak_indices == duet_peak_indices)
# def test_convert_peaks

Added additional unit tests for Duet benchmarking.