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: classification and regression #806

Merged
merged 20 commits into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `PSNR`


- Removed deprecated functions, and warnings in classification and regression ([#806](https://github.com/PyTorchLightning/metrics/pull/806))
* `FBeta`
* `F1`
* `Hinge`
* `IoU`
* `functional.iou`
* `MatthewsCorrcoef`
* `PearsonCorrcoef`
* `SpearmanCorrcoef`
* `functional.fbeta`
* `functional.f1`
* `functional.hinge`



- Removed deprecated functions, and warnings in detection and pairwise ([#804](https://github.com/PyTorchLightning/metrics/pull/804))
* `MAP`
* `functional.pairwise.manhatten`
Expand Down
15 changes: 1 addition & 14 deletions torchmetrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
SignalDistortionRatio,
SignalNoiseRatio,
)
from torchmetrics.classification import ( # noqa: E402, F401
from torchmetrics.classification import ( # noqa: E402
AUC,
AUROC,
F1,
ROC,
Accuracy,
AveragePrecision,
Expand All @@ -34,15 +33,11 @@
CohenKappa,
ConfusionMatrix,
F1Score,
FBeta,
FBetaScore,
HammingDistance,
Hinge,
HingeLoss,
IoU,
JaccardIndex,
KLDivergence,
MatthewsCorrcoef,
MatthewsCorrCoef,
Precision,
PrecisionRecallCurve,
Expand All @@ -64,10 +59,8 @@
MeanAbsolutePercentageError,
MeanSquaredError,
MeanSquaredLogError,
PearsonCorrcoef,
PearsonCorrCoef,
R2Score,
SpearmanCorrcoef,
SpearmanCorrCoef,
SymmetricMeanAbsolutePercentageError,
TweedieDevianceScore,
Expand Down Expand Up @@ -117,16 +110,12 @@
"TweedieDevianceScore",
"ExplainedVariance",
"ExtendedEditDistance",
"F1",
"F1Score",
"FBeta",
"FBetaScore",
"HammingDistance",
"Hinge",
"HingeLoss",
"JaccardIndex",
"KLDivergence",
"MatthewsCorrcoef",
"MatthewsCorrCoef",
"MaxMetric",
"MeanAbsoluteError",
Expand All @@ -141,7 +130,6 @@
"MinMetric",
"MultioutputWrapper",
"MultiScaleStructuralSimilarityIndexMeasure",
"PearsonCorrcoef",
"PearsonCorrCoef",
"PermutationInvariantTraining",
"Precision",
Expand All @@ -163,7 +151,6 @@
"ScaleInvariantSignalDistortionRatio",
"ScaleInvariantSignalNoiseRatio",
"SignalNoiseRatio",
"SpearmanCorrcoef",
"SpearmanCorrCoef",
"Specificity",
"SQuAD",
Expand Down
7 changes: 3 additions & 4 deletions torchmetrics/classification/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
from torchmetrics.classification.calibration_error import CalibrationError # noqa: F401
from torchmetrics.classification.cohen_kappa import CohenKappa # noqa: F401
from torchmetrics.classification.confusion_matrix import ConfusionMatrix # noqa: F401
from torchmetrics.classification.f_beta import F1, F1Score, FBeta, FBetaScore # noqa: F401
from torchmetrics.classification.f_beta import F1Score, FBetaScore # noqa: F401
from torchmetrics.classification.hamming import HammingDistance # noqa: F401
from torchmetrics.classification.hinge import Hinge, HingeLoss # noqa: F401
from torchmetrics.classification.iou import IoU # noqa: F401
from torchmetrics.classification.hinge import HingeLoss # noqa: F401
from torchmetrics.classification.jaccard import JaccardIndex # noqa: F401
from torchmetrics.classification.kl_divergence import KLDivergence # noqa: F401
from torchmetrics.classification.matthews_corrcoef import MatthewsCorrCoef, MatthewsCorrcoef # noqa: F401
from torchmetrics.classification.matthews_corrcoef import MatthewsCorrCoef # noqa: F401
from torchmetrics.classification.precision_recall import Precision, Recall # noqa: F401
from torchmetrics.classification.precision_recall_curve import PrecisionRecallCurve # noqa: F401
from torchmetrics.classification.roc import ROC # noqa: F401
Expand Down
92 changes: 0 additions & 92 deletions torchmetrics/classification/f_beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
from typing import Any, Callable, Optional

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

from torchmetrics.classification.stat_scores import StatScores
from torchmetrics.functional.classification.f_beta import _fbeta_compute
from torchmetrics.utilities import _future_warning
from torchmetrics.utilities.enums import AverageMethod


Expand Down Expand Up @@ -176,51 +174,6 @@ def compute(self) -> Tensor:
return _fbeta_compute(tp, fp, tn, fn, self.beta, self.ignore_index, self.average, self.mdmc_reduce)


class FBeta(FBetaScore):
r"""
Computes `F-score`_, specifically:

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

Example::
>>> f_beta = FBetaScore(num_classes=3, beta=0.5)
>>> f_beta(torch.tensor([0, 2, 1, 0, 0, 1]), torch.tensor([0, 1, 2, 0, 1, 2]))
tensor(0.3333)
"""

@deprecated(target=FBetaScore, deprecated_in="0.7", remove_in="0.8", stream=_future_warning)
def __init__(
self,
num_classes: Optional[int] = None,
beta: float = 1.0,
threshold: float = 0.5,
average: str = "micro",
mdmc_average: Optional[str] = None,
ignore_index: Optional[int] = None,
top_k: Optional[int] = None,
multiclass: Optional[bool] = None,
compute_on_step: bool = True,
dist_sync_on_step: bool = False,
process_group: Optional[Any] = None,
dist_sync_fn: Callable = None,
) -> None:
void(
num_classes,
beta,
threshold,
average,
mdmc_average,
ignore_index,
top_k,
multiclass,
compute_on_step,
dist_sync_on_step,
process_group,
dist_sync_fn,
)


class F1Score(FBetaScore):
"""Computes F1 metric. F1 metrics correspond to a harmonic mean of the precision and recall scores.

Expand Down Expand Up @@ -347,48 +300,3 @@ def __init__(
process_group=process_group,
dist_sync_fn=dist_sync_fn,
)


class F1(F1Score):
"""Computes F1 metric. F1 metrics correspond to a harmonic mean of the precision and recall scores.

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

Example:
>>> from torchmetrics import F1
>>> target = torch.tensor([0, 1, 2, 0, 1, 2])
>>> preds = torch.tensor([0, 2, 1, 0, 0, 1])
>>> f1 = F1(num_classes=3)
>>> f1(preds, target)
tensor(0.3333)
"""

@deprecated(target=F1Score, deprecated_in="0.7", remove_in="0.8", stream=_future_warning)
def __init__(
self,
num_classes: Optional[int] = None,
threshold: float = 0.5,
average: str = "micro",
mdmc_average: Optional[str] = None,
ignore_index: Optional[int] = None,
top_k: Optional[int] = None,
multiclass: Optional[bool] = None,
compute_on_step: bool = True,
dist_sync_on_step: bool = False,
process_group: Optional[Any] = None,
dist_sync_fn: Callable = None,
) -> None:
void(
num_classes,
threshold,
average,
mdmc_average,
ignore_index,
top_k,
multiclass,
compute_on_step,
dist_sync_on_step,
process_group,
dist_sync_fn,
)
40 changes: 0 additions & 40 deletions torchmetrics/classification/hinge.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, Optional, Union

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

from torchmetrics.functional.classification.hinge import MulticlassMode, _hinge_compute, _hinge_update
from torchmetrics.metric import Metric
from torchmetrics.utilities import _future_warning


class HingeLoss(Metric):
Expand Down Expand Up @@ -128,41 +126,3 @@ def update(self, preds: Tensor, target: Tensor) -> None: # type: ignore

def compute(self) -> Tensor:
return _hinge_compute(self.measure, self.total)


class Hinge(HingeLoss):
r"""
Computes the mean `Hinge loss`_, typically used for Support Vector Machines (SVMs).

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

Example (binary case):
>>> import torch
>>> hinge = Hinge()
>>> hinge(torch.tensor([-2.2, 2.4, 0.1]), torch.tensor([0, 1, 1]))
tensor(0.3000)

Example (default / multiclass case):
>>> hinge = Hinge()
>>> hinge(torch.tensor([[-1.0, 0.9, 0.2], [0.5, -1.1, 0.8], [2.2, -0.5, 0.3]]), torch.tensor([0, 1, 2]))
tensor(2.9000)

Example (multiclass example, one vs all mode):
>>> hinge = Hinge(multiclass_mode="one-vs-all")
>>> hinge(torch.tensor([[-1.0, 0.9, 0.2], [0.5, -1.1, 0.8], [2.2, -0.5, 0.3]]), torch.tensor([0, 1, 2]))
tensor([2.2333, 1.5000, 1.2333])

"""

@deprecated(target=HingeLoss, deprecated_in="0.7", remove_in="0.8", stream=_future_warning)
def __init__(
self,
squared: bool = False,
multiclass_mode: Optional[Union[str, MulticlassMode]] = None,
compute_on_step: bool = True,
dist_sync_on_step: bool = False,
process_group: Optional[Any] = None,
dist_sync_fn: Callable = None,
) -> None:
void(squared, multiclass_mode, compute_on_step, dist_sync_on_step, process_group, dist_sync_fn)
62 changes: 0 additions & 62 deletions torchmetrics/classification/iou.py

This file was deleted.

28 changes: 0 additions & 28 deletions torchmetrics/classification/matthews_corrcoef.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
from typing import Any, Callable, Optional

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

from torchmetrics.functional.classification.matthews_corrcoef import (
_matthews_corrcoef_compute,
_matthews_corrcoef_update,
)
from torchmetrics.metric import Metric
from torchmetrics.utilities import _future_warning


class MatthewsCorrCoef(Metric):
Expand Down Expand Up @@ -112,29 +110,3 @@ def update(self, preds: Tensor, target: Tensor) -> None: # type: ignore
def compute(self) -> Tensor:
"""Computes matthews correlation coefficient."""
return _matthews_corrcoef_compute(self.confmat)


class MatthewsCorrcoef(MatthewsCorrCoef):
"""Calculates `Matthews correlation coefficient`_ that measures the general correlation or quality of a
classification.

Example:
>>> matthews_corrcoef = MatthewsCorrcoef(num_classes=2)
>>> matthews_corrcoef(torch.tensor([0, 1, 0, 0]), torch.tensor([1, 1, 0, 0]))
tensor(0.5774)

.. deprecated:: v0.7
Renamed in favor of :class:`torchmetrics.MatthewsCorrCoef`. Will be removed in v0.8.
"""

@deprecated(target=MatthewsCorrCoef, deprecated_in="0.7", remove_in="0.8", stream=_future_warning)
def __init__(
self,
num_classes: int,
threshold: float = 0.5,
compute_on_step: bool = True,
dist_sync_on_step: bool = False,
process_group: Optional[Any] = None,
dist_sync_fn: Callable = None,
) -> None:
void(num_classes, threshold, compute_on_step, dist_sync_on_step, process_group, dist_sync_fn)
Loading