timm documentation

Swin Transformer V2 (CR)

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Swin Transformer V2 (CR)

Category: ViT · Code: timm/models/swin_transformer_v2_cr.py · Architectures: 16 · Pretrained weights: 3 (3 with ImageNet-1k results)

An alternative Swin Transformer V2 implementation adapted from Christoph Reich’s code, designed for changing the image size together with the window size, including non-square sizes. The module docstring marks it as experimental.

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_cr_tiny_ns_224.sw_in1k', pretrained=True)
>>> data_config = timm.data.resolve_model_data_config(model)

Model API support

FeatureSwinTransformerV2Cr
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 (SwinTransformerV2Cr with swinv2_cr_tiny_224 at 224), 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_cr_base_22487.8815.862240
swinv2_cr_base_38487.8850.573840
swinv2_cr_base_ns_22487.8815.862240
swinv2_cr_giant_2242598.76483.852240
swinv2_cr_giant_3842598.761450.713840
swinv2_cr_huge_224657.83115.972240
swinv2_cr_huge_384657.94352.043840
swinv2_cr_large_224196.6835.102240
swinv2_cr_large_384196.68108.963840
swinv2_cr_small_22449.709.072241
swinv2_cr_small_38449.7029.703840
swinv2_cr_small_ns_22449.709.082241
swinv2_cr_small_ns_25649.7012.072560
swinv2_cr_tiny_22428.334.662240
swinv2_cr_tiny_38428.3315.343840
swinv2_cr_tiny_ns_22428.334.662241

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_cr_small_224.sw_in1k22483.1262241000apache-2.0timm
swinv2_cr_small_ns_224.sw_in1k22483.4902241000apache-2.0timm
swinv2_cr_tiny_ns_224.sw_in1k22481.7962241000apache-2.0timm
Update on GitHub