timm/models/swintransformerv2.py
Swin Transformer V2
Category: ViT · Code:
timm/models/swin_transformer_v2.py
· Architectures: 12 · Pretrained weights: 12 (10 with ImageNet-1k results)
Swin Transformer V2 scales up Swin with residual post-norm, scaled cosine attention and a log-spaced continuous relative position bias that transfers across window sizes.
Papers
- Swin Transformer V2: Scaling Up Capacity and Resolution
Usage
See the Quickstart for loading pretrained weights, image preprocessing and fine-tuning, and Feature Extraction for using the models as backbones.
>>> import timm
>>> model = timm.create_model('swinv2_tiny_window16_256.ms_in1k', pretrained=True)
>>> data_config = timm.data.resolve_model_data_config(model)
Model API support
| Feature | SwinTransformerV2 |
|---|---|
features_only=True feature maps |
✓ (strides 4, 8, 16, 32) |
forward_intermediates() |
✓ |
prune_intermediate_layers() |
✓ |
| Any input size, no changes needed | ✗ |
set_input_size() |
✓ |
dynamic_img_size=True |
✓ |
set_grad_checkpointing() |
✓ |
Layer-wise LR decay (group_matcher()) |
✓ |
reset_classifier() |
✓ |
✓ supported, ✓ (square) works for square sizes only, ✗ not supported, – not needed (the model already accepts any input
size). Checked by running each feature on a randomly initialized model (SwinTransformerV2 with
swinv2_tiny_window16_256 at 256), other architectures of the same class are expected to behave the same. See the
Model API page for details.
Architectures
표 (13행)
| Architecture | Params (M) | GMACs | Input size | Pretrained weights |
|---|---|---|---|---|
swinv2_base_window8_256 |
87.92 | 20.37 | 256 | 1 |
swinv2_base_window12_192 |
109.28 | 11.90 | 192 | 1 |
swinv2_base_window12to16_192to256 |
87.92 | 22.02 | 256 | 1 |
swinv2_base_window12to24_192to384 |
87.92 | 55.25 | 384 | 1 |
swinv2_base_window16_256 |
87.92 | 22.02 | 256 | 1 |
swinv2_large_window12_192 |
228.77 | 26.17 | 192 | 1 |
swinv2_large_window12to16_192to256 |
196.74 | 47.81 | 256 | 1 |
swinv2_large_window12to24_192to384 |
196.74 | 116.15 | 384 | 1 |
swinv2_small_window8_256 |
49.73 | 11.58 | 256 | 1 |
swinv2_small_window16_256 |
49.73 | 12.82 | 256 | 1 |
swinv2_tiny_window8_256 |
28.35 | 5.96 | 256 | 1 |
swinv2_tiny_window16_256 |
28.35 | 6.68 | 256 | 1 |
GMACs and parameter counts are for the default input size and classifier of each architecture, from the benchmark results.
Pretrained weights
Top-1 is ImageNet-1k validation accuracy from
results-imagenet.csv at
the listed eval size, - if the weight has no ImageNet-1k result (e.g. pretraining or image-text weights). Classes is the
size of the pretrained classifier, none for weights without one.
표 (13행)
| Weight | Input size | Top-1 (%) | Eval size | Classes | License | Hub |
|---|---|---|---|---|---|---|
swinv2_base_window8_256.ms_in1k |
256 | 84.246 | 256 | 1000 | mit | timm |
swinv2_base_window12_192.ms_in22k |
192 | - | - | 21841 | mit | timm |
swinv2_base_window12to16_192to256.ms_in22k_ft_in1k |
256 | 86.270 | 256 | 1000 | mit | timm |
swinv2_base_window12to24_192to384.ms_in22k_ft_in1k |
384 | 87.142 | 384 | 1000 | mit | timm |
swinv2_base_window16_256.ms_in1k |
256 | 84.608 | 256 | 1000 | mit | timm |
swinv2_large_window12_192.ms_in22k |
192 | - | - | 21841 | mit | timm |
swinv2_large_window12to16_192to256.ms_in22k_ft_in1k |
256 | 86.934 | 256 | 1000 | mit | timm |
swinv2_large_window12to24_192to384.ms_in22k_ft_in1k |
384 | 87.474 | 384 | 1000 | mit | timm |
swinv2_small_window8_256.ms_in1k |
256 | 83.844 | 256 | 1000 | mit | timm |
swinv2_small_window16_256.ms_in1k |
256 | 84.216 | 256 | 1000 | mit | timm |
swinv2_tiny_window8_256.ms_in1k |
256 | 81.824 | 256 | 1000 | mit | timm |
swinv2_tiny_window16_256.ms_in1k |
256 | 82.828 | 256 | 1000 | mit | timm |
Source and license
Source: timm documentation, adapted for this site. Licensing and attribution follow the terms of the upstream project.