LeNet, AlexNet and embeddings
This lecture covers LeNet-5, hierarchical features, AlexNet and image embeddings. It shows learnable parameter counts, output sizes and Euclidean nearest neighbours. After this page you can compute kernel counts and compare image embeddings by Euclidean distance.
LeNetSearch on YouTube
LeNet is one of the earliest influential CNNs. It classified grey handwritten digits 0-9 from MNIST data. It proved that convolutions plus subsampling can read images end to end.
A CNN kernel is also called filter. This page uses only kernel after this sentence.
LeNet-5 stacks convolution, subsampling and fully connected layers. Each convolution layer applies several 3D kernels and produces a stack of feature maps. Each pooling layer reduces height and width and controls overfitting.
Layers and activation functionSearch on YouTube
LeNet-5 used sigmoid activation functions in hidden layers. The sigmoid squashes each sum into the range 0 to 1. Later networks replaced it with ReLU for faster training.
is the weighted sum plus bias at one unit. is the output between 0 and 1. LeNet-5 applied this activation function after convolution and fully connected layers.
A standard LeNet-5 layout is input , C1 , S2 , C3 , S4 , C5 , F6 , output . C means convolution. S means subsampling or pooling. F means fully connected.
When the input has depth , each kernel has depth . The depth of the C-layer output equals , the number of kernels. For RGB input the first depth is 3, but the output depth is still .
C5 behaves as a fully connected layerSearch on YouTube
C5 receives from S4. It applies kernels of size . Each kernel covers the whole input field.
is the input height. is the kernel height. is padding rounds. is stride. The same rule gives width. Apply it per layer to track each feature map size.
Since input size equals kernel size, the output is . So each kernel gives one number. The result is numbers. That is the same as a fully connected layer with units.
Worked example. LeNet C1 output size and learnable parameter count.
Output size. Input is . Kernel is . Stride is 1. Padding is 0.
Learnable parameter count. Each kernel holds weights plus one bias.
Without bias the count is . State the bias rule in the exam.
Worked example. LeNet C5 and total learnable parameter count.
C5 size. Input is . Kernel is . Stride is 1.
C5 count. Each of the kernels sees all input maps.
Full net. C1 has . C3 has . F6 has . Output has .
That is about K learnable parameters.
Write the bias rule first. Then use . Examiners accept both and for C1 if you state the rule.
Do not call C5 a convolution in the usual sliding sense. It uses convolution kernels, but each kernel sees the full field. Treat it as a fully connected layer.
Hierarchical featuresSearch on YouTube
Early CNN layers learn small-scale features. They detect edges, textures and corners. Middle layers learn medium-scale features. They combine edges into shapes and object parts.
Deeper layers learn global features. They combine parts into whole objects and abstract patterns. The network thus builds combinations across the full image. This hierarchy supports final classification.
Think of bricks, walls and houses. Early layers see bricks. Middle layers see walls. Deep layers see the house.
ImageNet challengeSearch on YouTube
ImageNet challenged models to classify RGB images into 1000 classes. The plot of error versus layers showed deeper CNNs with better training beat shallow models. The task needs colour, texture and part cues at many scales.
LeNet suited small grey digits. ImageNet needs far larger capacity and stronger regularization. AlexNet supplied both.
AlexNetSearch on YouTube
AlexNet revolutionized computer vision with deep CNNs. It has learnable layers: convolutional layers plus fully connected layers. Depth alone did not explain the gain. Five training tricks improved performance and generalization.
is the weighted sum plus bias. keeps positive inputs and sets negative inputs to 0. AlexNet used this ReLU activation function instead of sigmoid.
The five tricks are ReLU activations, overlapping max pooling, dropout, normalization of pixel values and data augmentation with resize to , crops and rotations.
R-O-D-N-D: Run Over Drops, Never Dry
ReLU · Overlapping pool · Dropout · Normalization · Data augmentation. AlexNet runs over dropout-regularized maps and never dries out on new images.
ReLU trains faster than sigmoid. Its gradient stays 1 for positive inputs. Sigmoid saturates at both ends and slows learning.
Overlapping pooling uses a window larger than its stride, for example with stride . Neighbour windows overlap. The overlap keeps more spatial context than disjoint windows.
Dropout randomly zeroes hidden units during training. It breaks co-adaptation between units. It reduces overfitting on large fully connected layers.
Normalization rescales pixel values and normalizes responses across feature maps. It keeps activations in a stable range. Training becomes faster and more stable.
Data augmentation enlarges the training set. It resizes images to , takes random crops, flips and rotates them. The network sees new variants each epoch.
Worked example. AlexNet conv1 output size and learnable parameter count.
Output size. Input is . Kernel is . Stride is . Padding is .
Learnable parameter count. There are kernels, each plus one bias.
One AlexNet layer already holds more learnable parameters than all of LeNet C1 and C3 combined.
For output size, compute the numerator first. Check that it divides by stride. Then add 1. For counts, compute one kernel first, then multiply by .
Learnable parameter scaleSearch on YouTube
The slide summary contrasts about K with about M learnable parameters. LeNet holds about K. AlexNet holds about M. The ratio is about .
The growth comes from RGB inputs, larger images, more kernels per layer and wide fully connected layers. The fully connected layers dominate the AlexNet total.
Worked example. Why AlexNet reaches about M: FC6 count.
Input size. After convolutions and pooling, the map is .
Learnable parameter count. Each output has one weight per input plus one bias.
This one layer holds about M learnable parameters. That alone is about times the LeNet total.
| LeNet | AlexNet |
|---|---|
| Grey inputs, labels | RGB inputs, labels |
| convolutions or subsampling plus dense | convolutions plus dense ( learnable) |
| Sigmoid activation function | ReLU activation function |
| No dropout or large augmentation | Dropout, normalization and augmentation |
| About K learnable parameters | About M learnable parameters |
Kernels vs tensor outputsSearch on YouTube
Each kernel produces one 2D feature map. kernels produce stacked maps. The slide shows learnable kernels giving outputs.
Each kernel spans the full input depth. For RGB input, each kernel is 3D with depth . For a -map input, each kernel has depth . The model learns every kernel value from the dataset.
is the spatial kernel size. is the input depth. is one bias per kernel. is the kernel count. The output depth equals .
So output depth is not a free choice after training. It equals the kernel count by construction. More kernels mean more feature maps and more learnable parameters.
Conv3 and conv4 without poolingSearch on YouTube
AlexNet pools after conv1, conv2 and conv5. It omits pooling between conv3 and conv4. Both are deeper layers with kernels. They focus on complex patterns such as object parts.
Pooling reduces height and width. It can destroy fine spatial detail. Skipping pooling here preserves spatial resolution. The network retains detailed part layouts for accurate classification.
Do not place pooling after every convolution by default. Pooling helps invariance and speed, but each pooling step loses location detail. AlexNet keeps conv3 and conv4 dense for that reason.
Embedding spaceSearch on YouTube
An image embedding space is a high-dimensional mathematical space. Each image maps to one vector in that space. These vectors are called embeddings.
AlexNet learned representations in such a space. Similar images mapped to nearby points. Points close together shared more semantic traits. A dog image sat near other dog images, far from truck images.
The output layer then assigns proposed labels. It converts the last embedding into scores over labels. The top scores are the proposed labels for the test image.
Similar feature vectors by Euclidean distanceSearch on YouTube
Given a test image, AlexNet compares its feature vector with training vectors. It ranks training images by Euclidean distance in the output layer. The smallest distances indicate the most similar feature vectors.
The slide illustrates the idea with four feature vectors over traits such as weight, height and ear size. Distance uses all traits together. Close vectors share trait profiles.
is the test vector. is one training vector. is the embedding size. Small means high similarity.
Worked example. Nearest neighbour among four 3-dim vectors.
Data. Test vector . Training vectors , , , .
Rank. .
The nearest neighbour is with distance . The slide reports such neighbours as similar feature vectors to the test image.
Square first, then sum, then root. For ranking only, compare squared distances. The order is the same and you skip four roots.
Quick self-testSearch on YouTube
1. State the LeNet task and the standard input and output sizes.
LeNet classified grey handwritten digits 0-9. Standard input is . Standard output is labels.
2. Compute the C1 output size for input, kernel, stride and no padding.
. The feature map is for kernels.
3. Compute the C1 learnable parameter count for kernels of with bias.
Per kernel . Total . Without bias the total is .
4. Why does C5 behave as a fully connected layer?
Its input is and each kernel is . Each kernel covers the full field and gives one number. So kernels give numbers like a dense layer.
5. Differentiate early, middle and deep CNN features.
Early layers learn edges, textures and corners. Middle layers learn shapes and object parts. Deep layers learn whole objects and abstract patterns.
6. List the five AlexNet tricks and state the layer count.
AlexNet has convolutions plus dense layers ( learnable). Tricks are ReLU, overlapping pooling, dropout, normalization and data augmentation.
7. Compute the AlexNet conv1 output width for input, kernel and stride .
. The feature map is .
8. Why do conv3 and conv4 skip pooling?
They capture complex object parts and need spatial detail. Pooling would shrink the maps and destroy fine location cues. Skipping it preserves resolution for classification.
9. Compare K and M. Which layer type drives the AlexNet total?
LeNet holds about K learnable parameters. AlexNet holds about M, about times more. Wide fully connected layers drive it: FC6 alone holds about M.
10. Rank these training vectors for test : , , .
Distances are , and . Rank is . The first is the nearest neighbour.
- LeNet classified grey digits with stacked convolution, pooling and dense layers. It used sigmoid activation functions.
- Standard sizes run to C1 , S2 , C3 , S4 , C5 , F6 , output .
- C5 behaves as a fully connected layer: input with kernels gives . Its count is .
- Early layers learn edges and textures. Middle layers learn shapes and parts. Deep layers learn objects.
- ImageNet needs RGB labels. It rewards deeper nets with strong regularization.
- AlexNet has convolutions plus dense layers. Tricks are R-O-D-N-D: ReLU, Overlapping pool, Dropout, Normalization, Data augmentation.
- Output size is . AlexNet conv1 gives with learnable parameters.
- Learnable count is . LeNet totals about K. AlexNet totals about M.
- Conv3 and conv4 skip pooling to preserve spatial detail for object parts.
- An embedding maps each image to a vector. Close vectors share semantic traits. Nearest neighbours use .
CNNs Explained
CNN Architectures
Word Embedding Word2Vec