diff --git a/docs/source/functional.rst b/docs/source/functional.rst index 60c548f5a9..0f9dd0a58d 100644 --- a/docs/source/functional.rst +++ b/docs/source/functional.rst @@ -66,27 +66,6 @@ resample .. autofunction:: resample -:hidden:`Complex Utility` -~~~~~~~~~~~~~~~~~~~~~~~~~ - -Utilities for pseudo complex tensor. This is not for the native complex dtype, such as `cfloat64`, but for tensors with real-value type and have extra dimension at the end for real and imaginary parts. - -angle ------ - -.. autofunction:: angle - -complex_norm ------------- - -.. autofunction:: complex_norm - - -magphase --------- - -.. autofunction:: magphase - :hidden:`Filtering` ~~~~~~~~~~~~~~~~~~~ diff --git a/docs/source/transforms.rst b/docs/source/transforms.rst index c5fa327cca..abde637132 100644 --- a/docs/source/transforms.rst +++ b/docs/source/transforms.rst @@ -87,13 +87,6 @@ Transforms are common audio transforms. They can be chained together using :clas .. automethod:: forward -:hidden:`ComplexNorm` -~~~~~~~~~~~~~~~~~~~~~ - -.. autoclass:: ComplexNorm - - .. automethod:: forward - :hidden:`ComputeDeltas` ~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/test/torchaudio_unittest/functional/functional_impl.py b/test/torchaudio_unittest/functional/functional_impl.py index 1b18bd255b..d3dabdc801 100644 --- a/test/torchaudio_unittest/functional/functional_impl.py +++ b/test/torchaudio_unittest/functional/functional_impl.py @@ -217,16 +217,6 @@ def test_amplitude_to_DB_top_db_clamp(self, shape): f"No values were close to the limit. Did it over-clamp?\n{decibels}" ) - @parameterized.expand( - list(itertools.product([(1, 2, 1025, 400, 2), (1025, 400, 2)], [1, 2, 0.7])) - ) - def test_complex_norm(self, shape, power): - torch.random.manual_seed(42) - complex_tensor = torch.randn(*shape, dtype=self.dtype, device=self.device) - expected_norm_tensor = complex_tensor.pow(2).sum(-1).pow(power / 2) - norm_tensor = F.complex_norm(complex_tensor, power) - self.assertEqual(norm_tensor, expected_norm_tensor, atol=1e-5, rtol=1e-5) - @parameterized.expand( list(itertools.product([(2, 1025, 400), (1, 201, 100)], [100], [0., 30.], [1, 2])) ) diff --git a/test/torchaudio_unittest/functional/torchscript_consistency_impl.py b/test/torchaudio_unittest/functional/torchscript_consistency_impl.py index a6424a0acb..59f2b0b06d 100644 --- a/test/torchaudio_unittest/functional/torchscript_consistency_impl.py +++ b/test/torchaudio_unittest/functional/torchscript_consistency_impl.py @@ -196,14 +196,6 @@ def func(tensor): tensor = torch.rand((1, 10)) self._assert_consistency(func, tensor) - def test_complex_norm(self): - def func(tensor): - power = 2. - return F.complex_norm(tensor, power) - - tensor = torch.randn(1, 2, 1025, 400, 2) - self._assert_consistency(func, tensor) - def test_mask_along_axis(self): def func(tensor): mask_param = 100 diff --git a/test/torchaudio_unittest/transforms/torchscript_consistency_impl.py b/test/torchaudio_unittest/transforms/torchscript_consistency_impl.py index 750f0d5d62..1a8eb67d7c 100644 --- a/test/torchaudio_unittest/transforms/torchscript_consistency_impl.py +++ b/test/torchaudio_unittest/transforms/torchscript_consistency_impl.py @@ -80,10 +80,6 @@ def test_Resample(self): tensor = common_utils.get_whitenoise(sample_rate=sr1) self._assert_consistency(T.Resample(float(sr1), float(sr2)), tensor) - def test_ComplexNorm(self): - tensor = torch.rand((1, 2, 201, 2)) - self._assert_consistency(T.ComplexNorm(), tensor) - def test_MuLawEncoding(self): tensor = common_utils.get_whitenoise() self._assert_consistency(T.MuLawEncoding(), tensor) diff --git a/torchaudio/functional/__init__.py b/torchaudio/functional/__init__.py index 5f81b7edf8..b9ac34d7a8 100644 --- a/torchaudio/functional/__init__.py +++ b/torchaudio/functional/__init__.py @@ -1,7 +1,5 @@ from .functional import ( amplitude_to_DB, - angle, - complex_norm, compute_deltas, compute_kaldi_pitch, create_dct, @@ -10,7 +8,6 @@ DB_to_amplitude, detect_pitch_frequency, griffinlim, - magphase, mask_along_axis, mask_along_axis_iid, mu_law_encoding, @@ -50,8 +47,6 @@ __all__ = [ 'amplitude_to_DB', - 'angle', - 'complex_norm', 'compute_deltas', 'compute_kaldi_pitch', 'create_dct', @@ -60,7 +55,6 @@ 'DB_to_amplitude', 'detect_pitch_frequency', 'griffinlim', - 'magphase', 'mask_along_axis', 'mask_along_axis_iid', 'mu_law_encoding', diff --git a/torchaudio/functional/functional.py b/torchaudio/functional/functional.py index 7982b0b6ce..e05f6f33df 100644 --- a/torchaudio/functional/functional.py +++ b/torchaudio/functional/functional.py @@ -3,7 +3,7 @@ from collections.abc import Sequence import io import math -import warnings +#import warnings from typing import Optional, Tuple import torch @@ -26,9 +26,6 @@ "DB_to_amplitude", "mu_law_encoding", "mu_law_decoding", - "complex_norm", - "angle", - "magphase", "phase_vocoder", 'mask_along_axis', 'mask_along_axis_iid', @@ -580,78 +577,6 @@ def mu_law_decoding( return x -@_mod_utils.deprecated( - "Please convert the input Tensor to complex type with `torch.view_as_complex` then " - "use `torch.abs`. " - "Please refer to https://github.com/pytorch/audio/issues/1337 " - "for more details about torchaudio's plan to migrate to native complex type.", - version="0.11", -) -def complex_norm( - complex_tensor: Tensor, - power: float = 1.0 -) -> Tensor: - r"""Compute the norm of complex tensor input. - - Args: - complex_tensor (Tensor): Tensor shape of `(..., complex=2)` - power (float): Power of the norm. (Default: `1.0`). - - Returns: - Tensor: Power of the normed input tensor. Shape of `(..., )` - """ - - # Replace by torch.norm once issue is fixed - # https://github.com/pytorch/pytorch/issues/34279 - return complex_tensor.pow(2.).sum(-1).pow(0.5 * power) - - -@_mod_utils.deprecated( - "Please convert the input Tensor to complex type with `torch.view_as_complex` then " - "use `torch.angle`. " - "Please refer to https://github.com/pytorch/audio/issues/1337 " - "for more details about torchaudio's plan to migrate to native complex type.", - version="0.11", -) -def angle( - complex_tensor: Tensor -) -> Tensor: - r"""Compute the angle of complex tensor input. - - Args: - complex_tensor (Tensor): Tensor shape of `(..., complex=2)` - - Return: - Tensor: Angle of a complex tensor. Shape of `(..., )` - """ - return torch.atan2(complex_tensor[..., 1], complex_tensor[..., 0]) - - -@_mod_utils.deprecated( - "Please convert the input Tensor to complex type with `torch.view_as_complex` then " - "use `torch.abs` and `torch.angle`. " - "Please refer to https://github.com/pytorch/audio/issues/1337 " - "for more details about torchaudio's plan to migrate to native complex type.", - version="0.11", -) -def magphase( - complex_tensor: Tensor, - power: float = 1.0 -) -> Tuple[Tensor, Tensor]: - r"""Separate a complex-valued spectrogram with shape `(..., 2)` into its magnitude and phase. - - Args: - complex_tensor (Tensor): Tensor shape of `(..., complex=2)` - power (float): Power of the norm. (Default: `1.0`) - - Returns: - (Tensor, Tensor): The magnitude and phase of the complex tensor - """ - mag = complex_norm(complex_tensor, power) - phase = angle(complex_tensor) - return mag, phase - - def phase_vocoder( complex_specgrams: Tensor, rate: float, diff --git a/torchaudio/transforms.py b/torchaudio/transforms.py index ac4a3192ad..40411e9550 100644 --- a/torchaudio/transforms.py +++ b/torchaudio/transforms.py @@ -25,7 +25,6 @@ 'MuLawEncoding', 'MuLawDecoding', 'Resample', - 'ComplexNorm', 'TimeStretch', 'Fade', 'FrequencyMasking', @@ -69,6 +68,13 @@ class Spectrogram(torch.nn.Module): This argument is only effective when ``power=None``. It is ignored for cases where ``power`` is a number as in those cases, the returned tensor is power spectrogram, which is a real-valued tensor. + + Example + + >>> specgram = torch.randn(1, 40, 1000) + >>> specgram = torchaudio.transforms.Spectrogram()(specgram) + >>> specgram.shape + torch.Size([1, 40, 201, 6]) """ __constants__ = ['n_fft', 'win_length', 'hop_length', 'pad', 'power', 'normalized'] @@ -775,37 +781,6 @@ def forward(self, waveform: Tensor) -> Tensor: self.kernel, self.width) -class ComplexNorm(torch.nn.Module): - r"""Compute the norm of complex tensor input. - - Args: - power (float, optional): Power of the norm. (Default: to ``1.0``) - """ - __constants__ = ['power'] - - def __init__(self, power: float = 1.0) -> None: - warnings.warn( - 'torchaudio.transforms.ComplexNorm has been deprecated ' - 'and will be removed from future release.' - 'Please convert the input Tensor to complex type with `torch.view_as_complex` then ' - 'use `torch.abs` and `torch.angle`. ' - 'Please refer to https://github.com/pytorch/audio/issues/1337 ' - "for more details about torchaudio's plan to migrate to native complex type." - ) - super(ComplexNorm, self).__init__() - self.power = power - - def forward(self, complex_tensor: Tensor) -> Tensor: - r""" - Args: - complex_tensor (Tensor): Tensor shape of `(..., complex=2)`. - - Returns: - Tensor: norm of the input tensor, shape of `(..., )`. - """ - return F.complex_norm(complex_tensor, self.power) - - class ComputeDeltas(torch.nn.Module): r"""Compute delta coefficients of a tensor, usually a spectrogram.