Skip to content
class

EfficientNet

extendsPretrainedModelBackboneMixin
EfficientNet(config: EfficientNetConfig)

EfficientNet feature-extracting backbone (no classification head).

Implements the compound-scaled topology from Tan & Le, "EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks", ICML 2019 (arXiv:1905.11946). The baseline (B0) is a NAS-designed network of MBConv blocks — inverted-residual bottlenecks (MobileNet-v2 style) augmented with a squeeze-and-excitation module and the swish (SiLU) activation. Successive B-variants (B0 through B7) apply the paper's compound-scaling rule

d=αϕ,w=βϕ,r=γϕ,αβ2γ2≈2,d = \alpha^\phi, \quad w = \beta^\phi, \quad r = \gamma^\phi, \qquad \alpha \beta^2 \gamma^2 \approx 2,

to scale depth, width, and resolution jointly along a single coefficient ϕ\phi.

The body is a 3×3 stem (stride 2) followed by seven MBConv stages and a final 1×1 head expansion to round(1280 · width_mult) channels. Stochastic depth (drop_connect_rate) is applied linearly across blocks as a strong regulariser at large depth.

Parameters

Frozen architecture spec. Use the factory functions (efficientnet_b0 through efficientnet_b7) for paper-cited variants.

Attributes

Stored copy of the config that built this model.
Stem + seven MBConv stages + 1×1 head. Channel and depth counts scale with config.width_mult and config.depth_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 MBConv block applies

x→Expand1×1→DWk×k→SE→Proj1×1,x \to \mathrm{Expand}_{1\times1} \to \mathrm{DW}_{k\times k} \to \mathrm{SE} \to \mathrm{Proj}_{1\times1},

with a residual when stride is 1 and channel counts match. During training the residual branch is randomly dropped with probability drop_connect_rate * block_idx / (total - 1) — deeper blocks get a higher drop probability, matching the "deep network regularisation" recipe of stochastic depth.

Examples

Build an EfficientNet-B0 backbone and run a forward pass:
>>> import lucid
>>> from lucid.models.vision.efficientnet import efficientnet_b0
>>> backbone = efficientnet_b0()
>>> 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: EfficientNetConfig)

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.