opensi·si

timm/models/visiontransformerhybrid.py

Hybrid Vision Transformer

Category: Hybrid · Code: timm/models/vision_transformer_hybrid.py · Architectures: 14 · Pretrained weights: 14 (7 with ImageNet-1k results)

Vision Transformers whose patch tokens come from a convolutional backbone (ResNet / ResNetV2 stem or stages) instead of a linear patch embedding, using the VisionTransformer class.

Papers

  • An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
  • How to train your ViT? Data, Augmentation, and Regularization in Vision Transformers
  • MobileCLIP: Fast Image-Text Models through Multi-Modal Reinforced Training
  • MobileCLIP2: Improving Multi-Modal Reinforced Training

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

Model API support

Feature VisionTransformer
features_only=True feature maps ✓ (strides 32, 32, 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 (VisionTransformer with vit_tiny_r_s16_p8_224 at 224), other architectures of the same class are expected to behave the same. See the Model API page for details.

Architectures

表格(15 行)
Architecture Params (M) GMACs Input size Pretrained weights
vit_base_mci_224 86.35 17.73 224 3
vit_base_r26_s32_224 101.38 6.81 224 0
vit_base_r50_s16_224 97.89 21.66 224 1
vit_base_r50_s16_384 98.95 67.43 384 1
vit_base_resnet26d_224 101.40 6.97 224 0
vit_base_resnet50d_224 110.97 8.73 224 0
vit_large_r50_s32_224 328.99 19.58 224 2
vit_large_r50_s32_384 329.09 57.43 384 1
vit_small_r26_s32_224 36.43 3.56 224 2
vit_small_r26_s32_384 36.47 10.43 384 1
vit_small_resnet26d_224 63.61 5.07 224 0
vit_small_resnet50d_s16_224 57.53 13.48 224 0
vit_tiny_r_s16_p8_224 6.34 0.44 224 2
vit_tiny_r_s16_p8_384 6.36 1.34 384 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.

Weights are grouped by source: the paper or origin given in the pretrained config, else a Hub organization other than timm, else the first part of the pretrained tag (architecture.tag). Sources with a single weight are listed under other.

augreg tags

Weight Input size Top-1 (%) Eval size Classes License Hub
vit_large_r50_s32_224.augreg_in21k 224 - - 21843 apache-2.0 timm
vit_large_r50_s32_224.augreg_in21k_ft_in1k 224 84.434 224 1000 apache-2.0 timm
vit_large_r50_s32_384.augreg_in21k_ft_in1k 384 86.188 384 1000 apache-2.0 timm
vit_small_r26_s32_224.augreg_in21k 224 - - 21843 apache-2.0 timm
vit_small_r26_s32_224.augreg_in21k_ft_in1k 224 81.856 224 1000 apache-2.0 timm
vit_small_r26_s32_384.augreg_in21k_ft_in1k 384 84.066 384 1000 apache-2.0 timm
vit_tiny_r_s16_p8_224.augreg_in21k 224 - - 21843 apache-2.0 timm
vit_tiny_r_s16_p8_224.augreg_in21k_ft_in1k 224 71.800 224 1000 apache-2.0 timm
vit_tiny_r_s16_p8_384.augreg_in21k_ft_in1k 384 75.962 384 1000 apache-2.0 timm

orig tags

Weight Input size Top-1 (%) Eval size Classes License Hub
vit_base_r50_s16_224.orig_in21k 224 - - none apache-2.0 timm
vit_base_r50_s16_384.orig_in21k_ft_in1k 384 84.988 384 1000 apache-2.0 timm

apple

Hosted by apple on the Hugging Face Hub.

Weight Input size Top-1 (%) Eval size Classes License Hub
vit_base_mci_224.apple_mclip 224 - - 512 apple-amlr apple/mobileclip_b_timm
vit_base_mci_224.apple_mclip_lt 224 - - 512 apple-amlr apple/mobileclip_b_lt_timm

Other

Weight Input size Top-1 (%) Eval size Classes License Hub
vit_base_mci_224.apple_mclip2_dfndr2b 224 - - 512 apple-amlr timm

Source and license

Source: timm documentation, adapted for this site. Licensing and attribution follow the terms of the upstream project.