LeNet-5 feature extractor (no fully-connected head).
Implements the canonical convolutional trunk of the original LeNet-5 network from LeCun et al., "Gradient-Based Learning Applied to Document Recognition", Proc. IEEE 1998: three convolutional layers (C1, C3, C5) interleaved with two sub-sampling layers (S2, S4). The receptive field grows from a single patch in C1 to the entire input by C5 — so for the canonical input size the C5 output collapses to a spatial map of 120 channels, acting as a fully-connected layer in conv form. Used as the canonical "Hello World" of convolutional networks and as the smallest paper-cited baseline in the model zoo.
Parameters
configLeNetConfiglenet_5 for the
paper-cited tanh + average-pool variant; pass a custom config to
switch to modern activation="relu" / pooling="max" or to
accept RGB input via in_channels=3.Attributes
configLeNetConfigfeaturesnn.Sequential_build_features for the exact layer chain.feature_infolist[FeatureInfo]BackboneMixin for downstream decoder modules. The
reductions are measured on the canonical 32×32 input, where S2, S4
and C5 emit 14×14, 5×5 and 1×1 maps; the unpadded convolutions make
them depend on the input size.Notes
From LeCun et al., "Gradient-Based Learning Applied to Document Recognition", Proc. IEEE 86(11):2278–2324, 1998, Figure 2. Each convolution computes
where is in the paper. The original
sub-sampling layer was a trainable average pool
with learnable scale and bias; this implementation uses standard
parameter-free lucid.nn.AvgPool2d for compatibility with
modern training recipes. Total parameter count is approximately
60 k — small enough to train to convergence on MNIST in minutes on
a CPU.
Examples
Run a single forward pass on a batch of MNIST-shaped inputs:
>>> import lucid
>>> from lucid.models.vision.lenet import lenet_5
>>> backbone = lenet_5()
>>> x = lucid.randn(8, 1, 32, 32)
>>> out = backbone(x)
>>> out.last_hidden_state.shape # (B, 120, 1, 1)
(8, 120, 1, 1)
Each stage's reduction is the 32-pixel input over the side of the map
it emits (14, 5 and 1), so the last stage spans the whole input.
>>> [f.reduction for f in backbone.feature_info]
[2, 6, 32]Used by 2
Constructors
1Initialise the module and validate the supplied config.
Parameters
configModelConfigconfig_class.Raises
TypeErrorconfig_class has not been set on the concrete subclass,
or if config is not an instance of config_class.Properties
1Instance methods
2forward(x: Tensor)Run the cached executable; save grads for backward.
entry_holder[0] is the _StepEntry selected
by the outer step() cache lookup. step_args is
laid out as (*x_args, *params) so the autograd graph
sees both the user inputs and the model parameters in
its next-edge slot list (the parameter gradients are
wired in backward).