Skip to content
class

MobileNetV4

extendsPretrainedModelBackboneMixin
MobileNetV4(config: MobileNetV4Config)

MobileNet-v4 feature-extracting backbone (no classification head).

Implements the searched architectures of Qin et al., "MobileNetV4: Universal Models for the Mobile Ecosystem", ECCV 2024 (arXiv:2404.10518). The trunk is a stride-2 stem followed by five stages built from the Universal Inverted Bottleneck (UIB), whose two optional depthwise convolutions let the architecture search pick an inverted bottleneck, a ConvNeXt-like block, an FFN or the new ExtraDW block at every position; a fused inverted bottleneck opens the medium and large models, and the hybrid variants interleave Mobile MQA attention blocks into the two deepest stages. The last stage is a 1×11 \times 1 convolution widening the stride-32 map to 960 channels.

Parameters

Architecture spec. Use the factory functions (mobilenet_v4_conv_small, mobilenet_v4_conv_medium, mobilenet_v4_conv_large, mobilenet_v4_hybrid_medium, mobilenet_v4_hybrid_large) for the paper's variants.

Attributes

The config that built this model.
conv_stemnn.Conv2d
Stride-2 3×33 \times 3 stem convolution (24 or 32 channels).
Stem normalisation.
Stem activation (ReLU, or GELU for Hybrid-Large).
Five stage Sequential containers; stage ii ends at stride 2i+22^{i+2} for i≤3i \le 3, and stage 4 is the 960-channel 1×11 \times 1 widening layer.
feature_infolist[FeatureInfo]
One entry per output resolution (strides 4, 8, 16 and 32); the stride-32 entry reports the 960 channels that forward_features returns.

Notes

The UIB computes

y=x+γ⊙P(Dmid(E(Dstart(x)))),y = x + \gamma \odot P\bigl(D_{\mathrm{mid}}(E(D_{\mathrm{start}}(x)))\bigr),

with EE the pointwise expansion (norm + activation), PP the linear pointwise projection, each DD an optional depthwise convolution and γ\gamma a per-channel layer scale present only in the hybrid variants. The residual is used whenever the block keeps both resolution and width.

Examples

>>> import lucid
>>> from lucid.models.vision.mobilenet_v4 import mobilenet_v4_conv_small
>>> backbone = mobilenet_v4_conv_small().eval()
>>> out = backbone(lucid.randn(1, 3, 224, 224))
>>> out.last_hidden_state.shape
(1, 960, 7, 7)
>>> [f.reduction for f in backbone.feature_info]
[4, 8, 16, 32]

Used by 2

Constructors

1
dunder

__init__

→None
__init__(config: MobileNetV4Config)

Instance methods

2
fn

forward_features

→Tensor
forward_features(x: Tensor)

Run the backbone's feature-extraction pass.

Parameters

Input image batch, shape (B, C, H, W).

Returns

Tensor

Feature map at the deepest stage. Concrete subclasses may additionally stash earlier stages on the instance so multi-stage consumers can fetch them.

Examples

The map returned is the one feature_info lists last, so a
neck can size itself from that entry without running the model.
>>> import lucid
>>> from lucid.models import create_model
>>> backbone = create_model("resnet_18").eval()
>>> last = backbone.feature_info[-1]
>>> last.num_channels, last.reduction
(512, 32)
>>> backbone.forward_features(lucid.randn((1, 3, 64, 96))).shape
(1, 512, 2, 3)
Each side is divided by the advertised reduction on its own, so
a non-square input keeps its aspect ratio.