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

Result of IoU is Nan when there is empty item in preds. #2778

Closed
joshuasv opened this issue Oct 14, 2024 · 1 comment · Fixed by #2780
Closed

Result of IoU is Nan when there is empty item in preds. #2778

joshuasv opened this issue Oct 14, 2024 · 1 comment · Fixed by #2780
Labels
bug / fix Something isn't working help wanted Extra attention is needed

Comments

@joshuasv
Copy link

🐛 Bug

To Reproduce

The target is:

[
 {'boxes': tensor([[  8.0000,  70.0000,  76.0000, 110.0000],
                   [247.0000, 131.0000, 315.0000, 175.0000],
                   [361.0000, 177.0000, 395.0000, 203.0000]]), 'labels': tensor([0, 0, 0])}
]

The preds is:

[
{'boxes': empty(size=(0, 4)), 'labels': tensor([], dtype=torch.int64), 'scores': tensor([])}
]

The last item of preds is empty, when using torchmetrics.detection.iou.IntersectionOverUnion to calculate IoU, the result is nan.

Code sample
import torch
from torch import tensor
from torch import empty
from torchmetrics.detection import IntersectionOverUnion

def calc_iou(preds: list, target: list):
    metric = IntersectionOverUnion()
    metric.update(preds, target)
    result = metric.compute()
    return result

target = [
 {'boxes': tensor([[  8.0000,  70.0000,  76.0000, 110.0000],
                   [247.0000, 131.0000, 315.0000, 175.0000],
                   [361.0000, 177.0000, 395.0000, 203.0000]]), 'labels': tensor([0, 0, 0])}
]
preds = [
{'boxes': empty(size=(0, 4)), 'labels': tensor([], dtype=torch.int64), 'scores': tensor([])}
]

calc_iou(preds, target)
{'iou': tensor(nan)}

Expected behavior

A correct iou value, i.e: 0.0

Environment

  • TorchMetrics version (if build from source, add commit SHA): torchmetrics==1.4.0.post0
  • Python & PyTorch Version (e.g., 1.0): Python 3.11.9 & torch==2.3.1+cpu
  • Any other relevant information such as OS (e.g., Linux): Ubuntu 22.04.5 LTS

Additional context

@joshuasv joshuasv added bug / fix Something isn't working help wanted Extra attention is needed labels Oct 14, 2024
Copy link

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

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant