Skip to content
class

MobileNetV2

extendsPretrainedModelBackboneMixin
MobileNetV2(config: MobileNetV2Config)

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

Implements the inverted-residual / linear-bottleneck topology from Sandler et al., "MobileNetV2: Inverted Residuals and Linear Bottlenecks", CVPR 2018 (arXiv:1801.04381). Each block expands a low-dimensional input up by an integer expand_ratio, runs a depthwise 3×33 \times 3 convolution in the wider interior space, then projects back to a narrow bottleneck — without a final non-linearity (the "linear bottleneck"). When stride and channel counts match, an identity shortcut is added around the whole block:

y=x+Proj(DW(Expand(x))).y = x + \mathrm{Proj}\big( \mathrm{DW}\big( \mathrm{Expand}(x) \big) \big).

The body is a 3×3 stem (stride 2) followed by seven inverted-residual stages and a final 1×1 head expansion to 1280 channels. A global average pool collapses the final feature map to a single 1×1 descriptor.

Parameters

Frozen architecture spec. Use the factory functions (mobilenet_v2, mobilenet_v2_075) for paper-cited width-multiplier variants.

Attributes

Stored copy of the config that built this model.
Stem + seven inverted-residual stages + 1×1 head expansion. Channel counts scale with config.width_mult.
Global average pool collapsing the final feature map to (B, C, 1, 1).
feature_infolist[FeatureInfo]
Per-stage descriptor (channels + reduction factor) exposed via BackboneMixin for downstream FPN / decoder modules.

Notes

The inverted-residual block is the inverse of the classical bottleneck shape: instead of wide → narrow → wide, it does narrow → wide → narrow, with the residual connection on the narrow (low-dimensional) tensor. Combined with the linear bottleneck (no ReLU on the projection), this preserves the representational capacity of the narrow channels while letting the wide interior use ReLU6 freely. The result is roughly 30%30\% fewer parameters and FLOPs than MobileNet-v1 at comparable accuracy.

Examples

Build a MobileNet-v2 backbone and run a forward pass:
>>> import lucid
>>> from lucid.models.vision.mobilenet_v2 import mobilenet_v2
>>> backbone = mobilenet_v2()
>>> x = lucid.randn(2, 3, 224, 224)
>>> out = backbone(x)
>>> out.last_hidden_state.shape
(2, 1280, 1, 1)

Used by 2

Constructors

1
dunder

__init__

→None
__init__(config: MobileNetV2Config)

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.