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: handle zero division error in binary IoU calculation #2726

Merged

Conversation

rittik9
Copy link
Contributor

@rittik9 rittik9 commented Sep 9, 2024

…tion

What does this PR do?

Fixes #2658

Before submitting
  • Was this discussed/agreed via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?

Did you have fun?

Yes

Issue:

zero_division does not work for binary IoU (Jaccard index) calculation and returns NaN when TP + FP + FN=0.

Reason:

The zero_division parameter in the BinaryJaccardIndex does not take effect during binary task calculations, as the IoU calculations for the binary task are returned early (Line 70) in _jaccard_index_reduce function.

Fix:

The change replaces the direct division operation with a call to the _safe_divide function, which handles the case of division by zero based on the specified zero_division parameter in _jaccard_index_reduce function.


📚 Documentation preview 📚: https://torchmetrics--2726.org.readthedocs.build/en/2726/

@Borda Borda changed the title Fix: Handle zero division error in binary IoU (Jaccard index) calcula… Fix: handle zero division error in binary IoU calculation Sep 9, 2024
@Borda Borda added the bug / fix Something isn't working label Sep 9, 2024
@mergify mergify bot added the has conflicts label Sep 9, 2024
@mergify mergify bot removed the has conflicts label Sep 9, 2024
Copy link

codecov bot commented Sep 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 41%. Comparing base (eecc55b) to head (31087e3).
Report is 92 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (eecc55b) and HEAD (31087e3). Click for more details.

HEAD has 4 uploads less than BASE
Flag BASE (eecc55b) HEAD (31087e3)
gpu 2 0
unittest 2 0
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #2726     +/-   ##
========================================
- Coverage      69%     41%    -28%     
========================================
  Files         329     316     -13     
  Lines       18065   17901    -164     
========================================
- Hits        12491    7329   -5162     
- Misses       5574   10572   +4998     

@mergify mergify bot added the ready label Sep 10, 2024
@Borda Borda merged commit 80929b5 into Lightning-AI:master Sep 10, 2024
49 of 57 checks passed
Borda pushed a commit that referenced this pull request Sep 11, 2024
* Fix: Handle zero division error in binary IoU (Jaccard index) calculation
* chlog

---------

Co-authored-by: Jirka Borovec <[email protected]>
(cherry picked from commit 80929b5)
Borda pushed a commit that referenced this pull request Sep 13, 2024
* Fix: Handle zero division error in binary IoU (Jaccard index) calculation
* chlog

---------

Co-authored-by: Jirka Borovec <[email protected]>
(cherry picked from commit 80929b5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zero_division does not work for binary IoU (Jaccard index) calculation and returns NaN
3 participants