Skip to content
class

AlexNetForImageClassification

extendsImageClassificationModelClassificationHeadMixin
AlexNetForImageClassification(config: AlexNetConfig)

AlexNet with two 4096-dim fully-connected layers and a linear classifier head.

Combines an AlexNet convolutional backbone with the paper-cited three-layer classifier head: FC6 (256·6·6 → 4096), FC7 (4096 → 4096), and the final linear projection to config.num_classes. lucid.nn.Dropout with config.dropout is applied after both ReLU activations in the hidden layers — these two large FC layers dominate the parameter count and are the main overfitting risk that dropout was introduced to control. When labels are supplied to forward, a cross-entropy loss is returned alongside the logits.

Parameters

Architecture spec. Use alexnet_cls for the paper-cited ImageNet-1k configuration (1000-class head, dropout=0.5).

Attributes

Stored copy of the config that built this model.
features, avgpool
Same backbone components as on AlexNet; see that class for shape semantics.
fc6, fc7nn.Linear
The two hidden fully-connected layers, both projecting to 4096 dimensions.
drop6, drop7nn.Dropout
lucid.nn.Dropout layers applied before each FC in the hidden FC stack, controlled by config.dropout.
classifiernn.Module
Final linear projection to num_classes, built by ClassificationHeadMixin._build_classifier.

Notes

From Krizhevsky 2014 (single-stream re-derivation of NIPS 2012). The two 4096-dim hidden layers alone account for roughly 54.5 M of the network's 61.1 M parameters — the original rationale for dropout, which randomly zeros out half of each FC activation during training so that no individual co-adapted neuron is critical for any single decision. Loss is the standard cross-entropy

L=−1N∑n=1Nlog⁡softmax⁡(logitsn) yn.\mathcal{L} = -\frac{1}{N} \sum_{n=1}^{N} \log \operatorname{softmax}(\text{logits}_n)_{\,y_n}.

Examples

Run inference on a batch of 224x224 RGB images:
>>> import lucid
>>> from lucid.models.vision.alexnet import alexnet_cls
>>> model = alexnet_cls()
>>> x = lucid.randn(4, 3, 224, 224)
>>> out = model(x)
>>> out.logits.shape
(4, 1000)
>>> out.loss is None
True
Compute a training loss given integer labels:
>>> labels = lucid.tensor([0, 1, 2, 3], dtype=lucid.int64)
>>> out = model(x, labels=labels)
>>> out.loss.shape
()

Used by 2

Constructors

1
dunder

__init__

→None
__init__(config: AlexNetConfig)

Instance methods

1