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

Ignore the NoUtterancesError when calculating pesq for a batch #2753

Merged
merged 15 commits into from
Oct 9, 2024
4 changes: 3 additions & 1 deletion src/torchmetrics/functional/audio/pesq.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def perceptual_evaluation_speech_quality(
)
import pesq as pesq_backend

_filter_error_msg = np.vectorize(lambda x: np.issubdtype(type(x), np.number))
Borda marked this conversation as resolved.
Show resolved Hide resolved

if fs not in (8000, 16000):
raise ValueError(f"Expected argument `fs` to either be 8000 or 16000 but got {fs}")
if mode not in ("wb", "nb"):
Expand All @@ -103,7 +105,7 @@ def perceptual_evaluation_speech_quality(
pesq_val_np = np.empty(shape=(preds_np.shape[0]))
for b in range(preds_np.shape[0]):
pesq_val_np[b] = pesq_backend.pesq(fs, target_np[b, :], preds_np[b, :], mode)
pesq_val = torch.from_numpy(pesq_val_np)
pesq_val = torch.from_numpy(pesq_val_np[_filter_error_msg(pesq_val_np)])
pesq_val = pesq_val.reshape(preds.shape[:-1])

if keep_same_device:
Expand Down