-
Notifications
You must be signed in to change notification settings - Fork 1
fix: optimal threshold computation #32
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| [tool.poetry] | ||
| name = "anomalib-orobix" | ||
| version = "0.7.0.dev150" | ||
| version = "0.7.0.dev151" | ||
| description = "Orobix anomalib fork" | ||
| authors = [ | ||
| "Intel OpenVINO <[email protected]>", | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,12 +2,14 @@ | |||||
| # SPDX-License-Identifier: Apache-2.0 | ||||||
|
|
||||||
| """Implementation of Optimal F1 score based on TorchMetrics.""" | ||||||
| from typing import Optional | ||||||
|
|
||||||
| import warnings | ||||||
| from typing import Optional | ||||||
|
|
||||||
| import torch | ||||||
| from torch import Tensor | ||||||
| from torchmetrics import Metric, PrecisionRecallCurve | ||||||
| from zmq import device | ||||||
michele-milesi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
|
|
||||||
| class OptimalF1(Metric): | ||||||
|
|
@@ -54,12 +56,21 @@ def compute(self) -> Tensor: | |||||
|
|
||||||
| epsilon = 1e-3 | ||||||
| if len(current_targets.unique()) == 1: | ||||||
| # Use torch nextafter to ensure that the threshold is higher (or smaller) | ||||||
| # than the maximum (or minimum) score. This ensure correctness for lower precisions. | ||||||
michele-milesi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| # Combined method is to avoid very small shifts around zero. | ||||||
| _inf = torch.tensor(torch.inf, dtype=current_preds.dtype, device=current_preds.device) | ||||||
| optimal_f1_score = torch.tensor(1.0) | ||||||
|
||||||
| optimal_f1_score = torch.tensor(1.0) | |
| optimal_f1_score = torch.tensor(1.0, dtype=current_preds.dtype, device=current_preds.device) |
Uh oh!
There was an error while loading. Please reload this page.