Skip to content

[Cherrypick] Refactor swin transfomer so its component can be reused on the 3d version #6100

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

Conversation

YosuaMichael
Copy link
Contributor

Cherry pick #6088
This is useful so our current swin transformer 2d can be more compatible with the 3d version (developed in facebookresearch/multimodal#43)

…on (pytorch#6088)

* Use List[int] instead of int for window_size and shift_size

* Make PatchMerging and SwinTransformerBlock able to handle 2d and 3d cases

* Separate patch embedding from SwinTransformer and enable to get model without head by specifying num_heads=None

* Dont use if before padding so it is fx friendly

* Put the handling on window_size edge cases on separate function and wrap with torch.fx.wrap so it is excluded from tracing

* Update the weight url to the converted weight with new structure

* Update the accuracy of swin_transformer

* Change assert to Exception and nit

* Make num_classes optional

* Add typing output for _fix_window_and_shift_size function

* init head to None to make it jit scriptable

* Revert the change to make num_classes optional

* Revert unneccesarry changes that might be risky

* Remove self.head declaration
Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@YosuaMichael YosuaMichael marked this pull request as ready for review May 26, 2022 14:59
@YosuaMichael YosuaMichael merged commit 1a288d1 into pytorch:release/0.13 May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants