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

Prune deprecated: audio #805

Merged
merged 7 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed deprecated functions, and warnings in Text ([#773](https://github.com/PyTorchLightning/metrics/pull/773))
* `functional.wer`
* `WER`
- Removed deprecated functions, and warnings in Audio ([#805](https://github.com/PyTorchLightning/metrics/pull/805))
* `PESQ`
* `PIT`
* `SDR`
* `SNR`
* `STOI`
* `functional.audio.pesq`
* `functional.audio.pit`
* `functional.audio.sdr`
* `functional.audio.snr`
* `functional.audio.stoi`
* `functional.audio.si_sdr`
* `functional.audio.si_snr`


### Fixed
Expand Down
2 changes: 1 addition & 1 deletion docs/source/references/functional.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ scale_invariant_signal_distortion_ratio [func]
scale_invariant_signal_noise_ratio [func]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. autofunction:: torchmetrics.functional.si_snr
.. autofunction:: torchmetrics.functional.scale_invariant_signal_noise_ratio
:noindex:


Expand Down
6 changes: 0 additions & 6 deletions docs/source/references/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ the metric will be computed over the ``time`` dimension.
>>> snr = SignalNoiseRatio()
>>> snr(preds, target)
tensor(16.1805)
>>> from torchmetrics import SNR
>>> target = torch.tensor([3.0, -0.5, 2.0, 7.0])
>>> preds = torch.tensor([2.5, 0.0, 2.0, 8.0])
>>> snr = SignalNoiseRatio()
>>> snr(preds, target)
tensor(16.1805)

PerceptualEvaluationSpeechQuality
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
18 changes: 11 additions & 7 deletions tests/audio/test_pit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
from tests.helpers import seed_all
from tests.helpers.testers import BATCH_SIZE, NUM_BATCHES, MetricTester
from torchmetrics.audio import PermutationInvariantTraining
from torchmetrics.functional import permutation_invariant_training, scale_invariant_signal_distortion_ratio, snr
from torchmetrics.functional import (
permutation_invariant_training,
scale_invariant_signal_distortion_ratio,
signal_noise_ratio,
)
from torchmetrics.utilities.imports import _TORCH_GREATER_EQUAL_1_6

seed_all(42)
Expand Down Expand Up @@ -96,7 +100,7 @@ def _average_metric(preds: Tensor, target: Tensor, metric_func: Callable) -> Ten
return metric_func(preds, target)[0].mean()


snr_pit_scipy = partial(naive_implementation_pit_scipy, metric_func=snr, eval_func="max")
snr_pit_scipy = partial(naive_implementation_pit_scipy, metric_func=signal_noise_ratio, eval_func="max")
si_sdr_pit_scipy = partial(
naive_implementation_pit_scipy, metric_func=scale_invariant_signal_distortion_ratio, eval_func="max"
)
Expand All @@ -105,9 +109,9 @@ def _average_metric(preds: Tensor, target: Tensor, metric_func: Callable) -> Ten
@pytest.mark.parametrize(
"preds, target, sk_metric, metric_func, eval_func",
[
(inputs1.preds, inputs1.target, snr_pit_scipy, snr, "max"),
(inputs1.preds, inputs1.target, snr_pit_scipy, signal_noise_ratio, "max"),
(inputs1.preds, inputs1.target, si_sdr_pit_scipy, scale_invariant_signal_distortion_ratio, "max"),
(inputs2.preds, inputs2.target, snr_pit_scipy, snr, "max"),
(inputs2.preds, inputs2.target, snr_pit_scipy, signal_noise_ratio, "max"),
(inputs2.preds, inputs2.target, si_sdr_pit_scipy, scale_invariant_signal_distortion_ratio, "max"),
],
)
Expand Down Expand Up @@ -166,19 +170,19 @@ def test_pit_half_gpu(self, preds, target, sk_metric, metric_func, eval_func):


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


def test_error_on_wrong_eval_func() -> None:
metric = PermutationInvariantTraining(snr, "xxx")
metric = PermutationInvariantTraining(signal_noise_ratio, "xxx")
with pytest.raises(ValueError, match='eval_func can only be "max" or "min"'):
metric(torch.randn(3, 3, 10), torch.randn(3, 3, 10))


def test_error_on_wrong_shape() -> None:
metric = PermutationInvariantTraining(snr, "max")
metric = PermutationInvariantTraining(signal_noise_ratio, "max")
with pytest.raises(ValueError, match="Inputs must be of shape *"):
metric(torch.randn(3), torch.randn(3))

Expand Down
10 changes: 0 additions & 10 deletions torchmetrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
from torchmetrics import functional # noqa: E402
from torchmetrics.aggregation import CatMetric, MaxMetric, MeanMetric, MinMetric, SumMetric # noqa: E402
from torchmetrics.audio import ( # noqa: E402
PIT,
SDR,
SI_SDR,
SI_SNR,
SNR,
PermutationInvariantTraining,
ScaleInvariantSignalDistortionRatio,
ScaleInvariantSignalNoiseRatio,
Expand Down Expand Up @@ -151,7 +146,6 @@
"PearsonCorrcoef",
"PearsonCorrCoef",
"PermutationInvariantTraining",
"PIT",
"Precision",
"PrecisionRecallCurve",
"PSNR",
Expand All @@ -168,14 +162,10 @@
"RetrievalRPrecision",
"ROC",
"SacreBLEUScore",
"SDR",
"SignalDistortionRatio",
"ScaleInvariantSignalDistortionRatio",
"SI_SDR",
"SI_SNR",
"ScaleInvariantSignalNoiseRatio",
"SignalNoiseRatio",
"SNR",
"SpearmanCorrcoef",
"SpearmanCorrCoef",
"Specificity",
Expand Down
8 changes: 3 additions & 5 deletions torchmetrics/audio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from torchmetrics.audio.pit import PIT, PermutationInvariantTraining # noqa: F401
from torchmetrics.audio.sdr import SDR, ScaleInvariantSignalDistortionRatio, SignalDistortionRatio # noqa: F401
from torchmetrics.audio.si_sdr import SI_SDR # noqa: F401
from torchmetrics.audio.si_snr import SI_SNR # noqa: F401
from torchmetrics.audio.snr import SNR, ScaleInvariantSignalNoiseRatio, SignalNoiseRatio # noqa: F401
from torchmetrics.audio.pit import PermutationInvariantTraining # noqa: F401
from torchmetrics.audio.sdr import ScaleInvariantSignalDistortionRatio, SignalDistortionRatio # noqa: F401
from torchmetrics.audio.snr import ScaleInvariantSignalNoiseRatio, SignalNoiseRatio # noqa: F401
from torchmetrics.utilities.imports import _PESQ_AVAILABLE, _PYSTOI_AVAILABLE

if _PESQ_AVAILABLE:
Expand Down
36 changes: 1 addition & 35 deletions torchmetrics/audio/pesq.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
# limitations under the License.
from typing import Any, Callable, Optional

from deprecate import deprecated, void
from torch import Tensor, tensor

from torchmetrics.functional.audio.pesq import perceptual_evaluation_speech_quality
from torchmetrics.metric import Metric
from torchmetrics.utilities import _future_warning
from torchmetrics.utilities.imports import _PESQ_AVAILABLE

__doctest_requires__ = {("PerceptualEvaluationSpeechQuality", "PESQ"): ["pesq"]}
__doctest_requires__ = {("PerceptualEvaluationSpeechQuality"): ["pesq"]}


class PerceptualEvaluationSpeechQuality(Metric):
Expand Down Expand Up @@ -134,35 +132,3 @@ def update(self, preds: Tensor, target: Tensor) -> None: # type: ignore
def compute(self) -> Tensor:
"""Computes average PESQ."""
return self.sum_pesq / self.total


class PESQ(PerceptualEvaluationSpeechQuality):
"""Perceptual Evaluation of Speech Quality (PESQ).

.. deprecated:: v0.7
Use :class:`torchmetrics.audio.PerceptualEvaluationSpeechQuality`. Will be removed in v0.8.

Example:
>>> import torch
>>> g = torch.manual_seed(1)
>>> preds = torch.randn(8000)
>>> target = torch.randn(8000)
>>> nb_pesq = PESQ(8000, 'nb')
>>> nb_pesq(preds, target)
tensor(2.2076)
>>> wb_pesq = PESQ(16000, 'wb')
>>> wb_pesq(preds, target)
tensor(1.7359)
"""

@deprecated(target=PerceptualEvaluationSpeechQuality, deprecated_in="0.7", remove_in="0.8", stream=_future_warning)
def __init__(
self,
fs: int,
mode: str,
compute_on_step: bool = True,
dist_sync_on_step: bool = False,
process_group: Optional[Any] = None,
dist_sync_fn: Optional[Callable[[Tensor], Tensor]] = None,
) -> None:
void(fs, mode, compute_on_step, dist_sync_on_step, process_group, dist_sync_fn)
42 changes: 2 additions & 40 deletions torchmetrics/audio/pit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
# limitations under the License.
from typing import Any, Callable, Dict, Optional

from deprecate import deprecated, void
from torch import Tensor, tensor

from torchmetrics.functional.audio.pit import permutation_invariant_training
from torchmetrics.metric import Metric
from torchmetrics.utilities import _future_warning


class PermutationInvariantTraining(Metric):
Expand Down Expand Up @@ -58,11 +56,11 @@ class PermutationInvariantTraining(Metric):
Example:
>>> import torch
>>> from torchmetrics import PermutationInvariantTraining
>>> from torchmetrics.functional import si_snr
>>> from torchmetrics.functional import scale_invariant_signal_noise_ratio
>>> _ = torch.manual_seed(42)
>>> preds = torch.randn(3, 2, 5) # [batch, spk, time]
>>> target = torch.randn(3, 2, 5) # [batch, spk, time]
>>> pit = PermutationInvariantTraining(si_snr, 'max')
>>> pit = PermutationInvariantTraining(scale_invariant_signal_noise_ratio, 'max')
>>> pit(preds, target)
tensor(-2.1065)

Expand Down Expand Up @@ -114,39 +112,3 @@ def update(self, preds: Tensor, target: Tensor) -> None: # type: ignore
def compute(self) -> Tensor:
"""Computes average PermutationInvariantTraining metric."""
return self.sum_pit_metric / self.total


class PIT(PermutationInvariantTraining):
"""Permutation invariant training (PIT). The PIT implements the famous Permutation Invariant Training method.

[1] in speech separation field in order to calculate audio metrics in a permutation invariant way.

.. deprecated:: v0.7
Use :class:`torchmetrics.audio.PermutationInvariantTraining`. Will be removed in v0.8.

Example:
>>> import torch
>>> from torchmetrics.functional import si_snr
>>> _ = torch.manual_seed(42)
>>> pit = PIT(si_snr, 'max')
>>> pit(torch.randn(3, 2, 5), torch.randn(3, 2, 5))
tensor(-2.1065)

Reference:
[1] D. Yu, M. Kolbaek, Z.-H. Tan, J. Jensen, Permutation invariant training of deep models for
speaker-independent multi-talker speech separation, in: 2017 IEEE Int. Conf. Acoust. Speech
Signal Process. ICASSP, IEEE, New Orleans, LA, 2017: pp. 241–245. https://doi.org/10.1109/ICASSP.2017.7952154.
"""

@deprecated(target=PermutationInvariantTraining, deprecated_in="0.7", remove_in="0.8", stream=_future_warning)
def __init__(
self,
metric_func: Callable,
eval_func: str = "max",
compute_on_step: bool = True,
dist_sync_on_step: bool = False,
process_group: Optional[Any] = None,
dist_sync_fn: Optional[Callable[[Tensor], Tensor]] = None,
**kwargs: Dict[str, Any],
) -> None:
void(metric_func, eval_func, compute_on_step, dist_sync_on_step, process_group, dist_sync_fn, **kwargs)
48 changes: 1 addition & 47 deletions torchmetrics/audio/sdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
# limitations under the License.
from typing import Any, Callable, Optional

from deprecate import deprecated, void
from torch import Tensor, tensor

from torchmetrics.functional.audio.sdr import scale_invariant_signal_distortion_ratio, signal_distortion_ratio
from torchmetrics.metric import Metric
from torchmetrics.utilities import _future_warning
from torchmetrics.utilities.imports import _FAST_BSS_EVAL_AVAILABLE

__doctest_requires__ = {("SignalDistortionRatio", "SDR"): ["fast_bss_eval"]}
__doctest_requires__ = {("SignalDistortionRatio"): ["fast_bss_eval"]}


class SignalDistortionRatio(Metric):
Expand Down Expand Up @@ -156,50 +154,6 @@ def compute(self) -> Tensor:
return self.sum_sdr / self.total


class SDR(SignalDistortionRatio):
r"""Signal to Distortion Ratio (SDR)

.. deprecated:: v0.7
Use :class:`torchmetrics.SignalDistortionRatio`. Will be removed in v0.8.

Example:
>>> import torch
>>> g = torch.manual_seed(1)
>>> sdr = SDR()
>>> sdr(torch.randn(8000), torch.randn(8000))
tensor(-12.0589)
>>> # use with pit
>>> from torchmetrics.audio import PermutationInvariantTraining
>>> from torchmetrics.functional.audio import signal_distortion_ratio
>>> pit = PermutationInvariantTraining(signal_distortion_ratio, 'max')
>>> pit(torch.randn(4, 2, 8000), torch.randn(4, 2, 8000))
tensor(-11.6051)
"""

@deprecated(target=SignalDistortionRatio, deprecated_in="0.7", remove_in="0.8", stream=_future_warning)
def __init__(
self,
use_cg_iter: Optional[int] = None,
filter_length: int = 512,
zero_mean: bool = False,
load_diag: Optional[float] = None,
compute_on_step: bool = True,
dist_sync_on_step: bool = False,
process_group: Optional[Any] = None,
dist_sync_fn: Optional[Callable[[Tensor], Tensor]] = None,
) -> None:
void(
use_cg_iter,
filter_length,
zero_mean,
load_diag,
compute_on_step,
dist_sync_on_step,
process_group,
dist_sync_fn,
)


class ScaleInvariantSignalDistortionRatio(Metric):
"""Scale-invariant signal-to-distortion ratio (SI-SDR). The SI-SDR value is in general considered an overall
measure of how good a source sound.
Expand Down
47 changes: 0 additions & 47 deletions torchmetrics/audio/si_sdr.py

This file was deleted.

Loading