Skip to content
class

EfficientNetForImageClassification

extendsImageClassificationModelClassificationHeadMixin
EfficientNetForImageClassification(config: EfficientNetConfig)

EfficientNet with global-average-pooled linear classification head.

Combines an EfficientNet backbone with the standard ImageNet classification head: an lucid.nn.AdaptiveAvgPool2d to pool every spatial location into a single feature vector, a lucid.nn.Dropout (probability config.dropout, scaled per B-variant from 0.2 at B0 up to 0.5 at B7), and a lucid.nn.Linear projection to config.num_classes logits. When labels are supplied to forward, a cross-entropy loss is computed and returned alongside the logits.

Parameters

Architecture spec. Use the *_cls factory functions (efficientnet_b0_cls through efficientnet_b7_cls) for paper-cited configurations.

Attributes

Stored copy of the config that built this model.
Same MBConv stack as on EfficientNet.
Global average pool collapsing the final feature map to 1 × 1.
Dropout layer (probability config.dropout) applied before the linear classifier.
classifiernn.Linear
Linear projection from round(1280 · width_mult) to config.num_classes.

Notes

The classification flow is

logits=W Drop⁡ ⁣(GAP⁡( backbone(x) ))+b,\text{logits} = W \,\operatorname{Drop}\!\left( \operatorname{GAP}(\,\mathrm{backbone}(x)\,) \right) + b,

with cross-entropy loss computed when labels is provided.

Examples

Run inference on a batch of 224×224 RGB images:
>>> import lucid
>>> from lucid.models.vision.efficientnet import efficientnet_b0_cls
>>> model = efficientnet_b0_cls()
>>> x = lucid.randn(4, 3, 224, 224)
>>> out = model(x)
>>> out.logits.shape
(4, 1000)
Retarget B3 to CIFAR-10:
>>> from lucid.models.vision.efficientnet import efficientnet_b3_cls
>>> model = efficientnet_b3_cls(num_classes=10)
>>> model.config.num_classes
10

Used by 2

Constructors

1
dunder

__init__

→None
__init__(config: EfficientNetConfig)

Instance methods

1