-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
IoU metric returns 0 score for classes not present in prediction or target #3097
Labels
Comments
abrahambotros
added
bug
Something isn't working
help wanted
Open to be worked on
labels
Aug 21, 2020
Hi! thanks for your contribution!, great first issue! |
abrahambotros
added a commit
to abrahambotros/pytorch-lightning
that referenced
this issue
Aug 21, 2020
Fixes Lightning-AI#3097 - Allow configurable not_present_score for IoU for classes not present in target or pred. Defaults to 1.0. - Also allow passing `num_classes` parameter through from iou metric class down to its underlying functional iou call.
abrahambotros
added a commit
to abrahambotros/pytorch-lightning
that referenced
this issue
Aug 21, 2020
Fixes Lightning-AI#3097 - Allow configurable not_present_score for IoU for classes not present in target or pred. Defaults to 1.0. - Also allow passing `num_classes` parameter through from iou metric class down to its underlying functional iou call.
7 tasks
abrahambotros
added a commit
to abrahambotros/pytorch-lightning
that referenced
this issue
Sep 1, 2020
Fixes Lightning-AI#3097 - Allow configurable not_present_score for IoU for classes not present in target or pred. Defaults to 1.0. - Also allow passing `num_classes` parameter through from iou metric class down to its underlying functional iou call.
abrahambotros
added a commit
to abrahambotros/pytorch-lightning
that referenced
this issue
Sep 1, 2020
Fixes Lightning-AI#3097 - Allow configurable not_present_score for IoU for classes not present in target or pred. Defaults to 1.0. - Also allow passing `num_classes` parameter through from iou metric class down to its underlying functional iou call.
abrahambotros
added a commit
to abrahambotros/pytorch-lightning
that referenced
this issue
Sep 4, 2020
Fixes Lightning-AI#3097 - Allow configurable not_present_score for IoU for classes not present in target or pred. Defaults to 1.0. - Also allow passing `num_classes` parameter through from iou metric class down to its underlying functional iou call.
Borda
pushed a commit
to abrahambotros/pytorch-lightning
that referenced
this issue
Sep 4, 2020
Fixes Lightning-AI#3097 - Allow configurable not_present_score for IoU for classes not present in target or pred. Defaults to 1.0. - Also allow passing `num_classes` parameter through from iou metric class down to its underlying functional iou call.
abrahambotros
added a commit
to abrahambotros/pytorch-lightning
that referenced
this issue
Sep 8, 2020
Fixes Lightning-AI#3097 - Allow configurable not_present_score for IoU for classes not present in target or pred. Defaults to 1.0. - Also allow passing `num_classes` parameter through from iou metric class down to its underlying functional iou call.
abrahambotros
added a commit
to abrahambotros/pytorch-lightning
that referenced
this issue
Sep 14, 2020
Fixes Lightning-AI#3097 - Allow configurable not_present_score for IoU for classes not present in target or pred. Defaults to 1.0. - Also allow passing `num_classes` parameter through from iou metric class down to its underlying functional iou call.
abrahambotros
added a commit
to abrahambotros/pytorch-lightning
that referenced
this issue
Sep 15, 2020
Fixes Lightning-AI#3097 - Allow configurable not_present_score for IoU for classes not present in target or pred. Defaults to 1.0. - Also allow passing `num_classes` parameter through from iou metric class down to its underlying functional iou call.
Borda
pushed a commit
that referenced
this issue
Sep 17, 2020
* Fix IoU score for classes not present in target or pred Fixes #3097 - Allow configurable not_present_score for IoU for classes not present in target or pred. Defaults to 1.0. - Also allow passing `num_classes` parameter through from iou metric class down to its underlying functional iou call. * Changelog: move IoU not-present score fix to [unreleased] * IoU: avoid recomputing class presence in target and pred Use already-computed support, true positives, and false positives to determine if a class is not present in either target or pred. * Test IoU against sklearn jaccard_score Also add TODO to test our IoU's not_present_score against sklearn's jaccard_score's zero_division when it beecomes available. * IoU: remove_bg -> ignore_index Fixes #2736 - Rename IoU metric argument from `remove_bg` -> `ignore_index`. - Accept an optional int class index to ignore, instead of a bool and instead of always assuming the background class has index 0. - If given, ignore the class index when computing the IoU output, regardless of reduction method. * Improve documentation for IoU not_present_score * Update default IoU not_present_score to 0.0 * Add note about IoU division by zero * Rename IoU not_present_score -> absent_score * Update IoU absent score changelog wording * Condense IoU absent_score argument docstring * Remove unnecessary IoU ignore_index comment * docstrings * isort * flake8 * Fix test of IoU against sklearn jaccard Use macro instead of micro averaging in sklearn's jaccard score, to match multi-class IoU, which conventionally takes per-class scores before averaging. Co-authored-by: rohitgr7 <rohitgr1998@gmail.com>
2 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
🐛 Bug
The
iou
metric implementation always returns a score of 0 for a class that is not present in either the prediction or the target. This can lead to a deflated score even for perfectly-predicted examples.Case 1: one example of an affected case is multi-class semantic segmentation of an image that does not contain one of the classes. This can be outlined as follows:
Case 2: another example that is a bit more implementation-dependent to explain:
Case 3: All the above are also affected by any
num_classes
parameter passed to the functionaliou
implementation - ifnum_classes=N
is given, then all classes with ids<N
that did not appear in the target or prediction will always be assigned 0 IoU score. For example, ifN=10
, and only classes 0 and 1 are present and correct in target and prediction, then classes 2-9 will all have IoU score 0.0.Especially in aggregate for a dataset with substantial neutral ground-truth values (i.e., semantic segmentation dataset with lots of images where not all classes are present), this can significantly deflate the (m)IoU score(s). This can also undesirably interact with checkpointing that looks at IoU-based metrics.
To Reproduce / Code sample
Case 1 above:
Case 2 above:
Case 3 above:
Expected behavior
The fallback IoU score to use for classes not in the target and correctly not in the prediction should be configurable. This should probably default to 1.0, which seems more expected behavior to me.
Case 1:
Case 2:
Case 3:
Environment
Additional context
I have a draft PR open at #3098 that attempts to implement the expected behavior described above, and adds some tests for this. Any feedback welcome!
Somewhat-related issues:
ignore_index
instead ofremove_bg
for IoU #2736The text was updated successfully, but these errors were encountered: