Skip to content

Commit

Permalink
Remove deprecated code from image domain (#796)
Browse files Browse the repository at this point in the history
* Remove deprecated functions, and warnings
* Update links for docstring
* chlog

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jirka <[email protected]>
  • Loading branch information
3 people authored Feb 5, 2022
1 parent b225889 commit 8e9eb8e
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 331 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 0 additions & 4 deletions torchmetrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
)
from torchmetrics.collections import MetricCollection # noqa: E402
from torchmetrics.image import ( # noqa: E402
PSNR,
SSIM,
MultiScaleStructuralSimilarityIndexMeasure,
PeakSignalNoiseRatio,
StructuralSimilarityIndexMeasure,
Expand Down Expand Up @@ -148,7 +146,6 @@
"PermutationInvariantTraining",
"Precision",
"PrecisionRecallCurve",
"PSNR",
"PeakSignalNoiseRatio",
"R2Score",
"Recall",
Expand All @@ -170,7 +167,6 @@
"SpearmanCorrCoef",
"Specificity",
"SQuAD",
"SSIM",
"StructuralSimilarityIndexMeasure",
"StatScores",
"SumMetric",
Expand Down
5 changes: 1 addition & 4 deletions torchmetrics/functional/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -123,7 +122,6 @@
"precision_recall",
"precision_recall_curve",
"peak_signal_noise_ratio",
"psnr",
"r2_score",
"recall",
"retrieval_average_precision",
Expand All @@ -144,7 +142,6 @@
"spearman_corrcoef",
"specificity",
"squad",
"ssim",
"structural_similarity_index_measure",
"stat_scores",
"symmetric_mean_absolute_percentage_error",
Expand Down
3 changes: 1 addition & 2 deletions torchmetrics/functional/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
47 changes: 0 additions & 47 deletions torchmetrics/functional/image/ms_ssim.py

This file was deleted.

25 changes: 1 addition & 24 deletions torchmetrics/functional/image/psnr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
27 changes: 0 additions & 27 deletions torchmetrics/functional/image/ssim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
11 changes: 5 additions & 6 deletions torchmetrics/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 1 addition & 35 deletions torchmetrics/image/fid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
35 changes: 1 addition & 34 deletions torchmetrics/image/inception.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Loading

0 comments on commit 8e9eb8e

Please sign in to comment.