-
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 all commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,8 +2,9 @@ | |||||
| # 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 | ||||||
|
|
@@ -54,12 +55,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 ensures correctness for lower precisions. | ||||||
| # 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.