Skip to content
class

InceptionV4ForImageClassification

extendsImageClassificationModelClassificationHeadMixin
InceptionV4ForImageClassification(config: InceptionV4Config)

Inception-v4 image classifier (trunk + GAP + dropout + linear).

Adds the paper's head to the InceptionV4 trunk: global average pooling over the 8×88\times8 grid, dropout with keep probability 0.8 (config.dropout = 0.2), and a single lucid.nn.Linear layer producing config.num_classes logits. The trunk is held directly as features and the head as last_linear so the state dict matches the released checkpoint's keys one-for-one.

Parameters

Architecture spec. Use inception_v4_cls for the paper configuration.

Attributes

Stored copy of the config that built this model.
Same 22-module trunk as InceptionV4.features.
Global average pool to 1×11\times1.
head_dropnn.Module
lucid.nn.Dropout when config.dropout > 0, otherwise lucid.nn.Identity.
last_linearnn.Linear
Classifier projecting 1536 → num_classes.

Notes

The loss, computed only when labels is given, is the mean categorical 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}.

42.7 M parameters in total. The paper reports 20.0% top-1 / 5.0% top-5 single-crop error on the ImageNet validation set (Table 2).

Examples

>>> import lucid
>>> from lucid.models.vision.inception_v4 import inception_v4_cls
>>> model = inception_v4_cls().eval()
>>> out = model(lucid.randn(2, 3, 299, 299))
>>> out.logits.shape
(2, 1000)

Used by 2

Constructors

1
dunder

__init__

→None
__init__(config: InceptionV4Config)

Instance methods

1
fn

forward

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

Classify a batch of images.

Parameters

Input images of shape (B, in_channels, H, W).
labelsTensor or None= None
Integer class targets of shape (B,). When given, the cross-entropy loss is returned alongside the logits.

Returns

InceptionV4Output

logits of shape (B, num_classes) and loss (or None).