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

[Feature] Add Base Retriever and Image2Image Retriever for retrieval tasks #1055

Merged
merged 17 commits into from Nov 2, 2022

Conversation

zzc98
Copy link
Contributor

@zzc98 zzc98 commented Sep 26, 2022

Motivation

  • A base class created to support generic retrieval tasks.
  • Realize the image to image retriever.

Use cases

gallery_dataloader = dict(
    batch_size=8,
    dataset=dict(
        type='InShop',
        data_root='data/inshop',
        ann_file='list_eval_partition.txt',
        mode='gallery',
        pipeline=val_pipeline
    ),
    sampler=dict(type='DefaultSampler', shuffle=False))

model = dict(
    type='ImageToImageRetriever',
    image_encoder=[
        dict(type='ResNet',
                  depth=101,
                  num_stages=4,
                  out_indices=(3,),
                  style='pytorch'),
        dict(type='GeneralizedMeanPooling'),
        dict(type='LinearReduction',
               in_channels=2048,
               out_channels=512,
               norm_cfg=dict(type='BN1d'),
               act_cfg=dict(type='ReLU'))
    ],
    head=dict(type='ArcFaceHead',
              num_classes=3997,
              in_channels=512,
              init_cfg=dict(type='Xavier', layer='Linear', distribution='uniform'),
              loss=dict(type='CrossEntropyLoss', loss_weight=1.0)),
    prototype=gallery_dataloader
)

Note:

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.

@Ezra-Yu Ezra-Yu added the 1.0rc Functionalities for MMClassification 1.0rc label Sep 26, 2022
@Ezra-Yu
Copy link
Collaborator

Ezra-Yu commented Sep 27, 2022

please fix the unit tests.

@codecov
Copy link

codecov bot commented Sep 27, 2022

Codecov Report

Base: 0.02% // Head: 91.51% // Increases project coverage by +91.48% 🎉

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

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

Additional details and impacted files
@@             Coverage Diff              @@
##           dev-1.x    #1055       +/-   ##
============================================
+ Coverage     0.02%   91.51%   +91.48%     
============================================
  Files          121      135       +14     
  Lines         8217    10120     +1903     
  Branches      1368     1630      +262     
============================================
+ Hits             2     9261     +9259     
+ Misses        8215      654     -7561     
- Partials         0      205      +205     
Flag Coverage Δ
unittests 91.51% <ø> (+91.48%) ⬆️

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

Impacted Files Coverage Δ
mmcls/apis/inference.py 0.00% <0.00%> (ø)
mmcls/datasets/transforms/compose.py
mmcls/models/backbones/efficientformer.py 95.08% <0.00%> (ø)
mmcls/structures/utils.py 77.77% <0.00%> (ø)
mmcls/models/retrievers/base.py 100.00% <0.00%> (ø)
mmcls/engine/hooks/retriever_hooks.py 72.72% <0.00%> (ø)
mmcls/models/backbones/mobilevit.py 91.15% <0.00%> (ø)
mmcls/models/retrievers/image2image.py 92.38% <0.00%> (ø)
mmcls/models/backbones/edgenext.py 95.20% <0.00%> (ø)
mmcls/models/backbones/mvit.py 92.46% <0.00%> (ø)
... and 125 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.

mmcls/engine/hooks/prototype_reset_hook.py Outdated Show resolved Hide resolved
mmcls/engine/hooks/prototype_reset_hook.py Outdated Show resolved Hide resolved
mmcls/models/retriever/base.py Outdated Show resolved Hide resolved
mmcls/models/retriever/image2image.py Outdated Show resolved Hide resolved
mmcls/models/retriever/base.py Outdated Show resolved Hide resolved
mmcls/models/retriever/base.py Outdated Show resolved Hide resolved
mmcls/models/retriever/image2image.py Outdated Show resolved Hide resolved
mmcls/models/retriever/image2image.py Outdated Show resolved Hide resolved
mmcls/models/retriever/image2image.py Outdated Show resolved Hide resolved
mmcls/models/retriever/image2image.py Outdated Show resolved Hide resolved
mmcls/models/retriever/image2image.py Outdated Show resolved Hide resolved
mmcls/engine/hooks/retriever_hooks.py Outdated Show resolved Hide resolved
mmcls/models/retriever/base.py Outdated Show resolved Hide resolved
mmcls/models/retriever/base.py Outdated Show resolved Hide resolved
mmcls/models/retriever/image2image.py Outdated Show resolved Hide resolved
mmcls/models/retriever/image2image.py Outdated Show resolved Hide resolved
mmcls/models/retriever/image2image.py Outdated Show resolved Hide resolved
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.

@mzr1996 mzr1996 merged commit 693596b into open-mmlab:dev-1.x Nov 2, 2022
mzr1996 added a commit to mzr1996/mmpretrain that referenced this pull request Nov 24, 2022
…tasks. (open-mmlab#1055)

* feat: add image retriever

* feat: add image retriever

* feat: add image retriever

* feat: add image retriever

* feat: add image retriever

* feat: add image retriever

* feat: add image retriever

* feat: add image retriever

* feat: add image retriever

* update retriever

* fix lint

* add hook unit test

* Use `register_buffer` to save prototype vectors and add a progress bar
during preparing prototype.

* update UTs

* update UTs

* fix typo

* modify the hook

Co-authored-by: Ezra-Yu <18586273+Ezra-Yu@users.noreply.github.com>
Co-authored-by: mzr1996 <mzr1996@163.com>
@zzc98 zzc98 deleted the add-retriever branch May 5, 2023 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.0rc Functionalities for MMClassification 1.0rc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants