CNN architecture design
Core Design Dimensions
Why These Matter
- Depth controls feature hierarchy: shallow layers learn edges/textures, deep layers learn parts/objects
- Width controls capacity at each level: more filters = more parallel feature detectors
- Connectivity solves training problems: skip connections combat vanishing gradients
- Receptive field determines context: object recognition needs larger fields than edge detection
Classic Architectures Evolution
1. LeNet-5 (1998)
Structure: Conv → Pool → Conv → Pool → FC → FC → Output
Input(32×32) → Conv(6@5×5) → AvgPool(2×2) → Conv(16@5×5) → AvgPool(2×2) → FC(120) → FC(84) → FC(10)
Design Philosophy:
- Small, shallow (only 2 conv layers)
- Used for digit recognition (MNIST)
- Receptive field: each output neuron sees 28×28 region of input
Why it works: For simple patterns (digits), you only need basic edge combinations. Two conv layers are enough to go from "edges" → "digit parts" → "full digit".

2. AlexNet (2012)
Structure:
Conv(96@11×11,s=4) → MaxPool → Conv(256@5×5) → MaxPool →
Conv(384@3×3) → Conv(384@3×3) → Conv(256@3×3) → MaxPool → FC(4096) → FC(4096) → FC(1000)
Key Innovations:
- ReLU activation (instead of tanh): faster training, no vanishing gradient
- Dropout in FC layers: regularization
- Data augmentation: random crops, flips
- GPU training: split across2 GPUs
Why deeper? ImageNet has 1000 classes with complex objects. Need hierarchy: edges → textures → parts → objects.
3. VGGNet (2014)
Design Principle: Use only 3×3 convolutions, stack them deep.
VGG-16 Structure:
- Block 1: Conv(64@3×3) → Conv(64@3×3) → MaxPool
- Block 2: Conv(128@3×3) → Conv(128@3×3) → MaxPool
- Block 3: Conv(256@3×3) → Conv(256@3×3) → Conv(256@3×3) → MaxPool
- Block 4: Conv(512@3×3) × 3 → MaxPool
- Block 5: Conv(512@3×3) × 3 → MaxPool
- FC(4096) → FC(4096) → FC(1000)
Why it works: Doubling filters after each pool balances computational cost (spatial size halves, channels double).
General formula for stacked 3×3 convs:
Three 3×3 layers → 7×7 receptive field, but with 3nonlinearities vs 1.
4. ResNet (2015)
Residual Block:
x → Conv → ReLU → Conv → (+) → ReLU → output
↓________________________↑
(skip connection)
Mathematically:
Where is the residual mapping (what the layers learn).
Why it works:
- Gradient flow: — the "+1" ensures gradient never vanishes
- Identity shortcut: If needed, the network can learn and just copy input (easier than learning identity through layers)
- Ensemble interpretation: Each path from input to output is like a separate model; ResNet ensembles paths
Bottleneck design: 1×1 conv reduces channels → 3×3 conv processes → 1×1 conv expands back. Reduces computation by ~70%.
5. Inception (GoogLeNet)
Inception Module:
Input
|
┌─────────┬───┴────┬────────┐
| | |
1×1 conv 1×1→3×3 1×1→5×5 3×3 pool→1×1
| | |
└─────────┴──────────┘
|
Concatenate (depth)
Why 1×1 before larger convs? Dimensionality reduction:
- Without: 256 channels → 5×5 conv with 256 filters = params
- With 1×1: 256→64→256 = params (74% reduction)
Concatenate: 28×28×(64+128+64+64) = 28×28×320
Why this step? Each branch captures different receptive fields. The network learns to weight branches based on the task.
Design Principles (Deriving Best Practices)
Principle 1: Receptive Field Growth
For object recognition, final layer needs to see the entire object. Two strategies:
-
Pooling: Halve spatial dimensions → doubles effective RF for pooling with size .
-
Stride: Skip pixels in convolution
- Stride multiplies RF by
- But loses information (use sparingly)
With 3×3 convs between pools, need ~15 total conv layers to reach 100×100.
Principle 2: Channel Progression
Standard pattern: Double channels when halving spatial size.
Why? Maintain computational balance:
If halve and doubles: FLOPs stay constant.
where is initial channels (typically 64).
Principle 3: Spatial Invariance
Problem: Images have translation/scale/rotation variance. Objects can appear anywhere.
Solutions:
- Data augmentation: Train on crops, flips, rotations
- Pooling: Max-pooling provides local translation invariance
- Global average pooling: Replace FC layers → full translation invariance
Example: Instead of 7×7×512 → Flatten → FC(1000):
7×7×512 → AvgPool(7×7) → 1×1×512 → Conv(1×1, 1000 filters) → 1×1×1000 → Softmax
This has no spatial position encoding → works at any input size!
Principle 4: Computational Efficiency
Most expensive layers: Early ones (large ) and late ones (large ).
Optimization strategies:
-
Depthwise separable convolutions (MobileNet):
- Depthwise: Each input channel gets its own filter →
- Pointwise: 1×1 conv to mix channels →
- Total: vs standard
- Speedup: (e.g., 9× for 3×3)
-
Bottleneck layers: 1×1 reduce → 3×3 process → 1×1 expand
Common Mistakes & Fixes
Bad (ResNet-50 copy):
- 7×7 conv, stride 2 → 32×32
- MaxPool → 16×16
- 4 stages of residual blocks → 1×1 (way too aggressive!)
- Over-parameterized for 2 classes
Good (adapted):
- 3×3 conv, stride 1 → 64×64 (preserve resolution)
- [3×3 conv × 2 + MaxPool] × 3 → 8×8
- AvgPool → 1×1×256
- FC(2) with softmax
- 10× fewer parameters, trains faster, similar accuracy
Modern Architecture Patterns
Neural Architecture Search (NAS)
Idea: Let algorithms design architectures.
Search space: Define building blocks (conv, pool, skip) and constraints (max depth, FLOP budget).
Search methods:
- Reinforcement learning: Controller RNN proposes architectures, trained on validation accuracy
- Evolution: Mutate/crossover architectures, select fittest
- Differentiable NAS: Make architecture choices continuous, use gradient descent
Result: EfficientNet (discovered by NAS) achieves ResNet-50 accuracy with 10× fewer parameters.
EfficientNet Scaling
Why? Higher resolution images need deeper/wider nets to extract features.
Vision Transformers (2020s)
Breaking from convolution entirely:
- Divide image into 16×16 patches
- Treat as sequence (like words in NLP)
- Use transformer self-attention
Tradeoff: Needs huge datasets (ImageNet-21k+) to match CNN performance, but scales better.
Design Checklist
When designing a CNN:
- Input size → Determines pooling schedule (halve to ~7×7)
- Task complexity → Determines depth (simple: 5-10 layers, complex: 50-100)
- Compute budget → Use bottlenecks/depthwise convs if limited
- Data availability → More data → can go deeper without overfitting
- Interpretability needs → Simpler architectures (VGG-style) easier to visualize
Recall Explain to a 12-year-old
Imagine you're building a machine to recognize animals in photos. You could build it in different ways: The Simple Way (LeNet): Just two "looking" steps. First step finds edges (like where fur changes color), second step combines edges into simple shapes. Works for easy tasks like reading handwritten numbers. The Deep Way (ResNet): Lots of steps stacked up. First step finds edges, next finds textures (stripes, spots), then parts (ears, tails), then whole animals. It's like looking closer and closer, seeing more details each time. But there's a problem: if you stack too many steps, the "learning signal" gets lost (like a game of telephone). Trick: add shortcuts that let information jump over steps, so the signal stays strong.
The Multi-Tool Way (Inception): Instead of choosing one "looking size", use small, medium, AND large "looking windows" at the same time. Some animals need close-up details (small windows), others need zomed-out views (large windows). Let the machine pick which to use.
The Smart Way (EfficientNet): Don't just make it deeper. Make it wider (more parallel lookers), deeper (more steps), AND give it higher-quality photos to look at—all at once! This balanced growth works better than just one change.
The key lesson: there's no single "best" design. You pick based on what you're recognizing (simple shapes vs complex scenes), how much computing power you have, and how much data you can gather.
Connections
- 3.401-convolution-operation — Building block of all CNN architectures
- 3.4.02-pooling-layers — Downsampling strategy affects architecture depth
- 3.4.03-activation-functions — ReLU enabled deeper networks (AlexNet innovation)
- 3.4.04-batch-normalization — Stabilizes training in very deep nets (post-2015 standard)
- 3.5.01-transfer-learning — Pre-trained architectures as feature extractors
- 4.2.03-vanishing-gradient — Core problem that ResNet solves
- 5.1.02-hyperparameter-tuning — Architecture choices are hyperparameters
- 6.3.01-model-compression — Making architectures efficient for deployment
#flashcards/ai-ml
What is the receptive field of a CNN layer? :: The spatial region of the input image that influences a particular output neuron. Grows with depth via convolutions and pooling.
Why use two 3×3 convolutions instead of one 5×5?
What problem does ResNet's skip connection solve?
In VGGNet, why double channels after each pooling layer?
What is a bottleneck block in ResNet?
Why does ResNet-50 use 1×1 convolutions?
What is the key insight of Inception modules?
How does Global Average Pooling provide translation invariance?
What is depthwise separable convolution? :: Factorizes standard convolution into depthwise (one filter per input channel) and pointwise (1×1 to mix channels). Reduces computation by ~k² for k×k kernels.
What is compound scaling in EfficientNet?
Why do very deep networks (>20 layers) without skip connections have higher TRAINING error?
What is the typical channel progression in modern CNs?
How many pooling layers are typically needed for 224×224 images?
What is the receptive field formula for n stacked 3×3 convolutions?
Why use larger kernels (7×7) only in the first layer?
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Dekho, is note ka core idea bahut simple hai - CNN banana thoda building construction jaisa hai. Aap ek chaudi single-story warehouse bana sakte ho ya patli si skyscraper. CNN mein bhi yahi choice hai: kitne layers (depth) aur kitne filters per layer (width) rakhne hain. Depth decide karta hai ki network kitna complex feature seekh sakta hai - shallow layers sirf edges aur textures pakadti hain, jabki deep layers pura object recognize kar leti hain. Isliye simple task jaise digit recognition (LeNet) ke liye 2 conv layers kaafi hain, lekin ImageNet ke 1000 complex classes ke liye AlexNet ko 5 layers tak jaana pada.
Ab yahan ek killer insight hai jo VGGNet ne diya - do 3×3 convolutions ka receptive field utna hi hota hai jitna ek 5×5 ka, lekin parameters kam lagte hain (18 vs 25, yaani 28% saving) aur do ReLU activations milti hain jo zyada non-linearity deti hain. Matlab chhote kernels ko stack karke aap deeper bhi ja sakte ho aur efficient bhi reh sakte ho. Receptive field ka simple funda yaad rakho: n stacked 3×3 layers ka receptive field 2n+1 hota hai. Aur jab network bahut deep ho jaata hai, tab vanishing gradient problem aati hai - isko solve karne ke liye ResNet ne skip connections (residual connections) introduce ki.
Ye samajhna important kyun hai? Kyunki jab aap real world mein koi model design karoge ya kisi paper ko padhoge, tab aapko yeh judgement lagana padega ki task ke liye kitni depth-vs-width chahiye. Har task ka apna tradeoff hota hai - blindly deep network banana waste of computation ho sakta hai, aur bahut shallow rakhoge to accuracy nahi aayegi. Ye classic architectures (LeNet, AlexNet, VGG, ResNet) actually ek evolution story hain jisme har design ne pichle problem ko solve kiya, aur inko samajhkar aap khud better architectural decisions le paoge.