Skip to content

Commit

Permalink
Reorder auc only when needed (#91)
Browse files Browse the repository at this point in the history
* reorder fpr array when needed

* add todo for adding stable sort after pytorch upgrade

* mypy

* set black version to match precommit
  • Loading branch information
djdameln authored Feb 3, 2022
1 parent 18ce474 commit d5bc8b0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions anomalib/core/metrics/auroc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Implementation of AUROC metric based on TorchMetrics."""
import torch
from torch import Tensor
from torchmetrics import ROC
from torchmetrics.functional import auc
Expand All @@ -13,5 +14,11 @@ def compute(self) -> Tensor:
Returns:
Value of the AUROC metric
"""
tpr: Tensor
fpr: Tensor

fpr, tpr, _thresholds = super().compute()
# TODO: use stable sort after upgrading to pytorch 1.9.x (https://github.com/openvinotoolkit/anomalib/issues/92)
if not (torch.all(fpr.diff() <= 0) or torch.all(fpr.diff() >= 0)):
return auc(fpr, tpr, reorder=True) # only reorder if fpr is not increasing or decreasing
return auc(fpr, tpr)

0 comments on commit d5bc8b0

Please sign in to comment.