EfficientFormer
PretrainedModelBackboneMixinEfficientFormer(config: EfficientFormerConfig)EfficientFormer backbone (Li et al., 2022).
EfficientFormer is a mobile-grade vision backbone designed so that its on-device latency, rather than its FLOP count, matches MobileNet on the same hardware while retaining transformer-level accuracy. The trunk has four stages preceded by a two stride-2 convolutional stem. Stages 1-3 are MetaFormer-style pooling blocks operating in layout — no reshape, no self-attention:
with initialised to (CaiT-style layer scale). The last stage switches its trailing blocks to standard multi-head self-attention with a learned relative-position bias on the now-tiny token grid.
forward_features returns the mean-pooled
feature.
Parameters
configEfficientFormerConfigdepths, embed_dims,
mlp_ratios, num_vit, drop_path_rate,
layer_scale_init, in_channels, and num_classes.
See EfficientFormerConfig.Attributes
stem_Stemstagesnn.ModuleListnormnn.LayerNormfeature_infolist[FeatureInfo]Notes
Reference: Yanyu Li et al., "EfficientFormer: Vision Transformers at MobileNet Speed", NeurIPS 2022, arXiv:2206.01191.
Examples
Build an EfficientFormer-L1 backbone and run a forward pass:
>>> import lucid
>>> from lucid.models.vision.efficientformer import (
... EfficientFormer, EfficientFormerConfig,
... )
>>> model = EfficientFormer(EfficientFormerConfig())
>>> x = lucid.randn(1, 3, 224, 224)
>>> feat = model.forward_features(x)
>>> feat.shape # (B, embed_dims[-1])
(1, 448)