Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue warning when a Mel filter is all zero #914

Merged
merged 3 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions test/torchaudio_unittest/functional/functional_cpu_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ class TestLFilterFloat64(Lfilter, common_utils.PytorchTestCase):
device = torch.device('cpu')


class TestCreateFBMatrix(common_utils.TorchaudioTestCase):
def test_no_warning_high_n_freq(self):
with pytest.warns(None) as w:
F.create_fb_matrix(288, 0, 8000, 128, 16000)
assert len(w) == 0

def test_no_warning_low_n_mels(self):
with pytest.warns(None) as w:
F.create_fb_matrix(201, 0, 8000, 89, 16000)
assert len(w) == 0

def test_warning(self):
with pytest.warns(None) as w:
F.create_fb_matrix(201, 0, 8000, 128, 16000)
assert len(w) == 1


class TestComputeDeltas(common_utils.TorchaudioTestCase):
"""Test suite for correctness of compute_deltas"""
def test_one_channel(self):
Expand Down
7 changes: 7 additions & 0 deletions torchaudio/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,13 @@ def create_fb_matrix(
enorm = 2.0 / (f_pts[2:n_mels + 2] - f_pts[:n_mels])
fb *= enorm.unsqueeze(0)

if (fb.max(dim=0).values == 0.).any():
warnings.warn(
"At least one mel filterbank has all zero values. "
f"The value for `n_mels` ({n_mels}) may be set too high. "
f"Or, the value for `n_freqs` ({n_freqs}) may be set too low."
)

return fb


Expand Down