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

update metric mAP@k for image retrieval #980

Open
wants to merge 16 commits into
base: dev-1.x
Choose a base branch
from

Conversation

zzc98
Copy link
Contributor

@zzc98 zzc98 commented Aug 18, 2022

Motivation

Support mAP@k in image retrieval

Use cases

  1. Use in the code
>>> import torch
>>> import numpy as np
>>> from mmcls.evaluation import RetrievalAveragePrecision

# using index format inputs
>>> pred = [ torch.Tensor([idx for idx in range(100)]) ] * 3
>>> target = [[0, 3, 6, 8, 35], [1, 2, 54, 105], [2, 42, 205]]
>>> RetrievalAveragePrecision.calculate(pred, target, 10, True, True)
29.246031746031747

# using tensor format inputs
>>> pred = np.array([np.linspace(0.95, 0.05, 10)] * 2)
>>> target = torch.Tensor([[1, 0, 1, 0, 0, 1, 0, 0, 1, 1]] * 2)
>>> RetrievalAveragePrecision.calculate(pred, target, 10)
62.222222222222214
  1. use in configs
val_evaluator = dict(type='RetrievalAveragePrecision', topk=100)
test_evaluator = val_evaluator

Checklist

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, like docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects, like MMDet or MMSeg.
  • CLA has been signed and all committers have signed the CLA in this PR.

@codecov
Copy link

codecov bot commented Aug 18, 2022

Codecov Report

Base: 0.02% // Head: 86.82% // Increases project coverage by +86.80% 🎉

Coverage data is based on head (d2c51c6) compared to base (b8b31e9).
Patch has no changes to coverable lines.

❗ Current head d2c51c6 differs from pull request most recent head e6d49dc. Consider uploading reports for the commit e6d49dc to get more accurate results

Additional details and impacted files
@@             Coverage Diff              @@
##           dev-1.x     #980       +/-   ##
============================================
+ Coverage     0.02%   86.82%   +86.80%     
============================================
  Files          121      169       +48     
  Lines         8217    14016     +5799     
  Branches      1368     2227      +859     
============================================
+ Hits             2    12170    +12168     
+ Misses        8215     1462     -6753     
- Partials         0      384      +384     
Flag Coverage Δ
unittests 86.82% <ø> (+86.80%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmcls/datasets/transforms/compose.py
mmcls/models/utils/norm.py 80.00% <0.00%> (ø)
mmcls/evaluation/metrics/retrieval.py 86.61% <0.00%> (ø)
mmcls/models/backbones/xcit.py 82.78% <0.00%> (ø)
mmcls/datasets/multi_task.py 74.46% <0.00%> (ø)
mmcls/models/classifiers/hugging_face.py 25.64% <0.00%> (ø)
mmcls/utils/analyze.py 100.00% <0.00%> (ø)
mmcls/models/backbones/mvit.py 92.46% <0.00%> (ø)
mmcls/models/retrievers/__init__.py 100.00% <0.00%> (ø)
mmcls/evaluation/metrics/multi_task.py 94.59% <0.00%> (ø)
... and 160 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Collaborator

@Ezra-Yu Ezra-Yu left a comment

Choose a reason for hiding this comment

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

LGTM.

@Ezra-Yu Ezra-Yu mentioned this pull request May 8, 2023
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants