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 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:
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
configMobileNetV2Configmobilenet_v2, mobilenet_v2_075) for
paper-cited width-multiplier variants.Attributes
configMobileNetV2Configfeaturesnn.Sequentialconfig.width_mult.avgpoolnn.AdaptiveAvgPool2d(B, C, 1, 1).feature_ infolist[FeatureInfo]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 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
1Instance methods
2forward(x: Tensor)Override in subclasses to define the computation.
Run the backbone's feature-extraction pass.
Parameters
(B, C, H, W).Returns
TensorFeature 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.