timm documentation

MLP-Mixer, ResMLP and gMLP

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

MLP-Mixer, ResMLP and gMLP

Category: MLP · Code: timm/models/mlp_mixer.py · Architectures: 15 · Pretrained weights: 19 (14 with ImageNet-1k results)

All-MLP architectures that alternate token mixing across patches with channel mixing: MLP-Mixer, ResMLP and gMLP (gating with a spatial projection). The module docstring notes the gMLP implementation is not verified.

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

Model API support

FeatureMlpMixer
features_only=True feature maps✓ (strides 16, 16, 16)
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 (MlpMixer with gmlp_ti16_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
gmixer_12_22412.702.672240
gmixer_24_22424.725.282241
gmlp_b16_22473.0815.782240
gmlp_s16_22419.424.422241
gmlp_ti16_2245.871.342240
mixer_b16_22459.8812.622244
mixer_b32_22460.293.242240
mixer_l16_224208.2044.602242
mixer_l32_224206.9411.272240
mixer_s16_22418.533.792240
mixer_s32_22419.101.002240
resmlp_12_22415.353.012243
resmlp_24_22430.025.962243
resmlp_36_22444.698.912242
resmlp_big_24_224129.14100.232243

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.

fb tags

WeightInput sizeTop-1 (%)Eval sizeClassesLicenseHub
resmlp_12_224.fb_dino224--1000apache-2.0timm
resmlp_12_224.fb_distilled_in1k22477.9482241000apache-2.0timm
resmlp_12_224.fb_in1k22476.6602241000apache-2.0timm
resmlp_24_224.fb_dino224--1000apache-2.0timm
resmlp_24_224.fb_distilled_in1k22480.7662241000apache-2.0timm
resmlp_24_224.fb_in1k22479.3802241000apache-2.0timm
resmlp_36_224.fb_distilled_in1k22481.1502241000apache-2.0timm
resmlp_36_224.fb_in1k22479.7722241000apache-2.0timm
resmlp_big_24_224.fb_distilled_in1k22483.5942241000apache-2.0timm
resmlp_big_24_224.fb_in1k22481.0342241000apache-2.0timm
resmlp_big_24_224.fb_in22k_ft_in1k22484.4142241000apache-2.0timm

goog tags

WeightInput sizeTop-1 (%)Eval sizeClassesLicenseHub
mixer_b16_224.goog_in21k224--21843apache-2.0timm
mixer_b16_224.goog_in21k_ft_in1k22476.6162241000apache-2.0timm
mixer_l16_224.goog_in21k224--21843apache-2.0timm
mixer_l16_224.goog_in21k_ft_in1k22472.0842241000apache-2.0timm

miil tags

WeightInput sizeTop-1 (%)Eval sizeClassesLicenseHub
mixer_b16_224.miil_in21k224--11221apache-2.0timm
mixer_b16_224.miil_in21k_ft_in1k22482.3142241000apache-2.0timm

ra3 tags

WeightInput sizeTop-1 (%)Eval sizeClassesLicenseHub
gmixer_24_224.ra3_in1k22478.0482241000apache-2.0timm
gmlp_s16_224.ra3_in1k22479.6522241000apache-2.0timm

Citation

@article{tolstikhin2021,
  title={MLP-Mixer: An all-MLP Architecture for Vision},
  author={Tolstikhin, Ilya and Houlsby, Neil and Kolesnikov, Alexander and Beyer, Lucas and Zhai, Xiaohua and Unterthiner,
        Thomas and Yung, Jessica and Keysers, Daniel and Uszkoreit, Jakob and Lucic, Mario and Dosovitskiy, Alexey},
  journal={arXiv preprint arXiv:2105.01601},
  year={2021}
}

@misc{touvron2021resmlp,
      title={ResMLP: Feedforward networks for image classification with data-efficient training},
      author={Hugo Touvron and Piotr Bojanowski and Mathilde Caron and Matthieu Cord and Alaaeldin El-Nouby and
        Edouard Grave and Armand Joulin and Gabriel Synnaeve and Jakob Verbeek and Hervé Jégou},
      year={2021},
      eprint={2105.03404},
}

@misc{liu2021pay,
      title={Pay Attention to MLPs},
      author={Hanxiao Liu and Zihang Dai and David R. So and Quoc V. Le},
      year={2021},
      eprint={2105.08050},
}
Update on GitHub