mobilenet_v2_cls(pretrained: bool | str = False, weights: MobileNetV2Weights | None = None, overrides: object = {})MobileNet-v2 image classifier at width multiplier .
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= FalsePretrained-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).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
MobileNetV2ForImageClassificationClassifier with the MobileNet-v2 ()
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 torchvision'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)