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

MeanAveragePrecision.tm_to_coco example fails with IndexError: list index out of range #2587

Closed
robmarkcole opened this issue Jun 4, 2024 · 1 comment · Fixed by #2588
Closed
Labels
bug / fix Something isn't working help wanted Extra attention is needed

Comments

@robmarkcole
Copy link

🐛 Bug

There appears to be a bug, the example doesn't include masks but this is raised

To Reproduce

Run the example from the docs

from torch import tensor
from torchmetrics.detection import MeanAveragePrecision
preds = [
  dict(
    boxes=tensor([[258.0, 41.0, 606.0, 285.0]]),
    scores=tensor([0.536]),
    labels=tensor([0]),
  )
]
target = [
  dict(
    boxes=tensor([[214.0, 41.0, 562.0, 285.0]]),
    labels=tensor([0]),
  )
]
metric = MeanAveragePrecision()
metric.update(preds, target)
metric.tm_to_coco("tm_map_input")  

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
[<ipython-input-2-d5b2db9d9305>](https://localhost:8080/#) in <cell line: 18>()
     16 metric = MeanAveragePrecision()
     17 metric.update(preds, target)
---> 18 metric.tm_to_coco("tm_map_input")

1 frames
[/usr/local/lib/python3.10/dist-packages/torchmetrics/detection/mean_ap.py](https://localhost:8080/#) in _get_coco_format(self, labels, boxes, masks, scores, crowds, area)
    865                 image_boxes = image_boxes.cpu().tolist()
    866             if masks is not None:
--> 867                 image_masks = masks[image_id]
    868                 if len(image_masks) == 0 and boxes is None:
    869                     continue

IndexError: list index out of range

Expected behavior

A pair of json are written

Environment

  • TorchMetrics version 1.4.0.post0
  • Fresh Google colab

Additional context

NA

@robmarkcole robmarkcole added bug / fix Something isn't working help wanted Extra attention is needed labels Jun 4, 2024
@Borda Borda changed the title MeanAveragePrecision.tm_to_coco example fails with IndexError: list index out of range MeanAveragePrecision.tm_to_coco example fails with IndexError: list index out of range Jun 4, 2024
@robmarkcole
Copy link
Author

Excellent, tested and the files are now generated

image

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