Skip to content
class

MobileNet

extendsPretrainedModelBackboneMixin
MobileNet(config: MobileNetConfig)

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

Implements the depthwise-separable convolutional topology from Howard et al., "MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications", arXiv:1704.04861, 2017. The network alternates a per-channel 3×33 \times 3 depthwise convolution with a 1×11 \times 1 pointwise convolution that mixes channels — a factorisation that reduces FLOPs by roughly 1/N+1/DK21/N + 1/D_K^2 relative to a standard DK×DKD_K \times D_K convolution, an 8–9× saving for the 3×33 \times 3 case.

The body is a 3×3 stem (stride 2) followed by 13 depthwise + pointwise blocks producing feature maps at strides 2, 4, 8, 16, and 32 relative to the input. A global average pool collapses the final spatial map to a single 1×1 descriptor. This class is the canonical feature extractor used by detection / segmentation heads when deployed on mobile / embedded devices.

Parameters

Frozen architecture spec. Use the factory functions (mobilenet, mobilenet_075, …) for paper-cited width-multiplier variants.

Attributes

Stored copy of the config that built this model.
Stem 3×33 \times 3 conv (stride 2) followed by 13 depthwise+pointwise blocks; 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

Each depthwise-separable block computes

PW(σ(BN(DW3×3(x))))    →    σ(BN( ⋅ )),\mathrm{PW}\big(\sigma(\mathrm{BN}(\mathrm{DW}_{3\times3}(x)))\big) \;\;\to\;\; \sigma(\mathrm{BN}(\,\cdot\,)),

where DW3×3\mathrm{DW}_{3\times3} is the per-channel 3×33 \times 3 spatial filter (groups=in_channels), PW\mathrm{PW} is the 1×11 \times 1 channel-mixing convolution, and σ\sigma is ReLU6 (see _dw_pw for why the references diverge from the paper's plain ReLU here). The width multiplier α∈(0,1]\alpha \in (0, 1] uniformly scales every channel count so that the same architecture can target sub-mW edge devices (α=0.25\alpha = 0.25) up to full desktop deployment (α=1.0\alpha = 1.0).

Examples

Build a MobileNet-v1 backbone and run a forward pass:
>>> import lucid
>>> from lucid.models.vision.mobilenet import mobilenet
>>> backbone = mobilenet()
>>> x = lucid.randn(2, 3, 224, 224)
>>> out = backbone(x)
>>> out.last_hidden_state.shape
(2, 1024, 7, 7)
Inspect the per-stage feature map descriptors for FPN integration:
>>> info = backbone.feature_info
>>> [(fi.stage, fi.num_channels, fi.reduction) for fi in info]
[(1, 64, 2), (2, 128, 4), (3, 256, 8), (4, 512, 16), (5, 1024, 32)]

Used by 2

Constructors

1
dunder

__init__

→None
__init__(config: MobileNetConfig)

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.