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 (map) returns -1.0 if max_detection_thresholds is changed #1153

Closed
marckatzenmaier opened this issue Jul 20, 2022 · 7 comments · Fixed by #2034
Closed
Assignees
Labels
bug / fix Something isn't working help wanted Extra attention is needed v0.9.x
Milestone

Comments

@marckatzenmaier
Copy link

marckatzenmaier commented Jul 20, 2022

🐛 Bug

I found a bug when changing the max_detection_thresholds of MeanAveragePrecision to a large number e.g. [1, 10, 1000] the result of the map calculation becomes -1.0
I wanted to increase the number of detections per image since my data has up to several thousand instances per image. I detected that the same problem occurs with the example given in the class definition.

To Reproduce

Run the example from the function definition with max_detection_thresholds=[1, 10, 1000] instead of the default [1, 10, 100].

Code sample

import torch
from torchmetrics.detection.mean_ap import MeanAveragePrecision
preds = [dict(
              boxes = torch.tensor([[258.0, 41.0, 606.0, 285.0]]),
              scores = torch.tensor([0.536]),
              labels = torch.tensor([0]),
             )]
target = [dict(
               boxes = torch.tensor([[214.0, 41.0, 562.0, 285.0]]),
               labels = torch.tensor([0]),
             )]
metric = MeanAveragePrecision(max_detection_thresholds=[1, 10, 1000])
metric.update(preds, target)
from pprint import pprint
pprint(metric.compute())

Output:

{'map': tensor(-1.),
 'map_50': tensor(1.),
 'map_75': tensor(1.),
 'map_large': tensor(0.6000),
 'map_medium': tensor(-1.),
 'map_per_class': tensor(-1.),
 'map_small': tensor(-1.),
 'mar_1': tensor(0.6000),
 'mar_10': tensor(0.6000),
 'mar_1000': tensor(0.6000),
 'mar_1000_per_class': tensor(-1.),
 'mar_large': tensor(0.6000),
 'mar_medium': tensor(-1.),
 'mar_small': tensor(-1.)}

Expected behavior

Get the same output as with [1, 10, 100]:

{'map': tensor(0.6000),
 'map_50': tensor(1.),
 'map_75': tensor(1.),
 'map_large': tensor(0.6000),
 'map_medium': tensor(-1.),
 'map_per_class': tensor(-1.),
 'map_small': tensor(-1.),
 'mar_1': tensor(0.6000),
 'mar_10': tensor(0.6000),
 'mar_100': tensor(0.6000),
 'mar_100_per_class': tensor(-1.),
 'mar_large': tensor(0.6000),
 'mar_medium': tensor(-1.),
 'mar_small': tensor(-1.)}

Environment

  • python 3.9
  • pytorch: 1.10
  • TorchMetrics: 0.9.0

Thanks for your help.

@marckatzenmaier marckatzenmaier added bug / fix Something isn't working help wanted Extra attention is needed labels Jul 20, 2022
@github-actions
Copy link

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

@Borda Borda added this to the v0.9 milestone Jul 27, 2022
@SkafteNicki SkafteNicki modified the milestones: v0.9, v0.11 Sep 16, 2022
@Borda Borda modified the milestones: v0.11, v0.10 Oct 19, 2022
@Borda Borda modified the milestones: v0.10, v0.11 Nov 18, 2022
@SkafteNicki SkafteNicki modified the milestones: v0.11, v0.12 Nov 22, 2022
@SkafteNicki
Copy link
Member

Closed by #1712 .

@RocketFlash
Copy link

Same issue using last library version

@RocketFlash
Copy link

@SkafteNicki could you recommend what to do ?

@SkafteNicki
Copy link
Member

@SkafteNicki could you recommend what to do ?

@RocketFlash Let me reopen the issue and investigate. A lot has happened to the implementation since the issue was first opened, so hard to say right now.

@SkafteNicki SkafteNicki reopened this Aug 23, 2023
@RocketFlash
Copy link

RocketFlash commented Aug 23, 2023

@SkafteNicki it seems something wrong with pycocotools, I've tried faster version of COCOEval wrapper based on
facebook's detectron2 implementation

This one and it calculates mAP correctly (not -1)

@Borda Borda changed the title MeanAveragePrecision (map) returns -1.0 if max_detection_thresholds is changed MeanAveragePrecision (map) returns -1.0 if max_detection_thresholds is changed Aug 25, 2023
@Borda Borda modified the milestones: v1.0.0, v1.1.x Aug 25, 2023
@Borda
Copy link
Member

Borda commented Aug 25, 2023

it seems something wrong with pycocotools

What version are using as the original repo was forked and some OSS development continued

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 v0.9.x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@Borda @RocketFlash @marckatzenmaier @SkafteNicki and others