VGGForImageClassification
PretrainedModelClassificationHeadMixinVGGForImageClassification(config: VGGConfig)VGG with two 4096-dim fully-connected layers and a linear classifier.
Combines a VGG convolutional backbone with the standard
paper-cited classifier head: FC6 (512·7·7 = 25088 → 4096), FC7
(4096 → 4096), and a final linear projection to
config.num_classes (default 1000 for ImageNet-1k).
lucid.nn.Dropout with config.dropout (0.5 in the
paper) is applied after both ReLU activations. When labels are
supplied to forward, cross-entropy loss is returned
alongside the logits.
Parameters
configVGGConfig*_cls factory functions
(vgg_11_cls, vgg_16_cls, …) for paper-cited
configurations.Attributes
configVGGConfigfeatures, avgpoolVGG.fc6, fc7nn.Lineardrop6, drop7nn.Dropoutconfig.dropout.classifiernn.Modulenum_classes.Notes
From Simonyan & Zisserman, ICLR 2015. The two 4096-dim FC layers
dominate the parameter count: VGG-16 has 138 M parameters total, of
which roughly 124 M sit in FC6 + FC7. This is a recognised
weakness — almost all later architectures (ResNet, DenseNet, …)
replace the giant FC head with a single lucid.nn.Linear
after lucid.nn.AdaptiveAvgPool2d to slash the parameter
cost. VGG-16 reaches a top-5 ImageNet validation error of 7.3% and
VGG-19 reaches 7.5%.
Examples
Run inference on a 224x224 RGB batch:
>>> import lucid
>>> from lucid.models.vision.vgg import vgg_16_cls
>>> model = vgg_16_cls()
>>> x = lucid.randn(2, 3, 224, 224)
>>> out = model(x)
>>> out.logits.shape
(2, 1000)Used by 2
Constructors
1Instance methods
1forward(x: Tensor, labels: Tensor | None = None)