MaxViTConfig
ModelConfigMaxViTConfig(num_classes: int = 1000, in_channels: int = 3, depths: tuple[int, ...] = (2, 2, 5, 2), dims: tuple[int, ...] = (64, 128, 256, 512), window_size: int = 7, num_heads: int = 32, mlp_ratio: float = 4.0, stem_width: int | None = None)Configuration dataclass for every MaxViT variant.
MaxViTConfig is an immutable container that fully specifies the
architecture of a MaxViT (Tu et al., 2022). MaxViT combines an
MBConv convolutional stage with two complementary sparse
self-attention mechanisms — block attention and grid attention
— in every MaxViT block, realising dense local + dense global
self-attention at linear complexity in the number of tokens.
Parameters
num_classesint= 10001000 (ImageNet-1k).in_channelsint= 33 (RGB).depthstuple of int= (2, 2, 5, 2)(2, 2, 5, 2) (MaxViT-Tiny).dimstuple of int= (64, 128, 256, 512)(64, 128, 256, 512) (MaxViT-Tiny).window_sizeint= 77.num_headsint= 32head_dim
to 32 and derives num_heads = dim / 32 per stage; this
field is informational. Defaults to 32.mlp_ratiofloat= 4.04.0.stem_widthint or None= Nonedims[0]: Tiny/Large keep stem_width == dims[0] while Small/Base use a narrower stem_width = 64 and
let the first block's shortcut expand to dims[0]. None
(the default) falls back to dims[0].Attributes
model_typeClassVar[str]"maxvit" used by the model registry.Notes
The canonical variants registered as factory functions in
lucid.models.vision.maxvit are:
================ ================== ==================== Variant depths dims ================ ================== ==================== MaxViT-Tiny (2, 2, 5, 2) (64, 128, 256, 512) MaxViT-Small (2, 2, 5, 2) (96, 192, 384, 768) MaxViT-Base (2, 6, 14, 2) (96, 192, 384, 768) MaxViT-Large (2, 6, 14, 2) (128, 256, 512, 1024) MaxViT-XLarge (2, 6, 14, 2) (192, 384, 768, 1536) ================ ================== ====================
Reference: Zhengzhong Tu et al., "MaxViT: Multi-Axis Vision Transformer", ECCV 2022, arXiv:2204.01697.
Examples
Build a MaxViT-Tiny configuration with a 100-class head:
>>> from lucid.models.vision.maxvit import MaxViTConfig
>>> cfg = MaxViTConfig(num_classes=100)
>>> cfg.depths, cfg.dims, cfg.window_size, cfg.num_classes
((2, 2, 5, 2), (64, 128, 256, 512), 7, 100)