Deep Learning · PyTorch · FashionMNIST

CNN Architecture Evolution

From LeNet-5 to ResNet-50 — implemented from scratch in PyTorch, trained on FashionMNIST, with batch normalization ablation study and architecture comparison.

ResNet-18 → 90.37% acc ResNet-34 → 89.70% acc ResNet-50 → 88.27% acc Dataset FashionMNIST (60k train)

Overview

This project traces the evolution of convolutional neural network architectures from the original LeNet-5 (1998) to the deep residual networks that transformed the field in 2015. Each architecture was built from scratch in PyTorch without relying on pretrained weights, trained and evaluated on FashionMNIST.

Python PyTorch FashionMNIST MNIST Jupyter d2l Adam / SGD CrossEntropyLoss

Part 1 — LeNet and Modernized LeNet

Original LeNet-5

Implemented the original LeCun (1998) architecture with Sigmoid activations and average pooling, trained on both MNIST and FashionMNIST across 5, 10, and 20 epoch configurations.

Conv1
6 filters, 5×5 kernel, padding=2 → Sigmoid → AvgPool 2×2
First feature extraction layer, preserves spatial dimensions with padding
Conv2
16 filters, 5×5 kernel → Sigmoid → AvgPool 2×2
Deeper feature maps with reduced spatial resolution
FC
Flatten → Linear(120) → Linear(84) → Linear(10)
Three fully-connected layers for final classification

Modernized LeNet

Upgraded the original architecture by replacing Sigmoid with ReLU activations and swapping average pooling for max pooling — both standard practices in modern CNNs that improve gradient flow and feature selection.

Key changes: Sigmoid → ReLU · AvgPool → MaxPool · faster convergence · better accuracy on FashionMNIST

LeNet training curves
→ LeNet Modernized training curves on FashionMNIST

Part 2 — Batch Normalization from Scratch

Implemented batch normalization manually in PyTorch — computing per-batch mean and variance during training, switching to running statistics during inference, with learnable scale (γ) and shift (β) parameters.

Three normalization variants implemented and compared:

VariantFormulaEffect
fullNormalize by mean and varianceStandard batch norm
mean_onlySubtract mean, skip varianceFaster, less stable
variance_onlyDivide by std, skip meanPartial normalization

Ablation Study

Tested selective batch normalization — enabling/disabling BN at individual layers using a bn_layers=[True, True, True, True] flag — to isolate which layers benefit most from normalization.

ConfigurationBN Layers ActiveObservation
Full BNAll conv + FC layersBest convergence speed
Conv onlyConv layers onlyGood stability, slower FC
No BN (baseline)NoneSlower, less stable training

Part 3 — ResNet-18, ResNet-34, ResNet-50

Implemented the full ResNet family with two residual block types — BasicResidual for ResNet-18/34 and ResidualBottleneck for ResNet-50 — matching the original He et al. (2015) paper specifications.

BasicResidual Block (ResNet-18 / 34)

Conv(3×3) → BN → ReLU → Conv(3×3) → BN → [+ skip connection] → ReLU
1×1 projection shortcut when channels change or stride > 1

Bottleneck Block (ResNet-50)

Conv(1×1) → BN → ReLU → Conv(3×3) → BN → ReLU → Conv(1×1) → BN → [+ skip] → ReLU
mid_channels = out_channels // 4 — reduces computation while preserving capacity

Model Configurations

ModelBlock TypeLayer ConfigParameters
ResNet-18BasicResidual[2, 2, 2, 2]~11M
ResNet-34BasicResidual[3, 4, 6, 2]~21M
ResNet-50Bottleneck[3, 4, 6, 3]~25M
ResNet training plot
→ ResNet training plot
ResNet training plot
→ ResNet training plot
ResNet training plot
→ ResNet training plot

Training Results

ResNet-18
90.37%
Best epoch 7 · 62.4s
ResNet-34
89.70%
Best epoch 9 · 88.8s
ResNet-50
88.27%
Best epoch 8 · 53.4s

ResNet-18 — Epoch-by-Epoch

EpochTrain LossTest Accuracy
10.633283.75%
20.360587.45%
30.307988.28%
50.268389.72%
70.236490.37%
100.208190.08%

ResNet-34 — Epoch-by-Epoch

EpochTrain LossTest Accuracy
10.930282.05%
30.349087.27%
60.270989.10%
90.233389.70%
100.232789.66%

ResNet-50 — Epoch-by-Epoch

EpochTrain LossTest Accuracy
10.796179.40%
40.403281.76%
60.343485.70%
80.314588.27%
100.275687.45%

Key Observations

ResNet-18 achieved the highest peak accuracy (90.37%) despite having fewer parameters than ResNet-34 and ResNet-50 — suggesting the shallower network generalizes better on FashionMNIST's relatively simple patterns. ResNet-50's bottleneck design shows slower initial convergence but stabilizes well by epoch 8. All three models show consistent loss decrease without overfitting, validating the residual connections.

ResNet comparison plot
→ ResNet model comparison
ResNet comparison plot
→ ResNet model comparison
ResNet comparison plot
→ ResNet model comparison