LeNet and AlexNet
Overview
LeNet and AlexNet are landmarkconvolutional neural network architectures== that demonstrated CNs could achieve breakthrough performance on image recognition tasks. LeNet (1998) proved the concept on handwritten digits, while AlexNet (2012) sparked the deep learning revolution by winning ImageNet with a massive performance gap.

LeNet-5 Architecture
Layer Sequence:
- Input: grayscale image
- C1 (Conv): 6 filters of , stride 1 → Output:
- S2 (Pool): average pooling, stride 2 → Output:
- C3 (Conv): 16 filters of , stride 1 → Output:
- S4 (Pool): average pooling, stride 2 → Output:
- C5 (Conv): 120 filters of → Output: (effectively FC)
- F6 (FC): 84 neurons
- Output (FC): 10 neurons (digit classes 0-9)
Total Parameters: ~60,000
Deriving Output Dimensions
The spatial dimension after convolution/pooling follows:
Derivation:
Why this formula?
- The kernel can slide positions horizontally
- Each position produces one output value
- With 6 filters, output is
Why average pooling? LeNet used average pooling (not max):
- Computation: In 1998, computation was expensive; averaging is cheaper than max
- Gradient flow: Averages distribute gradients to all inputs; max only to the largest
- Smoothing: Averaging provides gentle downsampling
AlexNet Architecture
Layer Sequence:
- Input: RGB image
- Conv1: 96 filters of , stride 4, ReLU →
- MaxPool1: , stride 2 →
- Conv2: 256 filters of , padding 2, ReLU →
- MaxPool2: , stride 2 →
- Conv3: 384 filters of , padding 1, ReLU →
- Conv4: 384 filters of , padding 1, ReLU →
- Conv5: 256 filters of , padding 1, ReLU →
- MaxPool3: , stride 2 →
- FC6: 4096 neurons, ReLU, Dropout(0.5)
- FC7: 4096 neurons, ReLU, Dropout(0.5)
- FC8: 1000 neurons (ImageNet classes), Softmax
Total Parameters: ~60 million
Key Innovations in AlexNet
Wait, why does AlexNet documentation say ?
- Implementation detail: AlexNet's actual Conv1 uses implicit padding that adds 1 pixel
- With effective input :
- The "224" in papers is a simplification; the code uses227
Why such a large stride (4)?
- Aggressive downsampling: Reduces computation immediately
- Large receptive field: kernel with stride 4 covers huge input regions
- Trade-off: Loses spatial detail, but AlexNet compensates with depth
1. ReLU Activation
Why ReLU is faster: Consider gradient flow.
Tanh gradient: For large , , so gradient (vanishing gradient).
ReLU gradient:
Key insight: ReLU gradient is either 1 or 0, never near-zero for positive inputs. This allows:
- 6× faster convergence (measured empirically by Krizhevsky)
- No gradient saturation for positive activations
- Simpler computation (just thresholding)
Trade-off: "Dying ReLU" problem when neurons always output 0 (addressed later by Leaky ReLU).
2. Dropout Regularization
Forward pass with dropout: where (1 with probability , 0 with probability ).
Test time (inference):
Why scale by at test time?
- Training: On average, fraction of neurons are active
- Test: All neurons are active, so outputs are times larger
- Solution: Multiply by to match expected training activation scale
Why dropout works:
- Ensemble effect: Training different sub-networks (like training networks for neurons)
- Co-adaptation prevention: Forces neurons to learn robust features independently
- AlexNet used in FC6 and FC7
3. Local Response Normalization (LRN)
where:
- = activity of neuron at position in channel
- = normalization window (AlexNet: )
- (hyperparameters)
Intuition: Neurons with large activations suppress nearby channels (mimics biological lateral inhibition).
Why it worked (slightly): Created competition between feature maps, improving generalization by ~1%.
Why it's abandoned: Batch Normalization (2015) is far more effective. Modern networks don't use LRN.
4. Data Augmentation
AlexNet pionered aggressive data augmentation:
Technique 1: Random Crops
- Extract random patches from images
- At test time, extract5 crops (corners + center) + their horizontal flips = 10 crops
- Average predictions over 10 crops
Technique 2: PCA Color Augmentation
- PerformCA on RGB values across training set
- Add multiples of principal components to RGB values: where = principal components, = eigenvalues,
Why this works: Captures natural variations in lighting and color while preserving object identity.
Architectural Comparison
| Aspect | LeNet-5 | AlexNet | |--------|------| | Year | 1998 | 2012 | | Input Size | grayscale | RGB | | Depth | 7 layers | 8 layers | | Parameters | ~60K | ~60M (1000× larger) | | Activation | / sigmoid | ReLU | | Pooling | Average pooling | Max pooling | | Regularization | Weight decay | Dropout + Data Aug | | Normalization | None | LRN | | Hardware | CPU | 2× GTX 580 GPUs | | Dataset | MNIST (60K images) | ImageNet (1.2M images) | | Classes | 10 | 1000 |
- Compute: GPUs made training 1000× larger networks feasible
- Data: ImageNet provided 20× more training data
- Algorithms: ReLU + Dropout solved vanishing gradients and overfitting
- Belief: The community didn't believe deep networks would work until AlexNet proved it
Worked Examples
Given:
- 6 filters of size
- Input: 1 channel (grayscale)
- Output: 6 feature maps
Calculation: Each filter has weights plus 1 bias. Total per filter: parameters. Total for 6 filters: parameters.
Why this step? Each filter slides over the entire input, sharing the same 26 parameters everywhere (parameter sharing reduces overfitting and computation).
Given:
- Input: (flattened to neurons)
- Output: 4096 neurons
Calculation: Each of 4096 output neurons connects to all 9216 input neurons:
Why this matters? FC6 alone contains 62% of AlexNet's total parameters. This is why modern architectures (ResNet, VGG) minimize FC layers and use global average pooling instead.
Given:
- Conv1: kernel, stride 4
Calculation: A Conv1 neuron sees an region in the input. The receptive field in the input is directly pixels.
For a Conv2 neuron:
- Conv2 sees in Conv1 feature map
- Each Conv1 pixel corresponds to input region with stride 4
- Receptive field: pixels
General formula for receptive field: where = kernel size at layer , = stride at layer .
Why this matters? Deep networks see large input regions. A neuron in Conv5 sees a input region, allowing recognition of large objects.
Common Mistakes
Why it feels right: More parameters = more capacity to learn complex patterns.
The fix:
- Parameters only help if you have enough training data to avoid overfitting
- LeNet on ImageNet would severely overfit (60K params, 1.2M images = underfitting)
- AlexNet on MNIST would severely overfit (60M params, 60K images = wasted capacity)
- Rule: Match model capacity to dataset size. Use regularization (dropout, data aug) to train large models on smaller datasets.
Why it feels right: The network is "learning," so it should adapt to any architecture.
The fix:
- Stride controls information loss. Large strides (AlexNet Conv1 stride 4) agressively downsample; information is permanently lost.
- Padding controls spatial dimension preservation. Without padding, spatial size shrinks every layer; with padding, it's controlled.
- Impact on depth: Without padding, a input with kernels reaches in ~110 layers. With padding, you can go arbitrarily deep (ResNet has 152+ layers).
Example: If you use stride 4 everywhere, your network will lose spatial information too quickly and fail to learn fine-grained features.
Why it feels right: AlexNet won ImageNet with LRN, so it must be important.
The fix:
- LRN provided only ~1% improvement in AlexNet
- Batch Normalization (2015) is far superior: faster training, better generalization,10-30% error reduction
- Modern practice: No one uses LRN anymore. Use Batch Norm instead.
- Lesson: Don't cargo-cult architectural details from old papers. Use modern best practices.
Active Recall Questions
Recall Explain LeNet and AlexNet to a 12-year-old
Imagine you're teaching a computer to recognize handwritten numbers. You could tell it "look for a curve here, a straight line there," but that's really hard to program for every possible way people write.
Instead, LeNet (created in 1998) uses a clever trick: it looks at the image in layers. The first layer finds simple things like edges (horizontal lines, vertical lines, curves). The second layer combines those edges to find slightly more complex shapes (like the top of a "5" or the loop in a "6"). By stacking these layers, the computer learns to recognize digits automatically, without anyone programming the rules!
LeNet worked great for simple images (like MNIST digits), but what about recognizing cats, dogs, cars in real photos? That's way harder because photos are bigger, more colorful, and have way more variety.
In 2012, AlexNet solved this by making the network much bigger and deeper. It used:
- More layers (8 instead of 5) to learn more complex patterns
- Faster math (ReLU instead of tanh, like switching from slow division to fast addition)
- Dropout (randomly turning off neurons during training, like practicing a sport with a handicap so you get stronger)
- Data tricks (flipping images, changing colors slightly to show the computer more examples)
AlexNet was so much better than everything else that it shocked the world and started the "deep learning revolution." Now, similar ideas power face recognition, self-driving cars, and AI assistants!
For AlexNet's 8 layers: "Cats Can Climb Canyon Cliffs For Fun Finally" (Conv, Conv, Conv, Conv, Conv, FC, FC, FC)
Connections
Prerequisites:
- Convolutional Layers — Understanding filters, stride, padding
- Pooling Layers — Max pooling vs average pooling
- Activation Functions — ReLU, tanh, sigmoid
- Backpropagation — How gradients flow through networks
Related Concepts:
- VGGNet — Deeper architecture with uniform filters (2014)
- Batch Normalization — Replaced LRN, normalizes layer inputs (2015)
- Dropout — AlexNet's key regularization technique
- ResNet — Skip connections enable100+ layer networks (2015)
- ImageNet Dataset — The benchmark AlexNet conquered
Applications:
- Transfer Learning — Using pretrained AlexNet/VGG for new tasks
- Object Detection — R-CNN built on AlexNet features
- Image Classification — Foundation for all modern architectures
#flashcards/ai-ml
What is the input size and number of parameters in LeNet-5? :: Input: grayscale image. Parameters: approximately 60,000.
What innovation in AlexNet made training 6× faster than tanh?
How many parameters does AlexNet have and where are most of them?
What is dropout and why does AlexNet scale activations by (1-p) at test time?
Calculate the output dimension for a convolutional layer with input 32×32, kernel5×5, stride 1, padding 0.
Why did AlexNet use stride 4 in the first convolutional layer?
What is the receptive field formula for layer l?
What are the two main data augmentation techniques AlexNet used?
Why is Local Response Normalization (LRN) not used in modern CNs?
What three algorithmic innovations allowed AlexNet to succeed where LeNet-scale networks had failed on ImageNet?
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Hinglish (regional understanding)
Intuition Hinglish mein samjho
LeNet aur AlexNet dono CNN ke history mein bahut important milestones hain, aur inko samajhna zaroori hai kyunki yehi wo architectures hain jinhone aaj ke modern deep learning ki neenv rakhi. LeNet (1998) ne pehli baar prove kiya ki hum handwritten digits (jaise MNIST wale 0-9 numbers) ko automatically pehchaan sakte hain — matlab pehle log manually features banate the, par LeNet ne backpropagation se khud seekh liya. Iska core idea hai hierarchical feature learning: early layers simple cheezein detect karti hain jaise edges, aur deeper layers unko combine karke complex features banati hain jaise pura digit. Yeh pattern aaj bhi har CNN follow karta hai, isliye yeh foundation samajhna must hai.
Ab AlexNet (2012) ne toh puri computer vision community ko hila diya. Yeh ImageNet competition mein 15.3% top-5 error laaya jabki doosra best 26.2% par tha — yeh 10-point ka farak bahut bada tha aur logon ko convince kar diya ki deep CNNs + GPUs + bahut saara data milkar traditional methods ko easily beat kar sakte hain. AlexNet ne kuch naye tricks introduce kiye jaise ReLU activation (jo training fast karta hai), Dropout (jo overfitting rokta hai), aur max pooling. LeNet ke ~60,000 parameters ke muqable AlexNet ke paas ~60 million parameters the — yeh scale ka jump dikhata hai ki compute power badhne se kitna kuch possible hua.
Ek cheez jo tumhe practically yaad rakhni chahiye wo hai output dimension nikalne ka formula: (Input - Kernel + 2×Padding)/Stride + 1. Isse tum kisi bhi conv ya pool layer ke baad size calculate kar sakte ho, jaise LeNet ka C1 layer 32×32 input ko 28×28 bana deta hai. Exams aur interviews mein yeh calculation bahut poocha jaata hai, toh iss formula pe achhi command bana lena. Overall, in dono architectures ko samajhna matlab poore CNN evolution ki story samajhna hai — kaise ek chhoti si idea se aaj ki powerful AI systems tak safar hua.