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

Fix swin backbone absolute pos_embed #8127

Merged
merged 5 commits into from
Aug 23, 2022
Merged

Conversation

normster
Copy link

@normster normster commented Jun 3, 2022

Motivation

The Swin transformer backbone is currently unable to process input images differing in size from the pretraining resolution when absolute positional embedding is enabled, due to lack of dynamic pos embed resizing in the forward pass.

Modification

When absolute positional embedding is enabled, the backbone now checks the input shape against the pos embed shape and performs a bicubic interpolation to the correct shape if necessary. This is based on the original Mask2former code: https://github.com/facebookresearch/Mask2Former/blob/main/mask2former/modeling/backbone/swin.py#L656.

The pos embed parameter's shape has also been changed from [B * (H*W) * D] -> [B * D * H * W] to bring the model into consistency with the checkpoint loading code, which expects the new shape.

BC-breaking (Optional)

This fix should not break backwards compatibility. No existing configs using the Swin backbone have absolute positional embedding enabled, or load from

Use cases (Optional)

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMCls.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@CLAassistant
Copy link

CLAassistant commented Jun 3, 2022

CLA assistant check
All committers have signed the CLA.

@ZwwWayne ZwwWayne added this to the 2.25.1 milestone Jun 5, 2022
@ZwwWayne ZwwWayne requested a review from chhluo June 5, 2022 09:00
@codecov
Copy link

codecov bot commented Jun 5, 2022

Codecov Report

Merging #8127 (605a55b) into dev (ca11860) will increase coverage by 0.00%.
The diff coverage is 60.00%.

@@           Coverage Diff           @@
##              dev    #8127   +/-   ##
=======================================
  Coverage   64.17%   64.17%           
=======================================
  Files         361      361           
  Lines       29525    29529    +4     
  Branches     5019     5020    +1     
=======================================
+ Hits        18947    18950    +3     
- Misses       9575     9576    +1     
  Partials     1003     1003           
Flag Coverage Δ
unittests 64.15% <60.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
mmdet/models/backbones/swin.py 81.01% <60.00%> (-0.49%) ⬇️
mmdet/datasets/pipelines/loading.py 57.99% <0.00%> (+0.15%) ⬆️
mmdet/utils/misc.py 64.10% <0.00%> (+2.56%) ⬆️

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

Copy link
Collaborator

@chhluo chhluo left a comment

Choose a reason for hiding this comment

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

LGTM.

There are some lint problems, please fix them.

image

@chhluo
Copy link
Collaborator

chhluo commented Jun 11, 2022

@ZwwWayne ZwwWayne removed this from the 2.25.1 milestone Aug 15, 2022
@ZwwWayne ZwwWayne added this to the 2.26.0 milestone Aug 23, 2022
@ZwwWayne ZwwWayne merged commit 2f249ff into open-mmlab:dev Aug 23, 2022
@ZwwWayne
Copy link
Collaborator

This PR needs to be migrated to dev-3.x

ZwwWayne pushed a commit that referenced this pull request Sep 9, 2022
* Fix swin backbone absolute pos_embed resizing

* fix lint

* fix lint

* add unit test

* Update swin.py

Co-authored-by: Cedric Luo <luochunhua1996@outlook.com>
triple-Mu pushed a commit to triple-Mu/mmdetection that referenced this pull request Nov 5, 2022
* Fix swin backbone absolute pos_embed resizing

* fix lint

* fix lint

* add unit test

* Update swin.py

Co-authored-by: Cedric Luo <luochunhua1996@outlook.com>
SakiRinn pushed a commit to SakiRinn/mmdetection-locount that referenced this pull request Mar 17, 2023
* Fix swin backbone absolute pos_embed resizing

* fix lint

* fix lint

* add unit test

* Update swin.py

Co-authored-by: Cedric Luo <luochunhua1996@outlook.com>
@OpenMMLab-Assistant-004
Copy link

Hi @normster !First of all, we want to express our gratitude for your significant PR in the mmdetection project. Your contribution is highly appreciated, and we are grateful for your efforts in helping improve this open-source project during your personal time. We believe that many developers will benefit from your PR.

We would also like to invite you to join our Special Interest Group (SIG) private channel on Discord, where you can share your experiences, ideas, and build connections with like-minded peers. To join the SIG channel, simply message moderator— OpenMMLab on Discord or briefly share your open-source contributions in the #introductions channel and we will assist you. Look forward to seeing you there! Join us :https://discord.gg/raweFPmdzG

If you have WeChat,welcome to join our community on WeChat. You can add our assistant :openmmlabwx. Please add "mmsig + Github ID" as a remark when adding friends:)
Thank you again for your contribution❤

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.

6 participants