torchmetrics icon indicating copy to clipboard operation
torchmetrics copied to clipboard

AUROC reported wrong value when called differently

Open SinChee opened this issue 2 years ago • 3 comments

🐛 Bug

AUROC calculation is different when being called differently.

To Reproduce

Copy the following code and run.

Note that when .update() is called, values that are greater than 1.0 will be scaled using the sigmoid activation, values that is less than 1.0 will not be scaled. This result in the compute step to compute with the wrong input values. However, directly calling the auroc will not rescale the value

from torchmetrics import AUROC
from torch import tensor

pp = tensor([tensor([1.2]), tensor([0.9678]), tensor([1.7])])
tt = tensor([tensor([1]), tensor([0]), tensor([1])])

auroc = AUROC(num_classes=1, task="binary")
print("Forward:", auroc(pp, tt))


for p, t in zip(pp, tt):
    auroc.update(p, t)
    print(auroc.preds, auroc.target)

print("Update and Compute:", auroc.compute())

Expected behavior

The reported AUROC metrics for both cases should be the same.

Environment

  • TorchMetrics 1.0.3
  • Python 3.9.16
  • PyTorch 1.13.1

SinChee avatar Aug 09 '23 03:08 SinChee

Hi! thanks for your contribution!, great first issue!

github-actions[bot] avatar Aug 09 '23 03:08 github-actions[bot]