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] Fix the bug of large seg map IoU calculation #534

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[fix] Fix calculation error when tensor contains value larger than nu…
…m_classes - 1.
  • Loading branch information
sennnnn committed May 8, 2021
commit 7bfc804cf512aced813eec9838cb8330def021a6
10 changes: 10 additions & 0 deletions mmseg/core/evaluation/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,21 @@ def intersect_and_union(pred_label,
label = label - 1
label[label == 254] = 255

# Remove ignore_index related pixelx.
mask = (label != ignore_index)
pred_label = pred_label[mask]
label = label[mask]

intersect = pred_label[pred_label == label]

# Remove those pixels which have larger value than num_classes - 1.
# Those pixels will cause error when use `torch.bincount`, because
# `torch.bincount` can only restrict min length of count vector and
# can't restrict max length of count vector.
pred_label = pred_label[pred_label < num_classes]
label = label[label < num_classes]
intersect = intersect[intersect < num_classes]

area_intersect = torch.bincount(intersect, minlength=num_classes)
area_pred_label = torch.bincount(pred_label, minlength=num_classes)
area_label = torch.bincount(label, minlength=num_classes)
Expand Down