class
MobileNetV4ForImageClassification
extends
ImageClassificationModelClassificationHeadMixinMobileNetV4ForImageClassification(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 convolution to 1280 channels with normalisation
and activation, and finally projected to the classes,
Pooling before the widest layer is the MobileNet-v3 head redesign; the normalisation after that layer is new in v4.
Parameters
configMobileNetV4ConfigArchitecture spec. Use the
*_cls factories
(mobilenet_v4_conv_small_cls and siblings) for the paper's
variants.Attributes
configMobileNetV4ConfigThe config that built this model.
conv_stem, bn1, act, blocksnn.ModuleThe same trunk as
MobileNetV4, held directly on the
classifier so the parameter names match the released checkpoints.global_poolnn.AdaptiveAvgPool2dGlobal average pool to .
conv_headnn.Conv2dBias-free convolution, 960 → 1280 channels.
norm_headnn.BatchNorm2dNormalisation of the 1280-channel head features.
act_headnn.ModuleHead activation (the variant's activation).
head_dropnn.DropoutDropout with probability
config.dropout.classifiernn.LinearFinal 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
1Instance methods
1forward(x: Tensor, labels: Tensor | None = None)