Unverified Commit 77df44e3 authored by toddstep's avatar toddstep Committed by GitHub
Browse files

Issue warning when a Mel filter is all zero (#914)

* Warn if create_fb_matrix produces a column whose weights are all zeros

See also https://github.com/librosa/librosa/issues/478
parent e7161acf
......@@ -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):
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment