GoogLeNetForImageClassification
PretrainedModelClassificationHeadMixinGoogLeNetForImageClassification(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
configGoogLeNetConfiggooglenet_cls for the
paper-cited configuration (auxiliary heads enabled). Pass
aux_logits=False for an inference-only variant.Attributes
configGoogLeNetConfigconv1, conv2, conv3, maxpool1, maxpool2, inception3a, ...,inception5b, maxpool3, maxpool4GoogLeNet.avgpoolnn.AdaptiveAvgPool2ddropnn.Dropoutp=config.dropout, 0.4 in the paper).classifiernn.Modulenum_classes, built by
ClassificationHeadMixin._build_classifier.aux1, aux2nn.Module_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
each term being the standard categorical cross-entropy . The 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
1Instance methods
1forward(x: Tensor, labels: Tensor | None = None)