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

[Enhance] Enhance ArcFaceClsHead #1181

Merged
merged 11 commits into from
Nov 21, 2022

Conversation

Ezra-Yu
Copy link
Collaborator

@Ezra-Yu Ezra-Yu commented Nov 9, 2022

Motivation

Enhance ArcFaceClsHead.

related paper : subcenterArcFace.
related issue #1169

Modification

  1. refactor the Arcface Code
  2. support subcenterArcFace
  3. support AdvMargins
  4. fix arcface when using amp

Use cases (Optional)

use vanilla ArcFace
mode = dict(
    backbone = xxx,
    neck = xxxx,
    head=dict(
        type='ArcFaceClsHead',
        num_classes=5000,
        in_channels=1024,
        loss = dict(type='CrossEntropyLoss', loss_weight=1.0),
        init_cfg=None),
)
use SubCenterArcFace with 3 sub-centers
mode = dict(
    backbone = xxx,
    neck = xxxx,
    head=dict(
        type='ArcFaceClsHead',
        num_classes=5000,
        in_channels=1024,
        num_subcenters=3,
        loss = dict(type='CrossEntropyLoss', loss_weight=1.0),
        init_cfg=None),
)
use ArcFaceWithAdvMargin
mode = dict(
    backbone = xxx,
    neck = xxxx,
    head=dict(
        type='ArcFaceClsHead',
        num_classes=5000,
        in_channels=1024,
        num_subcenters=3,
        loss = dict(type='CrossEntropyLoss', loss_weight=1.0),
        init_cfg=None),
)

custom_hooks = [dict(type='SetCountPowAdvMarginsHook')]

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 Nov 10, 2022

Codecov Report

Base: 0.02% // Head: 89.05% // Increases project coverage by +89.03% 🎉

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

Additional details and impacted files
@@             Coverage Diff              @@
##           dev-1.x    #1181       +/-   ##
============================================
+ Coverage     0.02%   89.05%   +89.03%     
============================================
  Files          121      147       +26     
  Lines         8217    11205     +2988     
  Branches      1368     1777      +409     
============================================
+ Hits             2     9979     +9977     
+ Misses        8215      975     -7240     
- Partials         0      251      +251     
Flag Coverage Δ
unittests 89.05% <ø> (+89.03%) ⬆️

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/davit.py 84.94% <0.00%> (ø)
mmcls/models/classifiers/timm.py 25.67% <0.00%> (ø)
mmcls/models/heads/margin_head.py 90.00% <0.00%> (ø)
mmcls/models/utils/layer_scale.py 86.66% <0.00%> (ø)
mmcls/models/retrievers/image2image.py 92.38% <0.00%> (ø)
mmcls/models/retrievers/__init__.py 100.00% <0.00%> (ø)
mmcls/models/backbones/swin_transformer_v2.py 89.63% <0.00%> (ø)
mmcls/models/backbones/mobileone.py 94.47% <0.00%> (ø)
... and 137 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.

@Ezra-Yu Ezra-Yu requested a review from okotaku November 10, 2022 04:32
@Ezra-Yu Ezra-Yu changed the title [Enhance] Support SubCenterArcFace and fix arcface when using amp [Enhance] Enhance ArcFaceClsHead Nov 10, 2022
@Ezra-Yu Ezra-Yu changed the title [Enhance] Enhance ArcFaceClsHead [Draft] [Enhance] Enhance ArcFaceClsHead Nov 10, 2022
@okotaku
Copy link
Collaborator

okotaku commented Nov 14, 2022

@Ezra-Yu The implementation is exactly as I intended in my proposal👍
It is a little complicated, but I can't think of any other simple plan.

@Ezra-Yu Ezra-Yu changed the title [Draft] [Enhance] Enhance ArcFaceClsHead [Enhance] Enhance ArcFaceClsHead Nov 17, 2022
@Ezra-Yu Ezra-Yu requested a review from mzr1996 November 17, 2022 10:58
Copy link
Collaborator

@okotaku okotaku 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 b000781 into open-mmlab:dev-1.x Nov 21, 2022
mzr1996 added a commit to mzr1996/mmpretrain that referenced this pull request Nov 24, 2022
* update arcface

* fix unit tests

* add adv-margins

add adv-margins

update arcface

* rebase

* update doc and fix ut

* rebase

* update code

* rebase

* use label data

* update set-margins

* Modify Arcface related method names.

Co-authored-by: mzr1996 <mzr1996@163.com>
@Ezra-Yu Ezra-Yu deleted the 1.x_enhance_arcface branch April 13, 2023 11:55
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.

None yet

3 participants