Skip to content
class

GoogLeNetForImageClassification

extendsImageClassificationModelClassificationHeadMixin
GoogLeNetForImageClassification(config: GoogLeNetConfig)

GoogLeNet image classifier with optional auxiliary classifiers.

Combines the GoogLeNet backbone with a global-average-pool + lucid.nn.Dropout (config.dropout, default 0.4) + lucid.nn.Linear head producing config.num_classes logits, plus two optional auxiliary classifiers attached at Inception 4a (512-channel feature map) and Inception 4d (528-channel feature map). Auxiliary heads are evaluated only in training mode and only when config.aux_logits=True; their contributions to the loss are weighted 0.3 each, following the original paper.

Parameters

Architecture spec. Use googlenet_cls for the paper-cited configuration (auxiliary heads enabled). Pass aux_logits=False for an inference-only variant.

Attributes

Stored copy of the config that built this model.
conv1, conv2, conv3, maxpool1, maxpool2, inception3a, ...,
inception5b, maxpool3, maxpool4
Same backbone components as on GoogLeNet.
Final global average pool to 1×11\times1.
Dropout applied before the main classifier (p=config.dropout, 0.4 in the paper).
classifiernn.Module
Final linear projection 1024 → num_classes, built by ClassificationHeadMixin._build_classifier.
aux1, aux2nn.Module
Auxiliary classifiers (instances of _AuxClassifier) when config.aux_logits=True; otherwise lucid.nn.Identity placeholders.

Notes

From Szegedy et al., "Going Deeper with Convolutions", CVPR 2015, §5. The full training loss with auxiliary heads is

L=Lmain+0.3⋅Laux1+0.3⋅Laux2,\mathcal{L} = \mathcal{L}_{\text{main}} + 0.3 \cdot \mathcal{L}_{\text{aux1}} + 0.3 \cdot \mathcal{L}_{\text{aux2}},

each term being the standard categorical cross-entropy −1N∑nlog⁡softmax⁡(⋅)yn-\frac{1}{N} \sum_n \log \operatorname{softmax}(\cdot)_{y_n}. The 0.30.3 weighting compensates for the auxiliary heads being much shallower than the main classifier; at inference only the main branch is evaluated.

Examples

Inference path (no labels, auxiliary heads inactive):
>>> import lucid
>>> from lucid.models.vision.googlenet import googlenet_cls
>>> model = googlenet_cls().eval()
>>> x = lucid.randn(4, 3, 224, 224)
>>> out = model(x)
>>> out.logits.shape
(4, 1000)
>>> out.aux_logits1 is None
True
Training path (auxiliary heads active, labels provided):
>>> model = model.train()
>>> labels = lucid.tensor([0, 1, 2, 3], dtype=lucid.int64)
>>> out = model(x, labels=labels)
>>> out.aux_logits1.shape   # available during training
(4, 1000)

Used by 2

Constructors

1
dunder

__init__

→None
__init__(config: GoogLeNetConfig)

Instance methods

1
fn

forward

→GoogLeNetOutput
forward(x: Tensor, labels: Tensor | None = None)

Override in subclasses to define the computation.