Skip to content
class

AlexNet

extendsPretrainedModelBackboneMixin
AlexNet(config: AlexNetConfig)

AlexNet feature-extracting backbone (no fully-connected head).

Implements the single-stream, no-LRN derivation from Krizhevsky, "One weird trick for parallelizing convolutional neural networks", arXiv:1404.5997 — the canonical re-derivation of the original Krizhevsky, Sutskever & Hinton 2012 two-GPU model into a single merged stream with adjusted channel widths (64,192,384,256,256)(64, 192, 384, 256, 256). Five convolutions (11×1111\times11 stride-4 first; 5×55\times5 second; three 3×33\times3), each followed by ReLU, with overlapping 3×33\times3 stride-2 max-pools after blocks 1, 2, and 5. A final lucid.nn.AdaptiveAvgPool2d collapses the feature map to 6×66\times6 regardless of input resolution.

Parameters

Frozen architecture spec. Use alexnet for the paper-cited single-stream configuration; pass a custom config to switch input channel count or to retarget the classifier variant.

Attributes

Stored copy of the config that built this model.
The five conv blocks (Conv → ReLU → optional MaxPool) — see _build_features for the exact ordering.
Global pool down to a 6×66\times6 spatial map so the backbone produces a fixed-size feature regardless of input resolution.
feature_infolist[FeatureInfo]
Per-stage descriptor (channels + reduction factor) exposed via BackboneMixin for downstream decoder modules.

Notes

From Krizhevsky 2014, §3. AlexNet's contribution to deep-learning history is threefold: the rectified linear unit ϕ(x)=max⁡(0,x)\phi(x) = \max(0, x) replaced saturating nonlinearities and cut training time by several factors; dropout with p=0.5p=0.5 regularised the 4096-dim fully-connected layers against overfitting on a 1.2 M-image dataset; and heavy data augmentation (random crop, horizontal flip, AlexNet-style PCA colour jitter) was made central to the recipe. The 2012 paper additionally used local response normalisation between blocks 1-2; this implementation omits it, following the reference implementation (the 2014 paper does not discuss normalisation). The classifier variant has 61,100,840 parameters, of which 58.6 M sit in the three fully-connected layers; the two 4096-dim hidden ones alone account for 54.5 M. With the original ImageNet-1k training recipe the single-stream AlexNet reaches roughly 56.5% top-1 / 79.1% top-5 on the validation split.

Examples

Build the backbone and run a single forward pass:
>>> import lucid
>>> from lucid.models.vision.alexnet import alexnet
>>> backbone = alexnet()
>>> x = lucid.randn(2, 3, 224, 224)
>>> out = backbone(x)
>>> out.last_hidden_state.shape   # (B, 256, 6, 6)
(2, 256, 6, 6)
Inspect per-stage feature descriptors:
>>> info = backbone.feature_info
>>> [(fi.stage, fi.num_channels, fi.reduction) for fi in info[:2]]
[(1, 64, 4), (2, 192, 8)]

Used by 2

Constructors

1
dunder

__init__

→None
__init__(config: AlexNetConfig)

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.