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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

off-by-one in MultiClassJaccard ignore_index handling #1861

Closed
martinmeinke opened this issue Jun 27, 2023 · 1 comment 路 Fixed by #1860
Closed

off-by-one in MultiClassJaccard ignore_index handling #1861

martinmeinke opened this issue Jun 27, 2023 · 1 comment 路 Fixed by #1860
Labels
bug / fix Something isn't working help wanted Extra attention is needed

Comments

@martinmeinke
Copy link
Contributor

馃悰 Bug

I believe the bugfix #1386 introduced aother bug when computing MulticlassJaccardIndex.

This bug appears when num_classes == ignore_index.

To Reproduce

Code sample
import torch
from torchmetrics.classification import MulticlassJaccardIndex
target = torch.tensor([2, 1, 0, 0])
preds = torch.tensor([2, 1, 0, 1])
metric = MulticlassJaccardIndex(num_classes=3, ignore_index=3)
metric(preds, target)
print(metric.confmat)
print(metric.compute())

results in:

IndexError: index 3 is out of bounds for dimension 0 with size 3

Expected behavior

setting ignore_index == num_classes should work

Environment

pip show torchmetrics
Name: torchmetrics
Version: 0.11.4

Fix: https://github.com/Lightning-AI/torchmetrics/pull/1860/files

@martinmeinke martinmeinke added bug / fix Something isn't working help wanted Extra attention is needed labels Jun 27, 2023
@github-actions
Copy link

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

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant