Skip to content

fix Detection IoU ignores predictions without ground truth#3025

Merged
SkafteNicki merged 9 commits into
Lightning-AI:masterfrom
Isalia20:box-iou-no-ignore-preds-without-gt
Mar 31, 2025
Merged

fix Detection IoU ignores predictions without ground truth#3025
SkafteNicki merged 9 commits into
Lightning-AI:masterfrom
Isalia20:box-iou-no-ignore-preds-without-gt

Conversation

@Isalia20

@Isalia20 Isalia20 commented Mar 23, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #2905

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?

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

@Isalia20 Isalia20 changed the title fix issue fix Detection IoU ignores predictions without ground truth Mar 23, 2025
@codecov

codecov Bot commented Mar 23, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 35%. Comparing base (2c28e25) to head (44d0712).
Report is 76 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (2c28e25) and HEAD (44d0712). Click for more details.

HEAD has 458 uploads less than BASE
Flag BASE (2c28e25) HEAD (44d0712)
macOS 27 1
cpu 117 4
python3.12 21 1
torch2.6.0 7 0
python3.10 63 2
torch2.0.1 14 1
torch2.0.1+cpu 21 1
Windows 20 3
torch2.7.0+cpu 13 1
python3.11 26 1
torch2.6.0+cpu 7 1
torch2.7.0 6 0
Linux 70 0
torch2.4.1+cpu 14 0
torch2.5.0+cpu 14 0
torch2.3.1+cpu 7 0
torch2.1.2+cpu 7 0
python3.9 7 0
torch2.2.2+cpu 7 0
gpu 3 0
unittest 3 0
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #3025     +/-   ##
========================================
- Coverage      70%     35%    -35%     
========================================
  Files         355     341     -14     
  Lines       19654   19475    -179     
========================================
- Hits        13775    6908   -6867     
- Misses       5879   12567   +6688     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Isalia20

Copy link
Copy Markdown
Contributor Author

Ready for review, errors seem to be unrelated

@SkafteNicki SkafteNicki added the bug / fix Something isn't working label Mar 24, 2025
@SkafteNicki SkafteNicki added this to the v1.7.x milestone Mar 24, 2025

@SkafteNicki SkafteNicki left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, just a couple of suggestions/fixes

Comment thread CHANGELOG.md Outdated
Comment thread src/torchmetrics/detection/iou.py Outdated
Comment thread src/torchmetrics/detection/iou.py Outdated
Comment thread src/torchmetrics/detection/iou.py Outdated
Comment thread src/torchmetrics/detection/iou.py
Isalia20 and others added 5 commits March 24, 2025 19:39
Co-authored-by: Nicki Skafte Detlefsen <[email protected]>
Co-authored-by: Nicki Skafte Detlefsen <[email protected]>
Co-authored-by: Nicki Skafte Detlefsen <[email protected]>
Co-authored-by: Nicki Skafte Detlefsen <[email protected]>
Co-authored-by: Nicki Skafte Detlefsen <[email protected]>
@Isalia20

Isalia20 commented Mar 24, 2025

Copy link
Copy Markdown
Contributor Author

Applied the fixes from review, tests fail when installing PyTDC==0.4.1 :(

@Borda

Borda commented Mar 24, 2025

Copy link
Copy Markdown
Collaborator

Applied the fixes from review, tests fail when installing PyTDC==0.4.1 :(

will try to check it... 🤔

@Isalia20

Copy link
Copy Markdown
Contributor Author

Can this be reviewed? Tests seem to be green except for some errors about purging cache and not being able to connect to huggingface

@mergify mergify Bot added the ready label Mar 26, 2025
@Borda
Borda requested review from SkafteNicki and Copilot March 26, 2025 21:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes issue #2905 by adjusting how the IntersectionOverUnion metric handles predictions when no corresponding ground truth exists. Key changes include:

  • Updating state collection to include predicted labels in both the metric and test implementations.
  • Modifying the compute logic to calculate class-wise IoU using the union of ground truth and prediction labels.
  • Enhancing tests to validate the new behavior.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/unittests/detection/test_intersection.py Updated test helper to collect predicted labels and compute per-class metrics using union labels.
src/torchmetrics/detection/iou.py Updated state management and compute method to incorporate predictions without ground truth.
CHANGELOG.md Documented the fix for the IoU behavior issue.
Comments suppressed due to low confidence (1)

tests/unittests/detection/test_intersection.py:80

  • [nitpick] Consider renaming 'union_cls' to 'all_labels' to be consistent with the naming convention used in the metric implementation.
union_cls = set()

@SkafteNicki SkafteNicki left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@SkafteNicki
SkafteNicki merged commit 9e08ff2 into Lightning-AI:master Mar 31, 2025
Borda added a commit that referenced this pull request Apr 7, 2025
* chlog update + `1.8.0dev`

* fix issue

* Update CHANGELOG.md

Co-authored-by: Nicki Skafte Detlefsen <[email protected]>

* Update src/torchmetrics/detection/iou.py

Co-authored-by: Nicki Skafte Detlefsen <[email protected]>

* Update src/torchmetrics/detection/iou.py

Co-authored-by: Nicki Skafte Detlefsen <[email protected]>

* Update src/torchmetrics/detection/iou.py

Co-authored-by: Nicki Skafte Detlefsen <[email protected]>

* Update src/torchmetrics/detection/iou.py

Co-authored-by: Nicki Skafte Detlefsen <[email protected]>

---------

Co-authored-by: Jirka B <[email protected]>
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: Nicki Skafte Detlefsen <[email protected]>
(cherry picked from commit 9e08ff2)
Borda added a commit that referenced this pull request Apr 7, 2025
* chlog update + `1.8.0dev`

* fix issue

* Update CHANGELOG.md

Co-authored-by: Nicki Skafte Detlefsen <[email protected]>

* Update src/torchmetrics/detection/iou.py

Co-authored-by: Nicki Skafte Detlefsen <[email protected]>

* Update src/torchmetrics/detection/iou.py

Co-authored-by: Nicki Skafte Detlefsen <[email protected]>

* Update src/torchmetrics/detection/iou.py

Co-authored-by: Nicki Skafte Detlefsen <[email protected]>

* Update src/torchmetrics/detection/iou.py

Co-authored-by: Nicki Skafte Detlefsen <[email protected]>

---------

Co-authored-by: Jirka B <[email protected]>
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: Nicki Skafte Detlefsen <[email protected]>
(cherry picked from commit 9e08ff2)
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 ready topic: Detect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detection IoU ignores predictions without ground truth

4 participants