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

Fix: JaccardIndex multi-label compute #1125

Merged
merged 4 commits into from
Jul 10, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/torchmetrics/classification/jaccard.py
Expand Up @@ -104,10 +104,25 @@ def __init__(

def compute(self) -> Tensor:
"""Computes intersection over union (IoU)"""
return _jaccard_from_confmat(
self.confmat,
self.num_classes,
self.average,
self.ignore_index,
self.absent_score,
)

if self.multilabel:
return torch.stack(
[
_jaccard_from_confmat(
confmat,
2,
self.average,
self.ignore_index,
self.absent_score,
)[1]
for confmat in self.confmat
]
)
else:
return _jaccard_from_confmat(
self.confmat,
self.num_classes,
self.average,
self.ignore_index,
self.absent_score,
)