Skip to content
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

DiceScore(average="weighted") produces scores bigger than 1.0 #2851

Open
nkaenzig opened this issue Nov 29, 2024 · 0 comments · May be fixed by #2860
Open

DiceScore(average="weighted") produces scores bigger than 1.0 #2851

nkaenzig opened this issue Nov 29, 2024 · 0 comments · May be fixed by #2860
Assignees
Labels
bug / fix Something isn't working help wanted Extra attention is needed v1.6.x

Comments

@nkaenzig
Copy link
Contributor

🐛 Bug

Using average=weighted aggregation in the DiceScore produces scores bigger than 1.0, and therefore outside the expected value range of [0,1] for dice.

To Reproduce

The following code sample returns a score of 2.0:

Code sample
import torch
from torchmetrics.segmentation import DiceScore

N_SAMPLES = 4
N_CLASSES = 3

target = torch.full((N_SAMPLES, N_CLASSES, 128, 128), 0, dtype=torch.int8)
preds = torch.full((N_SAMPLES, N_CLASSES, 128, 128), 0, dtype=torch.int8)

target[0, 0], preds[0, 0] = 1, 1

dice = DiceScore(num_classes=3, average='weighted', include_background=False)

print(dice(preds, target))

Expected behavior

Environment

  • TorchMetrics version (if build from source, add commit SHA): 1.6.0
  • Python & PyTorch Version (e.g., 1.0): Python 3.11.10 & torch==2.3.0
  • Any other relevant information such as OS (e.g., Linux): macOS 15.1.1 (24B91)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug / fix Something isn't working help wanted Extra attention is needed v1.6.x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants