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

Add SwinV2 #6246

Merged
merged 61 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
6eeecf9
init submit
ain-soph Jul 7, 2022
a104e79
Merge branch 'pytorch:main' into swin_transfomer_v2
ain-soph Jul 7, 2022
7ad94a7
fix typo
ain-soph Jul 7, 2022
4f1a59b
Merge branch 'swin_transfomer_v2' of https://github.com/ain-soph/visi…
ain-soph Jul 7, 2022
e28ec45
support ufmt and mypy
ain-soph Jul 7, 2022
ff44832
fix 2 unittest errors
ain-soph Jul 7, 2022
7d84b31
fix ufmt issue
ain-soph Jul 8, 2022
4a21e98
Apply suggestions from code review
ain-soph Jul 8, 2022
6e488d5
Merge branch 'swin_transfomer_v2' of https://github.com/ain-soph/visi…
ain-soph Jul 8, 2022
8e0f8f6
unify codes
ain-soph Jul 8, 2022
284ca50
fix meshgrid indexing
ain-soph Jul 8, 2022
e801222
fix a bug
ain-soph Jul 8, 2022
32bee48
Merge branch 'pytorch:main' into swin_transfomer_v2
ain-soph Jul 8, 2022
56cb30b
Merge branch 'swin_transfomer_v2' of https://github.com/ain-soph/visi…
ain-soph Jul 8, 2022
eb06414
fix type check
ain-soph Jul 8, 2022
5deccd5
add type_annotation
ain-soph Jul 8, 2022
75bcbc7
add slow model
ain-soph Jul 9, 2022
084833e
fix device issue
ain-soph Jul 9, 2022
a0498a9
fix ufmt issue
ain-soph Jul 9, 2022
c9b77c8
add expect pickle file
ain-soph Jul 9, 2022
81e2a2e
fix jit script issue
ain-soph Jul 9, 2022
3eb0de8
fix type check
ain-soph Jul 9, 2022
d7a4ca2
keep consistent argument order
ain-soph Jul 9, 2022
005bb13
add support for pretrained_window_size
ain-soph Jul 9, 2022
69bad17
avoid code duplication
ain-soph Jul 9, 2022
6717145
a better code reuse
ain-soph Jul 9, 2022
0dc1b22
update window_size argument
ain-soph Jul 9, 2022
8b85859
make permute and flatten operations modular
ain-soph Jul 9, 2022
b9bba94
add PatchMergingV2
ain-soph Jul 10, 2022
4d8de8a
modify expect.pkl
ain-soph Jul 10, 2022
db94095
use None as default argument value
ain-soph Jul 11, 2022
54cf584
fix type check
ain-soph Jul 11, 2022
568731c
fix indent
ain-soph Jul 11, 2022
b04b9c7
fix window_size (temporarily)
ain-soph Jul 11, 2022
a0e7a40
remove "v2_" related prefix and add v2 builder
ain-soph Jul 12, 2022
f643ff0
remove v2 builder
ain-soph Jul 12, 2022
e2b338b
keep default value consistent with official repo
ain-soph Jul 12, 2022
8a13f93
deprecate dropout
ain-soph Jul 12, 2022
f4ea5df
deprecate pretrained_window_size
ain-soph Jul 12, 2022
1c7579c
fix dynamic padding edge case
ain-soph Jul 13, 2022
daf8e19
remove unused imports
ain-soph Jul 13, 2022
0587039
remove doc modification
ain-soph Jul 13, 2022
1526658
Revert "deprecate dropout"
ain-soph Jul 13, 2022
a7b18d8
Revert "fix dynamic padding edge case"
ain-soph Jul 13, 2022
5353afb
remove unused kwargs
ain-soph Jul 13, 2022
83f9d3d
add downsample docs
ain-soph Jul 13, 2022
e07de70
revert block default value
ain-soph Jul 13, 2022
ce0103a
revert argument order change
ain-soph Jul 14, 2022
07fb86b
explicitly specify start_dim
ain-soph Jul 14, 2022
2670ae1
Merge branch 'main' into swin_transfomer_v2
ain-soph Jul 14, 2022
fba200b
add small and base variants
ain-soph Jul 20, 2022
e3f8935
Merge branch 'main' into swin_transfomer_v2
ain-soph Jul 20, 2022
f0a53b9
add expect files and slow_models
ain-soph Jul 20, 2022
da56c95
Merge branch 'main' into swin_transfomer_v2
jdsgomes Jul 22, 2022
af2f491
Merge branch 'main' into swin_transfomer_v2
ain-soph Aug 4, 2022
1266a4c
Merge branch 'main' into swin_transfomer_v2
jdsgomes Aug 8, 2022
3fd6968
Merge branch 'main' into swin_transfomer_v2
jdsgomes Aug 9, 2022
72cd9d8
Add model weights and documentation for swin v2
jdsgomes Aug 9, 2022
68ffa1c
fix lint
jdsgomes Aug 10, 2022
73373a5
fix end of files line
jdsgomes Aug 10, 2022
c13c5ef
Merge branch 'main' into swin_transfomer_v2
jdsgomes Aug 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions docs/source/models/swin_transformer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ SwinTransformer

.. currentmodule:: torchvision.models

The SwinTransformer model is based on the `Swin Transformer: Hierarchical Vision
The SwinTransformer models are based on the `Swin Transformer: Hierarchical Vision
Transformer using Shifted Windows <https://arxiv.org/abs/2103.14030>`__
paper.
SwinTransformer V2 models are based on the `Swin Transformer V2: Scaling Up Capacity
and Resolution <https://openaccess.thecvf.com/content/CVPR2022/papers/Liu_Swin_Transformer_V2_Scaling_Up_Capacity_and_Resolution_CVPR_2022_paper.pdf>`__
paper.


Model builders
--------------

The following model builders can be used to instantiate an SwinTransformer model.
`swin_t` can be instantiated with pre-trained weights and all others without.
The following model builders can be used to instantiate an SwinTransformer model (original and V2) with and without pre-trained weights.
All the model builders internally rely on the ``torchvision.models.swin_transformer.SwinTransformer``
base class. Please refer to the `source code
<https://github.com/pytorch/vision/blob/main/torchvision/models/swin_transformer.py>`_ for
Expand All @@ -25,3 +27,6 @@ more details about this class.
swin_t
swin_s
swin_b
swin_v2_t
swin_v2_s
swin_v2_b
11 changes: 11 additions & 0 deletions references/classification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ Note that `--val-resize-size` was optimized in a post-training step, see their `



### SwinTransformer V2
```
torchrun --nproc_per_node=8 train.py\
--model $MODEL --epochs 300 --batch-size 128 --opt adamw --lr 0.001 --weight-decay 0.05 --norm-weight-decay 0.0 --bias-weight-decay 0.0 --transformer-embedding-decay 0.0 --lr-scheduler cosineannealinglr --lr-min 0.00001 --lr-warmup-method linear --lr-warmup-epochs 20 --lr-warmup-decay 0.01 --amp --label-smoothing 0.1 --mixup-alpha 0.8 --clip-grad-norm 5.0 --cutmix-alpha 1.0 --random-erase 0.25 --interpolation bicubic --auto-augment ta_wide --model-ema --ra-sampler --ra-reps 4 --val-resize-size 256 --val-crop-size 256 --train-crop-size 256
```
Here `$MODEL` is one of `swin_v2_t`, `swin_v2_s` or `swin_v2_b`.
Note that `--val-resize-size` was optimized in a post-training step, see their `Weights` entry for the exact value.




### ShuffleNet V2
```
torchrun --nproc_per_node=8 train.py \
Expand Down
Binary file added test/expect/ModelTester.test_swin_v2_b_expect.pkl
Binary file not shown.
Binary file added test/expect/ModelTester.test_swin_v2_s_expect.pkl
Binary file not shown.
Binary file added test/expect/ModelTester.test_swin_v2_t_expect.pkl
Binary file not shown.
3 changes: 3 additions & 0 deletions test/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ def _check_input_backprop(model, inputs):
"swin_t",
"swin_s",
"swin_b",
"swin_v2_t",
"swin_v2_s",
"swin_v2_b",
]
for m in slow_models:
_model_params[m] = {"input_shape": (1, 3, 64, 64)}
Expand Down
Loading