diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ffd8e127a8..f4c07de9ad6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,11 @@ 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 Image ([#796](https://github.com/PyTorchLightning/metrics/pull/796)) + * `functional.ssim` + * `functional.psnr` + * `SSIM` + * `PSNR` - Removed deprecated functions, and warnings in detection and pairwise ([#804](https://github.com/PyTorchLightning/metrics/pull/804)) diff --git a/torchmetrics/__init__.py b/torchmetrics/__init__.py index 50af1f17447..d522762d78c 100644 --- a/torchmetrics/__init__.py +++ b/torchmetrics/__init__.py @@ -52,8 +52,6 @@ ) from torchmetrics.collections import MetricCollection # noqa: E402 from torchmetrics.image import ( # noqa: E402 - PSNR, - SSIM, MultiScaleStructuralSimilarityIndexMeasure, PeakSignalNoiseRatio, StructuralSimilarityIndexMeasure, @@ -148,7 +146,6 @@ "PermutationInvariantTraining", "Precision", "PrecisionRecallCurve", - "PSNR", "PeakSignalNoiseRatio", "R2Score", "Recall", @@ -170,7 +167,6 @@ "SpearmanCorrCoef", "Specificity", "SQuAD", - "SSIM", "StructuralSimilarityIndexMeasure", "StatScores", "SumMetric", diff --git a/torchmetrics/functional/__init__.py b/torchmetrics/functional/__init__.py index 3089fad2fe1..25fa04ba54b 100644 --- a/torchmetrics/functional/__init__.py +++ b/torchmetrics/functional/__init__.py @@ -35,10 +35,9 @@ from torchmetrics.functional.classification.specificity import specificity from torchmetrics.functional.classification.stat_scores import stat_scores from torchmetrics.functional.image.gradients import image_gradients -from torchmetrics.functional.image.psnr import peak_signal_noise_ratio, psnr +from torchmetrics.functional.image.psnr import peak_signal_noise_ratio from torchmetrics.functional.image.ssim import ( multiscale_structural_similarity_index_measure, - ssim, structural_similarity_index_measure, ) from torchmetrics.functional.pairwise.cosine import pairwise_cosine_similarity @@ -123,7 +122,6 @@ "precision_recall", "precision_recall_curve", "peak_signal_noise_ratio", - "psnr", "r2_score", "recall", "retrieval_average_precision", @@ -144,7 +142,6 @@ "spearman_corrcoef", "specificity", "squad", - "ssim", "structural_similarity_index_measure", "stat_scores", "symmetric_mean_absolute_percentage_error", diff --git a/torchmetrics/functional/image/__init__.py b/torchmetrics/functional/image/__init__.py index 04f38e3ef38..efef3576999 100644 --- a/torchmetrics/functional/image/__init__.py +++ b/torchmetrics/functional/image/__init__.py @@ -12,9 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. from torchmetrics.functional.image.gradients import image_gradients # noqa: F401 -from torchmetrics.functional.image.psnr import peak_signal_noise_ratio, psnr # noqa: F401 +from torchmetrics.functional.image.psnr import peak_signal_noise_ratio # noqa: F401 from torchmetrics.functional.image.ssim import ( # noqa: F401 multiscale_structural_similarity_index_measure, - ssim, structural_similarity_index_measure, ) diff --git a/torchmetrics/functional/image/ms_ssim.py b/torchmetrics/functional/image/ms_ssim.py deleted file mode 100644 index 89100f88b52..00000000000 --- a/torchmetrics/functional/image/ms_ssim.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright The PyTorch Lightning team. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# 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 typing import Optional, Sequence, Tuple - -import torch -from deprecate import deprecated, void -from torch import Tensor -from typing_extensions import Literal - -from torchmetrics.functional.image.ssim import multiscale_structural_similarity_index_measure as _ms_ssim -from torchmetrics.utilities import _future_warning - - -@deprecated(target=_ms_ssim, deprecated_in="0.7", remove_in="0.8", stream=_future_warning) -def multiscale_structural_similarity_index_measure( - preds: Tensor, - target: Tensor, - kernel_size: Sequence[int] = (11, 11), - sigma: Sequence[float] = (1.5, 1.5), - reduction: str = "elementwise_mean", - data_range: Optional[float] = None, - k1: float = 0.01, - k2: float = 0.03, - betas: Tuple[float, ...] = (0.0448, 0.2856, 0.3001, 0.2363, 0.1333), - normalize: Optional[Literal["relu", "simple"]] = None, -) -> Tensor: - """Computes `MultiScaleSSIM`_, Multi-scale Structual Similarity Index Measure, which is a generalization of - Structual Similarity Index Measure by incorporating image details at different resolution scores. - - Example: - >>> preds = torch.rand([1, 1, 256, 256], generator=torch.manual_seed(42)) - >>> target = preds * 0.75 - >>> multiscale_structural_similarity_index_measure(preds, target) - tensor(0.9558) - """ - return void(preds, target, kernel_size, sigma, reduction, data_range, k1, k2, betas, normalize) diff --git a/torchmetrics/functional/image/psnr.py b/torchmetrics/functional/image/psnr.py index f99e5995b36..31e9e8a1c6d 100644 --- a/torchmetrics/functional/image/psnr.py +++ b/torchmetrics/functional/image/psnr.py @@ -14,10 +14,9 @@ from typing import Optional, Tuple, Union import torch -from deprecate import deprecated, void from torch import Tensor, tensor -from torchmetrics.utilities import _future_warning, rank_zero_warn, reduce +from torchmetrics.utilities import rank_zero_warn, reduce def _psnr_compute( @@ -149,25 +148,3 @@ def peak_signal_noise_ratio( data_range = tensor(float(data_range)) sum_squared_error, n_obs = _psnr_update(preds, target, dim=dim) return _psnr_compute(sum_squared_error, n_obs, data_range, base=base, reduction=reduction) - - -@deprecated(target=peak_signal_noise_ratio, deprecated_in="0.7", remove_in="0.8", stream=_future_warning) -def psnr( - preds: Tensor, - target: Tensor, - data_range: Optional[float] = None, - base: float = 10.0, - reduction: str = "elementwise_mean", - dim: Optional[Union[int, Tuple[int, ...]]] = None, -) -> Tensor: - """Computes the peak signal-to-noise ratio. - - .. deprecated:: v0.7 - Use :func:torchmetrics.functional.psnr. Will be removed in v0.8. - - Example: - - >>> psnr(torch.tensor([[0.0, 1.0], [2.0, 3.0]]), torch.tensor([[3.0, 2.0], [1.0, 0.0]])) - tensor(2.5527) - """ - return void(preds, target, data_range, base, reduction, dim) diff --git a/torchmetrics/functional/image/ssim.py b/torchmetrics/functional/image/ssim.py index 8c033d5e154..a6dd8cd48de 100644 --- a/torchmetrics/functional/image/ssim.py +++ b/torchmetrics/functional/image/ssim.py @@ -14,12 +14,10 @@ from typing import List, Optional, Sequence, Tuple, Union import torch -from deprecate import deprecated, void from torch import Tensor from torch.nn import functional as F from typing_extensions import Literal -from torchmetrics.utilities import _future_warning from torchmetrics.utilities.checks import _check_same_shape from torchmetrics.utilities.distributed import reduce @@ -235,31 +233,6 @@ def structural_similarity_index_measure( return _ssim_compute(preds, target, kernel_size, sigma, reduction, data_range, k1, k2) -@deprecated(target=structural_similarity_index_measure, deprecated_in="0.7", remove_in="0.8", stream=_future_warning) -def ssim( - preds: Tensor, - target: Tensor, - kernel_size: Sequence[int] = (11, 11), - sigma: Sequence[float] = (1.5, 1.5), - reduction: str = "elementwise_mean", - data_range: Optional[float] = None, - k1: float = 0.01, - k2: float = 0.03, -) -> Tensor: - """Computes Structural Similarity Index Measure. - - .. deprecated:: v0.7 - Use :func:`torchmetrics.functional.scale_invariant_signal_noise_ratio`. Will be removed in v0.8. - - Example: - >>> preds = torch.rand([16, 1, 16, 16]) - >>> target = preds * 0.75 - >>> ssim(preds, target) - tensor(0.9219) - """ - return void(preds, target, kernel_size, sigma, reduction, data_range, k1, k2) - - def _get_normalized_sim_and_cs( preds: Tensor, target: Tensor, diff --git a/torchmetrics/image/__init__.py b/torchmetrics/image/__init__.py index b5c456a5e8c..87917e263a7 100644 --- a/torchmetrics/image/__init__.py +++ b/torchmetrics/image/__init__.py @@ -11,18 +11,17 @@ # 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.image.inception import IS, InceptionScore # noqa: F401 -from torchmetrics.image.kid import KID, KernelInceptionDistance # noqa: F401 -from torchmetrics.image.psnr import PSNR, PeakSignalNoiseRatio # noqa: F401 +from torchmetrics.image.psnr import PeakSignalNoiseRatio # noqa: F401 from torchmetrics.image.ssim import ( # noqa: F401 - SSIM, MultiScaleStructuralSimilarityIndexMeasure, StructuralSimilarityIndexMeasure, ) from torchmetrics.utilities.imports import _LPIPS_AVAILABLE, _TORCH_FIDELITY_AVAILABLE if _TORCH_FIDELITY_AVAILABLE: - from torchmetrics.image.fid import FID, FrechetInceptionDistance # noqa: F401 + from torchmetrics.image.fid import FrechetInceptionDistance # noqa: F401 + from torchmetrics.image.inception import InceptionScore # noqa: F401 + from torchmetrics.image.kid import KernelInceptionDistance # noqa: F401 if _LPIPS_AVAILABLE: - from torchmetrics.image.lpip import LPIPS, LearnedPerceptualImagePatchSimilarity # noqa: F401 + from torchmetrics.image.lpip import LearnedPerceptualImagePatchSimilarity # noqa: F401 diff --git a/torchmetrics/image/fid.py b/torchmetrics/image/fid.py index 0319c0c3544..5a023bd9425 100644 --- a/torchmetrics/image/fid.py +++ b/torchmetrics/image/fid.py @@ -15,12 +15,11 @@ import numpy as np import torch -from deprecate import deprecated, void from torch import Tensor from torch.autograd import Function from torchmetrics.metric import Metric -from torchmetrics.utilities import _future_warning, rank_zero_info, rank_zero_warn +from torchmetrics.utilities import rank_zero_info, rank_zero_warn from torchmetrics.utilities.data import dim_zero_cat from torchmetrics.utilities.imports import _SCIPY_AVAILABLE, _TORCH_FIDELITY_AVAILABLE @@ -285,36 +284,3 @@ def compute(self) -> Tensor: # compute fid return _compute_fid(mean1, cov1, mean2, cov2).to(orig_dtype) - - -class FID(FrechetInceptionDistance): - r""" - Calculates Fréchet inception distance (FID_) which is used to access the quality of generated images. - - .. deprecated:: v0.7 - Use :class:`torchmetrics.image.FrechetInceptionDistance`. Will be removed in v0.8. - - Example: - >>> import torch - >>> _ = torch.manual_seed(123) - >>> fid = FID(feature=64) - >>> # generate two slightly overlapping image intensity distributions - >>> imgs_dist1 = torch.randint(0, 200, (100, 3, 299, 299), dtype=torch.uint8) - >>> imgs_dist2 = torch.randint(100, 255, (100, 3, 299, 299), dtype=torch.uint8) - >>> fid.update(imgs_dist1, real=True) - >>> fid.update(imgs_dist2, real=False) - >>> fid.compute() - tensor(12.7202) - - """ - - @deprecated(target=FrechetInceptionDistance, deprecated_in="0.7", remove_in="0.8", stream=_future_warning) - def __init__( - self, - feature: Union[int, torch.nn.Module] = 2048, - compute_on_step: bool = False, - dist_sync_on_step: bool = False, - process_group: Optional[Any] = None, - dist_sync_fn: Callable[[Tensor], List[Tensor]] = None, - ) -> None: - void(feature, compute_on_step, dist_sync_on_step, process_group, dist_sync_fn) diff --git a/torchmetrics/image/inception.py b/torchmetrics/image/inception.py index 2ac88ab8ce6..a9a2fac1dd1 100644 --- a/torchmetrics/image/inception.py +++ b/torchmetrics/image/inception.py @@ -14,12 +14,11 @@ from typing import Any, Callable, List, Optional, Tuple, Union import torch -from deprecate import deprecated, void from torch import Tensor from torchmetrics.image.fid import NoTrainInceptionV3 from torchmetrics.metric import Metric -from torchmetrics.utilities import _future_warning, rank_zero_warn +from torchmetrics.utilities import rank_zero_warn from torchmetrics.utilities.data import dim_zero_cat from torchmetrics.utilities.imports import _TORCH_FIDELITY_AVAILABLE @@ -180,35 +179,3 @@ def compute(self) -> Tuple[Tensor, Tensor]: # return mean and std return kl.mean(), kl.std() - - -class IS(InceptionScore): - r""" - Calculates the Inception Score (IS) which is used to access how realistic generated images are. - - .. deprecated:: v0.7 - Use :class:`torchmetrics.image.InceptionScore`. Will be removed in v0.8. - - Example: - >>> import torch - >>> _ = torch.manual_seed(123) - >>> inception = IS() - >>> # generate some images - >>> imgs = torch.randint(0, 255, (100, 3, 299, 299), dtype=torch.uint8) - >>> inception.update(imgs) - >>> inception.compute() - (tensor(1.0544), tensor(0.0117)) - - """ - - @deprecated(target=InceptionScore, deprecated_in="0.7", remove_in="0.8", stream=_future_warning) - def __init__( - self, - feature: Union[str, int, torch.nn.Module] = "logits_unbiased", - splits: int = 10, - compute_on_step: bool = False, - dist_sync_on_step: bool = False, - process_group: Optional[Any] = None, - dist_sync_fn: Callable[[Tensor], List[Tensor]] = None, - ) -> None: - void(feature, splits, compute_on_step, dist_sync_on_step, process_group, dist_sync_fn) diff --git a/torchmetrics/image/kid.py b/torchmetrics/image/kid.py index 3fd1c7e6ae7..4726298ac11 100644 --- a/torchmetrics/image/kid.py +++ b/torchmetrics/image/kid.py @@ -14,13 +14,12 @@ from typing import Any, Callable, List, Optional, Tuple, Union import torch -from deprecate import deprecated, void from torch import Tensor from torch.nn import Module from torchmetrics.image.fid import NoTrainInceptionV3 from torchmetrics.metric import Metric -from torchmetrics.utilities import _future_warning, rank_zero_warn +from torchmetrics.utilities import rank_zero_warn from torchmetrics.utilities.data import dim_zero_cat from torchmetrics.utilities.imports import _TORCH_FIDELITY_AVAILABLE @@ -278,53 +277,3 @@ def compute(self) -> Tuple[Tensor, Tensor]: kid_scores_.append(o) kid_scores = torch.stack(kid_scores_) return kid_scores.mean(), kid_scores.std(unbiased=False) - - -class KID(KernelInceptionDistance): - r""" - Calculates Kernel Inception Distance (KID) which is used to access the quality of generated images. - - .. deprecated:: v0.7 - Use :class:`torchmetrics.image.KernelInceptionDistance`. Will be removed in v0.8. - - Example: - >>> import torch - >>> _ = torch.manual_seed(123) - >>> kid = KID(subset_size=50) - >>> # generate two slightly overlapping image intensity distributions - >>> imgs_dist1 = torch.randint(0, 200, (100, 3, 299, 299), dtype=torch.uint8) - >>> imgs_dist2 = torch.randint(100, 255, (100, 3, 299, 299), dtype=torch.uint8) - >>> kid.update(imgs_dist1, real=True) - >>> kid.update(imgs_dist2, real=False) - >>> kid_mean, kid_std = kid.compute() - >>> print((kid_mean, kid_std)) - (tensor(0.0337), tensor(0.0023)) - - """ - - @deprecated(target=KernelInceptionDistance, deprecated_in="0.7", remove_in="0.8", stream=_future_warning) - def __init__( - self, - feature: Union[str, int, torch.nn.Module] = 2048, - subsets: int = 100, - subset_size: int = 1000, - degree: int = 3, - gamma: Optional[float] = None, # type: ignore - coef: float = 1.0, - compute_on_step: bool = False, - dist_sync_on_step: bool = False, - process_group: Optional[Any] = None, - dist_sync_fn: Callable = None, - ) -> None: - void( - feature, - subsets, - subset_size, - degree, - gamma, - coef, - compute_on_step, - dist_sync_on_step, - process_group, - dist_sync_fn, - ) diff --git a/torchmetrics/image/lpip.py b/torchmetrics/image/lpip.py index 4354a3a8eeb..f492961057c 100644 --- a/torchmetrics/image/lpip.py +++ b/torchmetrics/image/lpip.py @@ -14,11 +14,9 @@ from typing import Any, Callable, List, Optional import torch -from deprecate import deprecated, void from torch import Tensor from torchmetrics.metric import Metric -from torchmetrics.utilities import _future_warning from torchmetrics.utilities.imports import _LPIPS_AVAILABLE if _LPIPS_AVAILABLE: @@ -159,36 +157,3 @@ def compute(self) -> Tensor: return self.sum_scores / self.total if self.reduction == "sum": return self.sum_scores - - -class LPIPS(LearnedPerceptualImagePatchSimilarity): - """The Learned Perceptual Image Patch Similarity (`LPIPS_`) is used to judge the perceptual similarity between - two images. LPIPS essentially computes the similarity between the activations of two image patches for some - pre-defined network. - - .. deprecated:: v0.7 - Use :class:`torchmetrics.image.LearnedPerceptualImagePatchSimilarity`. Will be removed in v0.8. - - Example: - >>> import torch - >>> _ = torch.manual_seed(123) - >>> lpips = LPIPS(net_type='vgg') - >>> img1 = torch.rand(10, 3, 100, 100) - >>> img2 = torch.rand(10, 3, 100, 100) - >>> lpips(img1, img2) - tensor(0.3566, grad_fn=) - """ - - @deprecated( - target=LearnedPerceptualImagePatchSimilarity, deprecated_in="0.7", remove_in="0.8", stream=_future_warning - ) - def __init__( - self, - net_type: str = "alex", - reduction: str = "mean", - compute_on_step: bool = True, - dist_sync_on_step: bool = False, - process_group: Optional[Any] = None, - dist_sync_fn: Callable[[Tensor], List[Tensor]] = None, - ) -> None: - void(net_type, reduction, compute_on_step, dist_sync_on_step, process_group, dist_sync_fn) diff --git a/torchmetrics/image/psnr.py b/torchmetrics/image/psnr.py index cfacc6f364e..5f92154ebe4 100644 --- a/torchmetrics/image/psnr.py +++ b/torchmetrics/image/psnr.py @@ -14,12 +14,11 @@ from typing import Any, Optional, Sequence, Tuple, Union import torch -from deprecate import deprecated, void from torch import Tensor, tensor from torchmetrics.functional.image.psnr import _psnr_compute, _psnr_update from torchmetrics.metric import Metric -from torchmetrics.utilities import _future_warning, rank_zero_warn +from torchmetrics.utilities import rank_zero_warn class PeakSignalNoiseRatio(Metric): @@ -147,29 +146,3 @@ def compute(self) -> Tensor: sum_squared_error = torch.cat([values.flatten() for values in self.sum_squared_error]) total = torch.cat([values.flatten() for values in self.total]) return _psnr_compute(sum_squared_error, total, data_range, base=self.base, reduction=self.reduction) - - -class PSNR(PeakSignalNoiseRatio): - """Peak Signal Noise Ratio (PSNR). - - .. deprecated:: v0.7 - Use :class:`torchmetrics.PeakSignalNoiseRatio`. Will be removed in v0.8. - - Example: - >>> psnr = PSNR() - >>> psnr(torch.tensor([[0.0, 1.0], [2.0, 3.0]]), torch.tensor([[3.0, 2.0], [1.0, 0.0]])) - tensor(2.5527) - """ - - @deprecated(target=PeakSignalNoiseRatio, deprecated_in="0.7", remove_in="0.8", stream=_future_warning) - def __init__( - self, - data_range: Optional[float] = None, - base: float = 10.0, - reduction: str = "elementwise_mean", - dim: Optional[Union[int, Tuple[int, ...]]] = None, - compute_on_step: bool = True, - dist_sync_on_step: bool = False, - process_group: Optional[Any] = None, - ) -> None: - void(data_range, base, reduction, dim, compute_on_step, dist_sync_on_step, process_group) diff --git a/torchmetrics/image/ssim.py b/torchmetrics/image/ssim.py index 1110c59a074..1f5aab9973e 100644 --- a/torchmetrics/image/ssim.py +++ b/torchmetrics/image/ssim.py @@ -13,14 +13,12 @@ # limitations under the License. from typing import Any, List, Optional, Sequence, Tuple -import torch -from deprecate import deprecated, void from torch import Tensor from typing_extensions import Literal from torchmetrics.functional.image.ssim import _multiscale_ssim_compute, _ssim_compute, _ssim_update from torchmetrics.metric import Metric -from torchmetrics.utilities import _future_warning, rank_zero_warn +from torchmetrics.utilities import rank_zero_warn from torchmetrics.utilities.data import dim_zero_cat @@ -45,6 +43,7 @@ class StructuralSimilarityIndexMeasure(Metric): Example: >>> from torchmetrics import StructuralSimilarityIndexMeasure + >>> import torch >>> preds = torch.rand([16, 1, 16, 16]) >>> target = preds * 0.75 >>> ssim = StructuralSimilarityIndexMeasure() @@ -108,36 +107,6 @@ def compute(self) -> Tensor: ) -class SSIM(StructuralSimilarityIndexMeasure): - """Computes Structual Similarity Index Measure (SSIM_). - - .. deprecated:: v0.7 - Use :class:`torchmetrics.StructuralSimilarityIndexMeasure`. Will be removed in v0.8. - - Example: - >>> preds = torch.rand([16, 1, 16, 16]) - >>> target = preds * 0.75 - >>> ssim = SSIM() - >>> ssim(preds, target) - tensor(0.9219) - """ - - @deprecated(target=StructuralSimilarityIndexMeasure, deprecated_in="0.7", remove_in="0.8", stream=_future_warning) - def __init__( - self, - kernel_size: Sequence[int] = (11, 11), - sigma: Sequence[float] = (1.5, 1.5), - reduction: str = "elementwise_mean", - data_range: Optional[float] = None, - k1: float = 0.01, - k2: float = 0.03, - compute_on_step: bool = True, - dist_sync_on_step: bool = False, - process_group: Optional[Any] = None, - ) -> None: - void(kernel_size, sigma, reduction, data_range, k1, k2, compute_on_step, dist_sync_on_step, process_group) - - class MultiScaleStructuralSimilarityIndexMeasure(Metric): """Computes `MultiScaleSSIM`_, Multi-scale Structural Similarity Index Measure, which is a generalization of Structural Similarity Index Measure by incorporating image details at different resolution scores. @@ -165,6 +134,7 @@ class MultiScaleStructuralSimilarityIndexMeasure(Metric): Example: >>> from torchmetrics import MultiScaleStructuralSimilarityIndexMeasure + >>> import torch >>> preds = torch.rand([1, 1, 256, 256], generator=torch.manual_seed(42)) >>> target = preds * 0.75 >>> ms_ssim = MultiScaleStructuralSimilarityIndexMeasure()