timm documentation

Swin Transformer V2

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

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

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

FeatureSwinTransformerV2
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

ArchitectureParams (M)GMACsInput sizePretrained weights
swinv2_base_window8_25687.9220.372561
swinv2_base_window12_192109.2811.901921
swinv2_base_window12to16_192to25687.9222.022561
swinv2_base_window12to24_192to38487.9255.253841
swinv2_base_window16_25687.9222.022561
swinv2_large_window12_192228.7726.171921
swinv2_large_window12to16_192to256196.7447.812561
swinv2_large_window12to24_192to384196.74116.153841
swinv2_small_window8_25649.7311.582561
swinv2_small_window16_25649.7312.822561
swinv2_tiny_window8_25628.355.962561
swinv2_tiny_window16_25628.356.682561

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.

WeightInput sizeTop-1 (%)Eval sizeClassesLicenseHub
swinv2_base_window8_256.ms_in1k25684.2462561000mittimm
swinv2_base_window12_192.ms_in22k192--21841mittimm
swinv2_base_window12to16_192to256.ms_in22k_ft_in1k25686.2702561000mittimm
swinv2_base_window12to24_192to384.ms_in22k_ft_in1k38487.1423841000mittimm
swinv2_base_window16_256.ms_in1k25684.6082561000mittimm
swinv2_large_window12_192.ms_in22k192--21841mittimm
swinv2_large_window12to16_192to256.ms_in22k_ft_in1k25686.9342561000mittimm
swinv2_large_window12to24_192to384.ms_in22k_ft_in1k38487.4743841000mittimm
swinv2_small_window8_256.ms_in1k25683.8442561000mittimm
swinv2_small_window16_256.ms_in1k25684.2162561000mittimm
swinv2_tiny_window8_256.ms_in1k25681.8242561000mittimm
swinv2_tiny_window16_256.ms_in1k25682.8282561000mittimm
Update on GitHub