AlexNetForImageClassification
PretrainedModelClassificationHeadMixinAlexNetForImageClassification(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
configAlexNetConfigalexnet_cls for the paper-cited
ImageNet-1k configuration (1000-class head, dropout=0.5).Attributes
configAlexNetConfigfeatures, avgpoolAlexNet; see that class
for shape semantics.fc6, fc7nn.Lineardrop6, drop7nn.Dropoutlucid.nn.Dropout layers applied after each ReLU in
the hidden FC stack, controlled by config.dropout.classifiernn.Modulenum_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
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
1Instance methods
1forward(x: Tensor, labels: Tensor | None = None)