Skip to content
fn

mobilenet_v2_cls

→MobileNetV2ForImageClassification3.5M
mobilenet_v2_cls(pretrained: bool | str = False, weights: MobileNetV2Weights | None = None, overrides: object = {})

MobileNet-v2 image classifier at width multiplier α=1.0\alpha = 1.0.

Builds a MobileNetV2ForImageClassification with the canonical paper topology (Sandler et al., 2018) followed by global average pooling and a linear projection to config.num_classes (default 1000 for ImageNet-1k). Approximately 3.5M parameters and 72.0% ImageNet-1k top-1 accuracy.

Model Size

Parameters

pretrainedbool or str= False
Pretrained-weight selector. False → random init; True → the DEFAULT tag (MobileNetV2Weights.IMAGENET1K_V1); a tag string (e.g. "IMAGENET1K_V1") → that specific checkpoint. Mutually exclusive with weights (which wins if both are given).
weights(MobileNetV2Weights, optional, keyword - only)= None
Explicit weights enum member, e.g. MobileNetV2Weights.IMAGENET1K_V1. Takes precedence over pretrained.
**overridesobject= {}
Keyword overrides forwarded into MobileNetV2Config (typically num_classes to retarget the classifier). Note: overriding num_classes away from the checkpoint's class count makes pretrained loading fail the strict key/shape check — load with a matching head, then call reset_classifier.

Returns

MobileNetV2ForImageClassification

Classifier with the MobileNet-v2 (α=1.0\alpha = 1.0) configuration applied (or with overrides merged on top of it), optionally initialised from pretrained weights.

Notes

See Sandler et al., "MobileNetV2: Inverted Residuals and Linear Bottlenecks", CVPR 2018 (arXiv:1801.04381), Table 4. Pretrained weights are converted from reference_vision's MobileNet_V2_Weights and hosted on the Hugging Face Hub under lucid-dl/mobilenet-v2.

Examples

>>> import lucid
>>> from lucid.models.vision.mobilenet_v2 import mobilenet_v2_cls
>>> model = mobilenet_v2_cls(num_classes=10)
>>> x = lucid.randn(2, 3, 224, 224)
>>> out = model(x)
>>> out.logits.shape
(2, 10)
Load ImageNet-pretrained weights:
>>> model = mobilenet_v2_cls(pretrained=True)            # DEFAULT tag
>>> from lucid.models.vision.mobilenet_v2 import MobileNetV2Weights
>>> model = mobilenet_v2_cls(weights=MobileNetV2Weights.IMAGENET1K_V1)

Used by 1