Fixed tests and variable naming bugs.
MODIFY
nussl/separation/nmf_mfcc.py
nussl/separation/nmf_mfcc.py
@@ -173,9 +173,10 @@ class NMF_MFCC(mask_separation_base.MaskSeparationBase):
"""
self.result_masks = []
self.audio_signal.stft_params = self.stft_params
+ self.audio_signal.stft()
- for i in range(self.audio_signal.num_channels):
- channel_stft = self.audio_signal.get_magnitude_spectrogram_channel(i)
+ for ch in range(self.audio_signal.num_channels):
+ channel_stft = self.audio_signal.get_magnitude_spectrogram_channel(ch)
# Set up NMF and run
nmf = transformer_nmf.TransformerNMF(input_matrix=channel_stft, num_components=self.num_templates,
@@ -192,12 +193,12 @@ class NMF_MFCC(mask_separation_base.MaskSeparationBase):
self.labeled_templates = self.clusterer.labels_
# Extract sources from signal
- channel_masks = self._extract_masks(channel_stft, channel_templates_matrix, channel_activation_matrix)
+ channel_masks = self._extract_masks(channel_templates_matrix, channel_activation_matrix, ch)
self.result_masks.append(channel_masks)
return self.result_masks
- def _extract_masks(self, templates_matrix, activation_matrix):
+ def _extract_masks(self, templates_matrix, activation_matrix, ch):
""" Creates binary masks from clustered templates and activation matrices
Parameters:
@@ -226,7 +227,7 @@ class NMF_MFCC(mask_separation_base.MaskSeparationBase):
activation_mask[i, :] = 0 if i in source_indices else activation_matrix[i, :]
mask_matrix = templates_mask.dot(activation_mask)
- music_stft_max = np.maximum(mask_matrix, np.abs(signal_stft))
+ music_stft_max = np.maximum(mask_matrix, np.abs(self.audio_signal.get_stft_channel(ch)))
mask_matrix = np.divide(mask_matrix, music_stft_max)
mask = np.nan_to_num(mask_matrix)

ADD
tests/__init__.py
tests/__init__.py
ADD
tests/duet_reference/__init__.py
tests/duet_reference/__init__.py
RENAME
tests/freeze_duet_values.py
tests/duet_reference/freeze_duet_values.py
@@ -14,7 +14,7 @@ import warnings
# Freezes essential values from DUET in its current implementation for benchmarking
# See test_benchmark_duet() in test_duet.py for usage
def freeze_duet_values():
- signal = nussl.AudioSignal(os.path.join('..', 'Input', 'dev1_female3_inst_mix.wav'))
+ signal = nussl.AudioSignal(os.path.join('..', 'input', 'dev1_female3_inst_mix.wav'))
duet = nussl.Duet(signal, 3)
output_folder = os.path.abspath('duet_reference/duet_benchmarks')

ADD
tests/nmf_mfcc_reference/__init__.py
tests/nmf_mfcc_reference/__init__.py
RENAME
tests/freeze_nmf_mfcc.py
tests/nmf_mfcc_reference/freeze_nmf_mfcc.py
@@ -9,19 +9,21 @@ import os
# Freezes essential values from NMF MFCC in its current implementation for benchmarking
# See test_benchmark_nmf_mfcc() in test_nmf_mfcc.py for usage
def main():
- path_to_benchmark_file = os.path.join('..', 'Input', 'piano_and_synth_arp_chord_mono.wav')
+ path_to_benchmark_file = os.path.join('..', '..', 'input', 'piano_and_synth_arp_chord_mono.wav')
signal = nussl.AudioSignal(path_to_benchmark_file)
# Set random seed in NMF and KMeans to 0
nmf_mfcc = nussl.NMF_MFCC(signal, num_sources=2, num_templates=6, distance_measure="euclidean",
- num_iterations=100, random_seed=0)
- output_folder = os.path.abspath('nmf_mfcc_reference/new')
+ num_iterations=10, random_seed=0)
+ output_folder = os.path.abspath('new')
nmf_mfcc.run()
np.save(os.path.join(output_folder, "benchmark_labeled_templates"), nmf_mfcc.labeled_templates)
- np.save(os.path.join(output_folder, "benchmark_masks"), nmf_mfcc.masks)
+ np.save(os.path.join(output_folder, "benchmark_masks"), nmf_mfcc.result_masks)
nmf_mfcc.make_audio_signals()
+ for source in nmf_mfcc.sources:
+ source.path_to_input_file = ''
np.save(os.path.join(output_folder, "benchmark_sources"), nmf_mfcc.sources)
if __name__ == '__main__':

ADD
tests/nmf_mfcc_reference/new/benchmark_masks.npy.REMOVED.git-id
+9e4a4d58a4b8299c26c7525cc53cb0cdcbb26525
\ No newline at end of file

ADD
tests/nmf_mfcc_reference/new/benchmark_sources.npy.REMOVED.git-id
+dc8a536e7eb325f0fec4a7495b63b02c498debb5
\ No newline at end of file

MODIFY
tests/test_nmf_mfcc.py
tests/test_nmf_mfcc.py
@@ -9,7 +9,7 @@ import os
class NMFMFCCUnitTests(unittest.TestCase):
# Update this if the benchmark file changes and rerun freeze_duet_values() (below)
- path_to_benchmark_file = os.path.join('..', 'Input', 'piano_and_synth_arp_chord_mono.wav')
+ path_to_benchmark_file = os.path.join('..', 'input', 'piano_and_synth_arp_chord_mono.wav')
def load_benchmarks(self):
benchmark_dict = {}
@@ -85,20 +85,19 @@ class NMFMFCCUnitTests(unittest.TestCase):
nmf_mfcc.run()
sources = nmf_mfcc.make_audio_signals()
- for i, source in enumerate(sources):
- output_file_name = str(i) + '.wav'
- source.write_audio_to_file(output_file_name)
-
def test_piano_and_synth(self):
# Load input file
input_file_name = os.path.join('..', 'input', 'piano_and_synth_arp_chord_mono.wav')
signal = nussl.AudioSignal(path_to_input_file=input_file_name)
# Set up NMMF MFCC
- nmf_mfcc = nussl.NMF_MFCC(signal, num_sources=2, num_templates=6, num_iterations=50, random_seed=0)
+ nmf_mfcc = nussl.NMF_MFCC(signal, num_sources=2, num_templates=6, num_iterations=10, random_seed=0)
# and run
nmf_mfcc.run()
sources = nmf_mfcc.make_audio_signals()
+ for i, source in enumerate(sources):
+ output_file_name = str(i) + '.wav'
+ source.write_audio_to_file(output_file_name)
def test_piano_and_synth_stereo(self):
# Load input file
@@ -130,19 +129,19 @@ class NMFMFCCUnitTests(unittest.TestCase):
# Set up NMMF MFCC
nmf_mfcc = nussl.NMF_MFCC(signal, num_sources=2, num_templates=6, distance_measure="euclidean",
- num_iterations=100, random_seed=0)
+ num_iterations=10, random_seed=0)
# and run
nmf_mfcc.run()
- benchmark_labeled_templates = np.load(os.path.join('nmf_mfcc_reference', 'nmf_mfcc_benchmarks',
+ benchmark_labeled_templates = np.load(os.path.join('nmf_mfcc_reference', 'new',
'benchmark_labeled_templates.npy'))
- benchmark_masks = np.load(os.path.join('nmf_mfcc_reference', 'nmf_mfcc_benchmarks', 'benchmark_masks.npy'))
+ benchmark_masks = np.load(os.path.join('nmf_mfcc_reference', 'new', 'benchmark_masks.npy'))
nmf_mfcc.make_audio_signals()
- benchmark_sources = np.load(os.path.join('nmf_mfcc_reference', 'nmf_mfcc_benchmarks', 'benchmark_sources.npy'))
+ for source in nmf_mfcc.sources:
+ source.path_to_input_file = ''
+ benchmark_sources = np.load(os.path.join('nmf_mfcc_reference', 'new', 'benchmark_sources.npy'))
+ assert np.all(benchmark_sources == nmf_mfcc.sources)
assert np.all(benchmark_labeled_templates == nmf_mfcc.labeled_templates)
- assert np.all(benchmark_masks == nmf_mfcc.masks)
- for i in range(nmf_mfcc.num_sources):
- assert np.all(benchmark_sources[i].audio_data == nmf_mfcc.sources[i].audio_data)
- assert all(benchmark_sources[i] == nmf_mfcc.sources[i] for i in range(len(nmf_mfcc.sources)))
+ assert np.all(benchmark_masks == nmf_mfcc.result_masks)

Fixed tests and variable naming bugs.