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

intersection_over_union error #2534

Closed
bennymi opened this issue May 10, 2024 · 2 comments · Fixed by #2577
Closed

intersection_over_union error #2534

bennymi opened this issue May 10, 2024 · 2 comments · Fixed by #2577
Labels
bug / fix Something isn't working help wanted Extra attention is needed v1.2.x
Milestone

Comments

@bennymi
Copy link

bennymi commented May 10, 2024

🐛 Bug

Trying to copy over the Jaccard Index example to use with the functional IoU, results in the following error:

RuntimeError: The size of tensor a (23) must match the size of tensor b (2) at non-singleton dimension 2

To Reproduce

Steps to reproduce the behavior...

from torchmetrics.functional.detection import intersection_over_union
import torch

target = torch.randint(0, 2, (10, 25, 25))
preds = torch.tensor(target)
preds[2:5, 7:13, 9:15] = 1 - preds[2:5, 7:13, 9:15]

intersection_over_union(preds=preds[2], target=target[2])

Expected behavior

Expecting to get the same prediction as in the Jaccard Index example.

Environment

  • TorchMetrics version (and how you installed TM, e.g. conda, pip, build from source):
    • installed with pip: torchmetrics 1.2.1
  • Python & PyTorch Version (e.g., 1.0):
    • Python 3.11.6 + PyTorch 2.1.0
  • Any other relevant information such as OS (e.g., Linux):
    • Windows 10
@bennymi bennymi added bug / fix Something isn't working help wanted Extra attention is needed labels May 10, 2024
Copy link

Hi! thanks for your contribution!, great first issue!

@SkafteNicki
Copy link
Member

Hi @bennymi, thanks for raising this issue.
If you look at the documentation for the functional interface of intersection_over_union you will see that the input for this metric is expected to be bounding box coordinates and not raw predicted labels. The difference in expected input is one reason why this metric is not in the classification domain but instead in the detection domain.
PR #2577 will add better error messages when trying to use the metric.

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 help wanted Extra attention is needed v1.2.x
Projects
None yet
3 participants