Skip to content

Commit

Permalink
Improved shape checking of permutation_invariant_training (#864)
Browse files Browse the repository at this point in the history
* fix

* update change log

* pep 8

Co-authored-by: quancs <quancs@qq.com>
  • Loading branch information
quancs and quancs authored Feb 28, 2022
1 parent 9f94086 commit ffe824a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion tests/audio/test_pit.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ def test_pit_half_gpu(self, preds, target, sk_metric, metric_func, eval_func):

def test_error_on_different_shape() -> None:
metric = PermutationInvariantTraining(signal_noise_ratio, "max")
with pytest.raises(RuntimeError, match="Predictions and targets are expected to have the same shape"):
with pytest.raises(
RuntimeError,
match="Predictions and targets are expected to have the same shape at the batch and speaker dimensions",
):
metric(torch.randn(3, 3, 10), torch.randn(3, 2, 10))


Expand Down
6 changes: 4 additions & 2 deletions torchmetrics/functional/audio/pit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import torch
from torch import Tensor

from torchmetrics.utilities.checks import _check_same_shape
from torchmetrics.utilities.imports import _SCIPY_AVAILABLE

# _ps_dict: cache of permutations
Expand Down Expand Up @@ -145,7 +144,10 @@ def permutation_invariant_training(
Reference:
[1] `Permutation Invariant Training of Deep Models`_
"""
_check_same_shape(preds, target)
if preds.shape[0:2] != target.shape[0:2]:
raise RuntimeError(
"Predictions and targets are expected to have the same shape at the batch and speaker dimensions"
)
if eval_func not in ["max", "min"]:
raise ValueError(f'eval_func can only be "max" or "min" but got {eval_func}')
if target.ndim < 2:
Expand Down

0 comments on commit ffe824a

Please sign in to comment.