timm documentation

MaxViT and CoAtNet

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v1.0.30).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

MaxViT and CoAtNet

Category: Hybrid · Code: timm/models/maxxvit.py · Architectures: 58 · Pretrained weights: 52 (43 with ImageNet-1k results)

From-scratch implementations of MaxViT (MBConv blocks with multi-axis attention, blocked local and dilated grid attention) and CoAtNet (convolution stages followed by relative attention stages), plus timm variants (_rw configs, MaxxViT).

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

Model API support

FeatureMaxxVit
features_only=True feature maps✓ (strides 2, 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 (MaxxVit with maxvit_pico_rw_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
coatnet_0_22425.044.582240
coatnet_0_rw_22427.444.432241
coatnet_1_22442.238.702240
coatnet_1_rw_22441.728.042241
coatnet_2_22474.6816.502240
coatnet_2_rw_22473.8715.092242
coatnet_3_224166.9736.562240
coatnet_3_rw_224181.8133.442241
coatnet_4_224275.4362.482240
coatnet_5_224687.47145.492240
coatnet_bn_0_rw_22427.444.672241
coatnet_nano_cc_22413.762.242240
coatnet_nano_rw_22415.142.412241
coatnet_pico_rw_22410.852.052240
coatnet_rmlp_0_rw_22427.454.722240
coatnet_rmlp_1_rw2_22441.728.112242
coatnet_rmlp_1_rw_22441.697.852241
coatnet_rmlp_2_rw_22473.8815.182243
coatnet_rmlp_2_rw_38473.8847.693841
coatnet_rmlp_3_rw_224165.1533.562240
coatnet_rmlp_nano_rw_22415.152.622241
coatnext_nano_rw_22414.702.472241
maxvit_base_tf_224119.4724.042242
maxvit_base_tf_384119.6573.803842
maxvit_base_tf_512119.88138.025122
maxvit_large_tf_224211.7943.682242
maxvit_large_tf_384212.03132.553842
maxvit_large_tf_512212.33244.755122
maxvit_nano_rw_25615.454.462561
maxvit_pico_rw_2567.461.832560
maxvit_rmlp_base_rw_224116.1423.152242
maxvit_rmlp_base_rw_384116.1470.973841
maxvit_rmlp_nano_rw_25615.504.472561
maxvit_rmlp_pico_rw_2567.521.852561
maxvit_rmlp_small_rw_22464.9010.752241
maxvit_rmlp_small_rw_25664.9014.152560
maxvit_rmlp_tiny_rw_25629.156.772561
maxvit_small_tf_22468.9311.662241
maxvit_small_tf_38469.0235.873841
maxvit_small_tf_51269.1367.265121
maxvit_tiny_pm_25630.096.612560
maxvit_tiny_rw_22429.065.112241
maxvit_tiny_rw_25629.076.742560
maxvit_tiny_tf_22430.925.602241
maxvit_tiny_tf_38430.9817.533841
maxvit_tiny_tf_51231.0533.495121
maxvit_xlarge_tf_224506.9997.522241
maxvit_xlarge_tf_384475.32292.783841
maxvit_xlarge_tf_512475.77534.145121
maxxvit_rmlp_nano_rw_25616.784.372561
maxxvit_rmlp_small_rw_25666.0114.672561
maxxvit_rmlp_tiny_rw_25629.646.662560
maxxvitv2_nano_rw_25623.706.262561
maxxvitv2_rmlp_base_rw_224116.0924.202242
maxxvitv2_rmlp_base_rw_384116.0972.983841
maxxvitv2_rmlp_large_rw_224215.4244.142240
test_coatnet0.58-1600
test_maxvit1.09-1600

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
coatnet_0_rw_224.sw_in1k22482.3962241000apache-2.0timm
coatnet_1_rw_224.sw_in1k22483.6202241000apache-2.0timm
coatnet_2_rw_224.sw_in12k224--11821apache-2.0timm
coatnet_2_rw_224.sw_in12k_ft_in1k22486.5822241000apache-2.0timm
coatnet_3_rw_224.sw_in12k224--11821apache-2.0timm
coatnet_bn_0_rw_224.sw_in1k22482.3942241000apache-2.0timm
coatnet_nano_rw_224.sw_in1k22481.7042241000apache-2.0timm
coatnet_rmlp_1_rw2_224.sw_in12k224--11821apache-2.0timm
coatnet_rmlp_1_rw2_224.sw_in12k_ft_in1k22484.9402241000apache-2.0timm
coatnet_rmlp_1_rw_224.sw_in1k22483.3502241000apache-2.0timm
coatnet_rmlp_2_rw_224.sw_in12k224--11821apache-2.0timm
coatnet_rmlp_2_rw_224.sw_in12k_ft_in1k22486.5382241000apache-2.0timm
coatnet_rmlp_2_rw_224.sw_in1k22484.6082241000apache-2.0timm
coatnet_rmlp_2_rw_384.sw_in12k_ft_in1k38487.3883841000apache-2.0timm
coatnet_rmlp_nano_rw_224.sw_in1k22482.0642241000apache-2.0timm
coatnext_nano_rw_224.sw_in1k22481.9982241000apache-2.0timm
maxvit_base_tf_224.in1k22484.8842241000apache-2.0timm
maxvit_base_tf_224.in21k224--21843apache-2.0timm
maxvit_base_tf_384.in1k38486.2903841000apache-2.0timm
maxvit_base_tf_384.in21k_ft_in1k38487.9303841000apache-2.0timm
maxvit_base_tf_512.in1k51286.5985121000apache-2.0timm
maxvit_base_tf_512.in21k_ft_in1k51288.2145121000apache-2.0timm
maxvit_large_tf_224.in1k22484.9382241000apache-2.0timm
maxvit_large_tf_224.in21k224--21843apache-2.0timm
maxvit_large_tf_384.in1k38486.2423841000apache-2.0timm
maxvit_large_tf_384.in21k_ft_in1k38487.9943841000apache-2.0timm
maxvit_large_tf_512.in1k51286.5345121000apache-2.0timm
maxvit_large_tf_512.in21k_ft_in1k51288.2365121000apache-2.0timm
maxvit_nano_rw_256.sw_in1k25682.9342561000apache-2.0timm
maxvit_rmlp_base_rw_224.sw_in12k224--11821apache-2.0timm
maxvit_rmlp_base_rw_224.sw_in12k_ft_in1k22486.9082241000apache-2.0timm
maxvit_rmlp_base_rw_384.sw_in12k_ft_in1k38487.8103841000apache-2.0timm
maxvit_rmlp_nano_rw_256.sw_in1k25682.9782561000apache-2.0timm
maxvit_rmlp_pico_rw_256.sw_in1k25680.5502561000apache-2.0timm
maxvit_rmlp_small_rw_224.sw_in1k22484.4882241000apache-2.0timm
maxvit_rmlp_tiny_rw_256.sw_in1k25684.2262561000apache-2.0timm
maxvit_small_tf_224.in1k22484.4522241000apache-2.0timm
maxvit_small_tf_384.in1k38485.5343841000apache-2.0timm
maxvit_small_tf_512.in1k51286.1025121000apache-2.0timm
maxvit_tiny_rw_224.sw_in1k22483.5222241000apache-2.0timm
maxvit_tiny_tf_224.in1k22483.4262241000apache-2.0timm
maxvit_tiny_tf_384.in1k38485.1063841000apache-2.0timm
maxvit_tiny_tf_512.in1k51285.6585121000apache-2.0timm
maxvit_xlarge_tf_224.in21k224--21843apache-2.0timm
maxvit_xlarge_tf_384.in21k_ft_in1k38488.3023841000apache-2.0timm
maxvit_xlarge_tf_512.in21k_ft_in1k51288.5405121000apache-2.0timm
maxxvit_rmlp_nano_rw_256.sw_in1k25683.0362561000apache-2.0timm
maxxvit_rmlp_small_rw_256.sw_in1k25684.6342561000apache-2.0timm
maxxvitv2_nano_rw_256.sw_in1k25683.1082561000apache-2.0timm
maxxvitv2_rmlp_base_rw_224.sw_in12k224--11821apache-2.0timm
maxxvitv2_rmlp_base_rw_224.sw_in12k_ft_in1k22486.6402241000apache-2.0timm
maxxvitv2_rmlp_base_rw_384.sw_in12k_ft_in1k38487.4803841000apache-2.0timm

Citation

@article{tu2022maxvit,
  title={MaxViT: Multi-Axis Vision Transformer},
  author={Tu, Zhengzhong and Talebi, Hossein and Zhang, Han and Yang, Feng and Milanfar, Peyman and Bovik, Alan and Li, Yinxiao},
  journal={ECCV},
  year={2022},
}

@article{DBLP:journals/corr/abs-2106-04803,
  author    = {Zihang Dai and Hanxiao Liu and Quoc V. Le and Mingxing Tan},
  title     = {CoAtNet: Marrying Convolution and Attention for All Data Sizes},
  journal   = {CoRR},
  volume    = {abs/2106.04803},
  year      = {2021}
}
Update on GitHub