Skip to content
class

MobileNetV4ForImageClassification

extendsImageClassificationModelClassificationHeadMixin
MobileNetV4ForImageClassification(config: MobileNetV4Config)

MobileNet-v4 image classifier with the post-pool head.

Runs the MobileNetV4 trunk and the head of the paper's tables: the 960-channel map is globally average-pooled first, then widened by a 1×11 \times 1 convolution to 1280 channels with normalisation and activation, and finally projected to the classes,

AvgPool⁡→Conv⁡1×11280→BN⁡→σ→Dropout⁡→Linear⁡.\operatorname{AvgPool} \to \operatorname{Conv}_{1\times1}^{1280} \to \operatorname{BN} \to \sigma \to \operatorname{Dropout} \to \operatorname{Linear}.

Pooling before the widest layer is the MobileNet-v3 head redesign; the normalisation after that layer is new in v4.

Parameters

Architecture spec. Use the *_cls factories (mobilenet_v4_conv_small_cls and siblings) for the paper's variants.

Attributes

The config that built this model.
conv_stem, bn1, act, blocksnn.Module
The same trunk as MobileNetV4, held directly on the classifier so the parameter names match the released checkpoints.
Global average pool to 1×11 \times 1.
conv_headnn.Conv2d
Bias-free 1×11 \times 1 convolution, 960 → 1280 channels.
Normalisation of the 1280-channel head features.
act_headnn.Module
Head activation (the variant's activation).
head_dropnn.Dropout
Dropout with probability config.dropout.
classifiernn.Linear
Final 1280 → config.num_classes projection.

Notes

When labels are passed to forward, the categorical cross-entropy against the logits is returned as loss.

Examples

>>> import lucid
>>> from lucid.models.vision.mobilenet_v4 import mobilenet_v4_conv_small_cls
>>> model = mobilenet_v4_conv_small_cls().eval()
>>> out = model(lucid.randn(2, 3, 224, 224))
>>> out.logits.shape
(2, 1000)
Retarget the head for a 10-class task:
>>> model = mobilenet_v4_conv_small_cls(num_classes=10).eval()
>>> model(lucid.randn(1, 3, 224, 224)).logits.shape
(1, 10)

Used by 2

Constructors

1
dunder

__init__

→None
__init__(config: MobileNetV4Config)

Instance methods

1