timm documentation

MetaFormer (PoolFormer, ConvFormer, CAFormer)

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

MetaFormer (PoolFormer, ConvFormer, CAFormer)

Category: Hybrid · Code: timm/models/metaformer.py · Architectures: 18 · Pretrained weights: 50 (42 with ImageNet-1k results)

MetaFormer models share a general transformer block structure and vary the token mixer: pooling in PoolFormer / PoolFormerV2, separable convolutions in ConvFormer, and convolutions in the early stages with attention in the later stages in CAFormer.

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

Model API support

FeatureMetaFormer
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 (MetaFormer with poolformerv2_s12 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
caformer_b3698.7523.222245
caformer_m3656.2013.292245
caformer_s1826.344.132245
caformer_s3639.308.002245
convformer_b3699.8822.692245
convformer_m3657.0512.892245
convformer_s1826.773.962245
convformer_s3640.017.672245
poolformer_m3656.178.802241
poolformer_m4873.4711.592241
poolformer_s1211.921.822241
poolformer_s2421.393.412241
poolformer_s3630.865.002241
poolformerv2_m3656.088.812241
poolformerv2_m4873.3511.592241
poolformerv2_s1211.891.832241
poolformerv2_s2421.343.422241
poolformerv2_s3630.795.012241

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
caformer_b36.sail_in1k22485.5022241000apache-2.0timm
caformer_b36.sail_in1k_38438486.4003841000apache-2.0timm
caformer_b36.sail_in22k224--21841apache-2.0timm
caformer_b36.sail_in22k_ft_in1k22487.4502241000apache-2.0timm
caformer_b36.sail_in22k_ft_in1k_38438488.0583841000apache-2.0timm
caformer_m36.sail_in1k22485.2422241000apache-2.0timm
caformer_m36.sail_in1k_38438486.1643841000apache-2.0timm
caformer_m36.sail_in22k224--21841apache-2.0timm
caformer_m36.sail_in22k_ft_in1k22486.6062241000apache-2.0timm
caformer_m36.sail_in22k_ft_in1k_38438487.4703841000apache-2.0timm
caformer_s18.sail_in1k22483.6642241000apache-2.0timm
caformer_s18.sail_in1k_38438485.0363841000apache-2.0timm
caformer_s18.sail_in22k224--21841apache-2.0timm
caformer_s18.sail_in22k_ft_in1k22484.0922241000apache-2.0timm
caformer_s18.sail_in22k_ft_in1k_38438485.4423841000apache-2.0timm
caformer_s36.sail_in1k22484.5282241000apache-2.0timm
caformer_s36.sail_in1k_38438485.7623841000apache-2.0timm
caformer_s36.sail_in22k224--21841apache-2.0timm
caformer_s36.sail_in22k_ft_in1k22485.7802241000apache-2.0timm
caformer_s36.sail_in22k_ft_in1k_38438486.8603841000apache-2.0timm
convformer_b36.sail_in1k22484.8262241000apache-2.0timm
convformer_b36.sail_in1k_38438485.7703841000apache-2.0timm
convformer_b36.sail_in22k224--21841apache-2.0timm
convformer_b36.sail_in22k_ft_in1k22486.9922241000apache-2.0timm
convformer_b36.sail_in22k_ft_in1k_38438487.6063841000apache-2.0timm
convformer_m36.sail_in1k22484.4862241000apache-2.0timm
convformer_m36.sail_in1k_38438485.5803841000apache-2.0timm
convformer_m36.sail_in22k224--21841apache-2.0timm
convformer_m36.sail_in22k_ft_in1k22486.1522241000apache-2.0timm
convformer_m36.sail_in22k_ft_in1k_38438486.8683841000apache-2.0timm
convformer_s18.sail_in1k22482.9682241000apache-2.0timm
convformer_s18.sail_in1k_38438484.3923841000apache-2.0timm
convformer_s18.sail_in22k224--21841apache-2.0timm
convformer_s18.sail_in22k_ft_in1k22483.7682241000apache-2.0timm
convformer_s18.sail_in22k_ft_in1k_38438485.0043841000apache-2.0timm
convformer_s36.sail_in1k22484.0682241000apache-2.0timm
convformer_s36.sail_in1k_38438485.3803841000apache-2.0timm
convformer_s36.sail_in22k224--21841apache-2.0timm
convformer_s36.sail_in22k_ft_in1k22485.4202241000apache-2.0timm
convformer_s36.sail_in22k_ft_in1k_38438486.3743841000apache-2.0timm
poolformer_m36.sail_in1k22482.1042241000apache-2.0timm
poolformer_m48.sail_in1k22482.4622241000apache-2.0timm
poolformer_s12.sail_in1k22477.2382241000apache-2.0timm
poolformer_s24.sail_in1k22480.2942241000apache-2.0timm
poolformer_s36.sail_in1k22481.4282241000apache-2.0timm
poolformerv2_m36.sail_in1k22482.2142241000apache-2.0timm
poolformerv2_m48.sail_in1k22482.6122241000apache-2.0timm
poolformerv2_s12.sail_in1k22478.0082241000apache-2.0timm
poolformerv2_s24.sail_in1k22480.7462241000apache-2.0timm
poolformerv2_s36.sail_in1k22481.5762241000apache-2.0timm
Update on GitHub