LeNet-5 Explained Simply (Step-by-Step CNN Guide)
๐ Table of Contents
- What is LeNet-5?
- Core Intuition
- Layers Explained
- How It Works
- Code Example
- CLI Output
- Why It Matters
- Key Takeaways
- Related Articles
๐ What is LeNet-5?
LeNet-5 is one of the first successful Convolutional Neural Networks (CNNs). It was designed to recognize handwritten digits like 0–9.
๐ง Core Intuition
LeNet-5 works in 3 simple stages:
- ๐ Look for basic patterns (edges, lines)
- ๐งฉ Combine patterns into shapes
- ๐ข Decide which digit it is
๐ Layers of LeNet-5
1️⃣ Input Layer
Image size: 32 × 32 (grayscale)
Original images are 28x28. Padding adds borders so edges are not lost.
2️⃣ Convolution Layer (C1)
- 6 filters (5×5) - Output: 28 × 28 × 6
Filters scan the image and detect edges, corners, and simple patterns.
3️⃣ Pooling Layer (S2)
- Average pooling (2×2) - Output: 14 × 14 × 6
Reduces size → faster computation → keeps important info.
4️⃣ Convolution Layer (C3)
- 16 filters - Output: 10 × 10 × 16
Now the network detects more complex shapes (like curves and parts of digits).
5️⃣ Pooling Layer (S4)
- Output: 5 × 5 × 16
6️⃣ Fully Connected Layer (F5)
- 120 neurons
All features are combined to understand the full image.
7️⃣ Output Layer
- 10 neurons → digits (0–9)
๐ How LeNet-5 Works (Step-by-Step)
- Input image enters
- Find edges using filters
- Reduce size using pooling
- Detect complex shapes
- Flatten into vector
- Predict digit
๐ป Code Example
import tensorflow as tf from tensorflow.keras import layers model = tf.keras.Sequential([ layers.Conv2D(6, (5,5), activation='relu', input_shape=(32,32,1)), layers.AveragePooling2D(), layers.Conv2D(16, (5,5), activation='relu'), layers.AveragePooling2D(), layers.Flatten(), layers.Dense(120, activation='relu'), layers.Dense(84, activation='relu'), layers.Dense(10, activation='softmax') ]) model.summary()
๐ฅ CLI Output
Layer (type) Output Shape Conv2D (None, 28, 28, 6) AvgPooling (None, 14, 14, 6) Conv2D (None, 10, 10, 16) AvgPooling (None, 5, 5, 16) Dense (None, 120) Dense (None, 84) Dense (None, 10)
๐ Why LeNet-5 Matters
- First successful CNN
- Showed machines can learn features automatically
- Foundation of modern AI (face recognition, self-driving)
๐ฏ Key Takeaways
๐ Related Articles
๐ง Final Thought
LeNet-5 teaches us a powerful idea: Computers don’t need rules — they can learn patterns.
No comments:
Post a Comment