opensi·si

timm/models/metaformer.py ·

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

  • MetaFormer Is Actually What You Need for Vision
  • MetaFormer Baselines for Vision

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

Feature MetaFormer
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

표 (19행)
Architecture Params (M) GMACs Input size Pretrained weights
caformer_b36 98.75 23.22 224 5
caformer_m36 56.20 13.29 224 5
caformer_s18 26.34 4.13 224 5
caformer_s36 39.30 8.00 224 5
convformer_b36 99.88 22.69 224 5
convformer_m36 57.05 12.89 224 5
convformer_s18 26.77 3.96 224 5
convformer_s36 40.01 7.67 224 5
poolformer_m36 56.17 8.80 224 1
poolformer_m48 73.47 11.59 224 1
poolformer_s12 11.92 1.82 224 1
poolformer_s24 21.39 3.41 224 1
poolformer_s36 30.86 5.00 224 1
poolformerv2_m36 56.08 8.81 224 1
poolformerv2_m48 73.35 11.59 224 1
poolformerv2_s12 11.89 1.83 224 1
poolformerv2_s24 21.34 3.42 224 1
poolformerv2_s36 30.79 5.01 224 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.

표 (51행)
Weight Input size Top-1 (%) Eval size Classes License Hub
caformer_b36.sail_in1k 224 85.502 224 1000 apache-2.0 timm
caformer_b36.sail_in1k_384 384 86.400 384 1000 apache-2.0 timm
caformer_b36.sail_in22k 224 - - 21841 apache-2.0 timm
caformer_b36.sail_in22k_ft_in1k 224 87.450 224 1000 apache-2.0 timm
caformer_b36.sail_in22k_ft_in1k_384 384 88.058 384 1000 apache-2.0 timm
caformer_m36.sail_in1k 224 85.242 224 1000 apache-2.0 timm
caformer_m36.sail_in1k_384 384 86.164 384 1000 apache-2.0 timm
caformer_m36.sail_in22k 224 - - 21841 apache-2.0 timm
caformer_m36.sail_in22k_ft_in1k 224 86.606 224 1000 apache-2.0 timm
caformer_m36.sail_in22k_ft_in1k_384 384 87.470 384 1000 apache-2.0 timm
caformer_s18.sail_in1k 224 83.664 224 1000 apache-2.0 timm
caformer_s18.sail_in1k_384 384 85.036 384 1000 apache-2.0 timm
caformer_s18.sail_in22k 224 - - 21841 apache-2.0 timm
caformer_s18.sail_in22k_ft_in1k 224 84.092 224 1000 apache-2.0 timm
caformer_s18.sail_in22k_ft_in1k_384 384 85.442 384 1000 apache-2.0 timm
caformer_s36.sail_in1k 224 84.528 224 1000 apache-2.0 timm
caformer_s36.sail_in1k_384 384 85.762 384 1000 apache-2.0 timm
caformer_s36.sail_in22k 224 - - 21841 apache-2.0 timm
caformer_s36.sail_in22k_ft_in1k 224 85.780 224 1000 apache-2.0 timm
caformer_s36.sail_in22k_ft_in1k_384 384 86.860 384 1000 apache-2.0 timm
convformer_b36.sail_in1k 224 84.826 224 1000 apache-2.0 timm
convformer_b36.sail_in1k_384 384 85.770 384 1000 apache-2.0 timm
convformer_b36.sail_in22k 224 - - 21841 apache-2.0 timm
convformer_b36.sail_in22k_ft_in1k 224 86.992 224 1000 apache-2.0 timm
convformer_b36.sail_in22k_ft_in1k_384 384 87.606 384 1000 apache-2.0 timm
convformer_m36.sail_in1k 224 84.486 224 1000 apache-2.0 timm
convformer_m36.sail_in1k_384 384 85.580 384 1000 apache-2.0 timm
convformer_m36.sail_in22k 224 - - 21841 apache-2.0 timm
convformer_m36.sail_in22k_ft_in1k 224 86.152 224 1000 apache-2.0 timm
convformer_m36.sail_in22k_ft_in1k_384 384 86.868 384 1000 apache-2.0 timm
convformer_s18.sail_in1k 224 82.968 224 1000 apache-2.0 timm
convformer_s18.sail_in1k_384 384 84.392 384 1000 apache-2.0 timm
convformer_s18.sail_in22k 224 - - 21841 apache-2.0 timm
convformer_s18.sail_in22k_ft_in1k 224 83.768 224 1000 apache-2.0 timm
convformer_s18.sail_in22k_ft_in1k_384 384 85.004 384 1000 apache-2.0 timm
convformer_s36.sail_in1k 224 84.068 224 1000 apache-2.0 timm
convformer_s36.sail_in1k_384 384 85.380 384 1000 apache-2.0 timm
convformer_s36.sail_in22k 224 - - 21841 apache-2.0 timm
convformer_s36.sail_in22k_ft_in1k 224 85.420 224 1000 apache-2.0 timm
convformer_s36.sail_in22k_ft_in1k_384 384 86.374 384 1000 apache-2.0 timm
poolformer_m36.sail_in1k 224 82.104 224 1000 apache-2.0 timm
poolformer_m48.sail_in1k 224 82.462 224 1000 apache-2.0 timm
poolformer_s12.sail_in1k 224 77.238 224 1000 apache-2.0 timm
poolformer_s24.sail_in1k 224 80.294 224 1000 apache-2.0 timm
poolformer_s36.sail_in1k 224 81.428 224 1000 apache-2.0 timm
poolformerv2_m36.sail_in1k 224 82.214 224 1000 apache-2.0 timm
poolformerv2_m48.sail_in1k 224 82.612 224 1000 apache-2.0 timm
poolformerv2_s12.sail_in1k 224 78.008 224 1000 apache-2.0 timm
poolformerv2_s24.sail_in1k 224 80.746 224 1000 apache-2.0 timm
poolformerv2_s36.sail_in1k 224 81.576 224 1000 apache-2.0 timm

Source and license

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