You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When calling the .plot(score=True) on curve metrics like BinaryPrecisionRecall, BinaryROC.... The AUC score is not shown.
To Reproduce
Steps to reproduce the behavior...
from torch import randn, randint
from torchmetrics.classification import BinaryPrecisionRecallCurve
import torch.nn.functional as F
preds = F.softmax(randn(20, 2), dim=1)
target = randint(2, (20,))
metric = BinaryPrecisionRecallCurve()
metric.update(preds[:, 1], target)
fig_, ax_ = metric.plot(score=True)
Code sample
Expected behavior
Expect a legend showing the AUC score.
Environment
TorchMetrics version (and how you installed TM, e.g. conda, pip, build from source): 1.01, from pip
Python & PyTorch Version (e.g., 1.0): torch 1.13, python 3.10.11
Any other relevant information such as OS (e.g., Linux): Linux
Additional context
The bug seems be due to the score is computed when curve is None and score is True, however curve is computed before this expression, so curve is always not None and score will never be computed, here is an example of BinaryROC:
# line 156-164 in src/torchmetrics/classification/roc.py
curve = curve or self.compute()
score = _auc_compute_without_check(curve[0], curve[1], 1.0) if not curve and score is True else None
return plot_curve(
curve,
score=score,
ax=ax,
label_names=("False positive rate", "True positive rate"),
name=self.__class__.__name__,
)
it works as expected after changing it to:
curve_computed = curve or self.compute()
score = _auc_compute_without_check(curve_computed[0], curve_computed[1], 1.0) if not curve and score is True else None
return plot_curve(
curve_computed,
score=score,
ax=ax,
label_names=("False positive rate", "True positive rate"),
name=self.__class__.__name__,
)
The text was updated successfully, but these errors were encountered:
🐛 Bug
When calling the
.plot(score=True)
on curve metrics like BinaryPrecisionRecall, BinaryROC.... The AUC score is not shown.To Reproduce
Steps to reproduce the behavior...
Code sample
Expected behavior
Expect a legend showing the AUC score.
Environment
conda
,pip
, build from source): 1.01, from pipAdditional context
The bug seems be due to the score is computed when
curve is None and score is True
, howevercurve
is computed before this expression, socurve
is always not None andscore
will never be computed, here is an example of BinaryROC:it works as expected after changing it to:
The text was updated successfully, but these errors were encountered: