From 2fec71f98a7130df2ece7ecbad3e7eee4ed95513 Mon Sep 17 00:00:00 2001 From: jcaw Date: Mon, 1 Mar 2021 23:12:20 +0000 Subject: [PATCH 1/4] Parameterize `test_sliding_window_cmn` Don't test every combination of `center` and `norm_vars` at the same time - generate separate tests. --- .../functional/batch_consistency_test.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/test/torchaudio_unittest/functional/batch_consistency_test.py b/test/torchaudio_unittest/functional/batch_consistency_test.py index f1c1ef371a..de4d034fce 100644 --- a/test/torchaudio_unittest/functional/batch_consistency_test.py +++ b/test/torchaudio_unittest/functional/batch_consistency_test.py @@ -180,16 +180,14 @@ def test_flanger(self): sample_rate = 44100 self.assert_batch_consistency(F.flanger, waveforms, sample_rate) - def test_sliding_window_cmn(self): + @parameterized.expand(list(itertools.product( + [True, False], # center + [True, False], # norm_vars + )), name_func=lambda f, _, p: f'{f.__name__}_{"_".join(str(arg) for arg in p.args)}') + def test_sliding_window_cmn(self, center, norm_vars): waveforms = torch.randn(self.batch_size, 2, 1024) - 0.5 self.assert_batch_consistency( - F.sliding_window_cmn, waveforms, center=True, norm_vars=True) - self.assert_batch_consistency( - F.sliding_window_cmn, waveforms, center=True, norm_vars=False) - self.assert_batch_consistency( - F.sliding_window_cmn, waveforms, center=False, norm_vars=True) - self.assert_batch_consistency( - F.sliding_window_cmn, waveforms, center=False, norm_vars=False) + F.sliding_window_cmn, waveforms, center=center, norm_vars=norm_vars) def test_vad_from_file(self): filepath = common_utils.get_asset_path("vad-go-stereo-44100.wav") From a0c3cced949d674807bb2f66c36aa48c327754d8 Mon Sep 17 00:00:00 2001 From: jcaw Date: Mon, 1 Mar 2021 23:21:26 +0000 Subject: [PATCH 2/4] Extract test naming function --- .../functional/batch_consistency_test.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/torchaudio_unittest/functional/batch_consistency_test.py b/test/torchaudio_unittest/functional/batch_consistency_test.py index de4d034fce..ff37b1cec6 100644 --- a/test/torchaudio_unittest/functional/batch_consistency_test.py +++ b/test/torchaudio_unittest/functional/batch_consistency_test.py @@ -9,6 +9,13 @@ from torchaudio_unittest import common_utils +def _name_from_args(func, _, params): + """Return a parameterized test name, based on parameter values.""" + return "{}_{}".format( + func.__name__, + "_".join(str(arg) for arg in params.args)) + + @parameterized_class([ # Single-item batch isolates problems that come purely from adding a # dimension (rather than processing multiple items) @@ -58,7 +65,7 @@ def test_griffinlim(self): @parameterized.expand(list(itertools.product( [8000, 16000, 44100], [1, 2], - )), name_func=lambda f, _, p: f'{f.__name__}_{"_".join(str(arg) for arg in p.args)}') + )), name_func=_name_from_args) def test_detect_pitch_frequency(self, sample_rate, n_channels): # Use different frequencies to ensure each item in the batch returns a # different answer. @@ -183,7 +190,7 @@ def test_flanger(self): @parameterized.expand(list(itertools.product( [True, False], # center [True, False], # norm_vars - )), name_func=lambda f, _, p: f'{f.__name__}_{"_".join(str(arg) for arg in p.args)}') + )), name_func=_name_from_args) def test_sliding_window_cmn(self, center, norm_vars): waveforms = torch.randn(self.batch_size, 2, 1024) - 0.5 self.assert_batch_consistency( From 4e8b1a802039f569607c15b449ac97452a94618a Mon Sep 17 00:00:00 2001 From: jcaw Date: Mon, 1 Mar 2021 23:23:28 +0000 Subject: [PATCH 3/4] Pass a spectrogram to `F.sliding_window_cmn` --- .../torchaudio_unittest/functional/batch_consistency_test.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/torchaudio_unittest/functional/batch_consistency_test.py b/test/torchaudio_unittest/functional/batch_consistency_test.py index ff37b1cec6..c711baee3c 100644 --- a/test/torchaudio_unittest/functional/batch_consistency_test.py +++ b/test/torchaudio_unittest/functional/batch_consistency_test.py @@ -192,9 +192,10 @@ def test_flanger(self): [True, False], # norm_vars )), name_func=_name_from_args) def test_sliding_window_cmn(self, center, norm_vars): - waveforms = torch.randn(self.batch_size, 2, 1024) - 0.5 + spectrogram = torch.rand(self.batch_size, 2, 1024, 1024) * 200 self.assert_batch_consistency( - F.sliding_window_cmn, waveforms, center=center, norm_vars=norm_vars) + F.sliding_window_cmn, spectrogram, center=center, + norm_vars=norm_vars) def test_vad_from_file(self): filepath = common_utils.get_asset_path("vad-go-stereo-44100.wav") From 575f4826dcd13ba890a53a2265b7f41823180132 Mon Sep 17 00:00:00 2001 From: jcaw Date: Tue, 2 Mar 2021 00:17:19 +0000 Subject: [PATCH 4/4] Set manual seed for remaining rand calls in suite --- test/torchaudio_unittest/functional/batch_consistency_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/torchaudio_unittest/functional/batch_consistency_test.py b/test/torchaudio_unittest/functional/batch_consistency_test.py index c711baee3c..40703b9955 100644 --- a/test/torchaudio_unittest/functional/batch_consistency_test.py +++ b/test/torchaudio_unittest/functional/batch_consistency_test.py @@ -192,6 +192,7 @@ def test_flanger(self): [True, False], # norm_vars )), name_func=_name_from_args) def test_sliding_window_cmn(self, center, norm_vars): + torch.manual_seed(0) spectrogram = torch.rand(self.batch_size, 2, 1024, 1024) * 200 self.assert_batch_consistency( F.sliding_window_cmn, spectrogram, center=center, @@ -208,6 +209,7 @@ def test_vad_from_file(self): def test_vad_different_items(self): """Separate test to ensure VAD consistency with differing items.""" sample_rate = 44100 + torch.manual_seed(0) waveforms = torch.rand(self.batch_size, 2, 100) - 0.5 self.assert_batch_consistency( F.vad, waveforms, sample_rate=sample_rate)