3.4.5 · HinglishConvolutional Neural Networks

CNN architecture design

3,259 words15 min readRead in English

3.4.5 · AI-ML › Convolutional Neural Networks

Core Design Dimensions

Ye Kyun Matter Karte Hain

  • Depth feature hierarchy control karti hai: shallow layers edges/textures seekhti hain, deep layers parts/objects seekhti hain
  • Width har level par capacity control karti hai: zyada filters = zyada parallel feature detectors
  • Connectivity training problems solve karta hai: skip connections vanishing gradients se ladte hain
  • Receptive field context determine karta hai: object recognition ko edge detection se bada field chahiye

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:

  • Chhota, shallow (sirf 2 conv layers)
  • Digit recognition ke liye use hua (MNIST)
  • Receptive field: har output neuron input ka 28×28 region dekhta hai

Ye kaam kyun karta hai: Simple patterns (digits) ke liye, tumhe sirf basic edge combinations chahiye. Do conv layers kaafi hain "edges" → "digit parts" → "full digit" tak jaane ke liye.

Figure — CNN architecture design

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:

  1. ReLU activation (tanh ki jagah): faster training, no vanishing gradient
  2. Dropout FC layers mein: regularization
  3. Data augmentation: random crops, flips
  4. GPU training: 2 GPUs par split

Deeper kyun? ImageNet mein 1000 classes hain complex objects ke saath. Hierarchy chahiye: edges → textures → parts → objects.

3. VGGNet (2014)

Design Principle: Sirf 3×3 convolutions use karo, unhe deep stack karo.

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)

Ye kaam kyun karta hai: Har pool ke baad filters double karna computational cost balance karta hai (spatial size aadha hoti hai, channels double hote hain).

stacked 3×3 convs ke liye general formula:

Teen 3×3 layers → 7×7 receptive field, lekin 1 ki jagah 3 nonlinearities ke saath.

4. ResNet (2015)

Residual Block:

x → Conv → ReLU → Conv → (+) → ReLU → output
 ↓________________________↑
      (skip connection)

Mathematically:

Jahaan residual mapping hai (layers kya seekhti hain).

Ye kaam kyun karta hai:

  1. Gradient flow: — "+1" ensure karta hai ki gradient kabhi vanish na ho
  2. Identity shortcut: Agar zaroorat ho, network seekh sakta hai aur sirf input copy kar sakta hai (layers ke through identity seekhne se aasaan)
  3. Ensemble interpretation: Input se output tak har path ek alag model jaisa hai; ResNet paths ensemble karta hai

Bottleneck design: 1×1 conv channels reduce karta hai → 3×3 conv process karta hai → 1×1 conv wapas expand karta hai. Computation ~70% reduce karta hai.

5. Inception (GoogLeNet)

Inception Module:

                Input
                      |
        ┌─────────┬───┴────┬────────┐
        |         |          |
     1×1 conv  1×1→3×3  1×1→5×5   3×3 pool→1×1
        |         |          |
        └─────────┴──────────┘
                      |
              Concatenate (depth)

1×1 bade convs se pehle kyun? Dimensionality reduction:

  • Bina: 256 channels → 5×5 conv with 256 filters = params
  • 1×1 ke saath: 256→64→256 = params (74% reduction)

Concatenate: 28×28×(64+128+64+64) = 28×28×320

Ye step kyun? Har branch alag receptive fields capture karti hai. Network task ke basis par branches weight karna seekhta hai.

Design Principles (Best Practices Derive Karna)

Principle 1: Receptive Field Growth

Object recognition ke liye, final layer ko poora object dekhna chahiye. Do strategies:

  1. Pooling: Spatial dimensions aadhe karo → effective RF double hoti hai size ke pooling ke liye.

  2. Stride: Convolution mein pixels skip karo

    • Stride RF ko se multiply karta hai
    • Lekin information lose hoti hai (sparingly use karo)

Pools ke beech 3×3 convs ke saath, 100×100 reach karne ke liye ~15 total conv layers chahiye.

Principle 2: Channel Progression

Standard pattern: Spatial size aadhi hone par channels double karo.

Kyun? Computational balance maintain karo:

Agar aadhe ho jayein aur double ho jaye: FLOPs constant rehte hain.

jahaan initial channels hai (typically 64).

Principle 3: Spatial Invariance

Problem: Images mein translation/scale/rotation variance hoti hai. Objects kahin bhi appear ho sakte hain.

Solutions:

  1. Data augmentation: Crops, flips, rotations par train karo
  2. Pooling: Max-pooling local translation invariance deta hai
  3. Global average pooling: FC layers replace karo → full translation invariance

Example: 7×7×512 → Flatten → FC(1000) ki jagah:

7×7×512 → AvgPool(7×7) → 1×1×512 → Conv(1×1, 1000 filters) → 1×1×1000 → Softmax

Isme koi spatial position encoding nahi → kisi bhi input size par kaam karta hai!

Principle 4: Computational Efficiency

Sabse expensive layers: Early wale (bade ) aur late wale (bade ).

Optimization strategies:

  1. Depthwise separable convolutions (MobileNet):

    • Depthwise: Har input channel ka apna filter hota hai →
    • Pointwise: Channels mix karne ke liye 1×1 conv →
    • Total: vs standard
    • Speedup: (jaise 3×3 ke liye 9×)
  2. 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 (bahut zyada aggressive!)
  • 2 classes ke liye over-parameterized

Good (adapted):

  • 3×3 conv, stride 1 → 64×64 (resolution preserve karo)
  • [3×3 conv × 2 + MaxPool] × 3 → 8×8
  • AvgPool → 1×1×256
  • FC(2) with softmax
  • 10× kam parameters, faster train hota hai, similar accuracy

Modern Architecture Patterns

Neural Architecture Search (NAS)

Idea: Algorithms ko architectures design karne do.

Search space: Building blocks (conv, pool, skip) aur constraints (max depth, FLOP budget) define karo.

Search methods:

  1. Reinforcement learning: Controller RNN architectures propose karta hai, validation accuracy par trained hota hai
  2. Evolution: Architectures mutate/crossover karo, fittest select karo
  3. Differentiable NAS: Architecture choices continuous banao, gradient descent use karo

Result: EfficientNet (NAS se discover hua) ResNet-50 accuracy achieve karta hai 10× kam parameters ke saath.

EfficientNet Scaling

Kyun? Higher resolution images ko features extract karne ke liye deeper/wider nets chahiye.

Vision Transformers (2020s)

Convolution se bilkul alag ho kar:

  • Image ko 16×16 patches mein divide karo
  • Sequence ki tarah treat karo (jaise NLP mein words)
  • Transformer self-attention use karo

Tradeoff: CNN performance match karne ke liye huge datasets (ImageNet-21k+) chahiye, lekin better scale karta hai.

Design Checklist

CNN design karte waqt:

  1. Input size → Pooling schedule determine karta hai (~7×7 tak aadha karo)
  2. Task complexity → Depth determine karta hai (simple: 5-10 layers, complex: 50-100)
  3. Compute budget → Limited ho to bottlenecks/depthwise convs use karo
  4. Data availability → Zyada data → bina overfitting ke deeper ja sakte ho
  5. Interpretability needs → Simpler architectures (VGG-style) visualize karna aasaan hai
Recall Ek 12-saal ke bacche ko samjhao

Socho tum ek machine bana rahe ho jo photos mein animals recognize kare. Tum ise alag-alag tareekon se bana sakte ho: Simple Way (LeNet): Sirf do "dekhne" ke steps. Pehla step edges dhundhta hai (jaise jahan fur ka color badalta hai), doosra step edges ko simple shapes mein combine karta hai. Easy tasks ke liye kaam karta hai jaise handwritten numbers padhna. Deep Way (ResNet): Bahut saare steps stack kiye hue. Pehla step edges dhundhta hai, agle mein textures (stripes, spots), phir parts (ears, tails), phir poore animals. Ye aisa hai jaise baar baar aur kareeb se dekhte raho, har baar aur details dikhaai detein hain. Lekin ek problem hai: agar bahut zyada steps stack karo, to "learning signal" kho jaata hai (jaise telephone game mein). Trick: shortcuts add karo jo information ko steps jump karne dein, taaki signal strong rahe.

Multi-Tool Way (Inception): Ek "dekhne ka size" choose karne ki jagah, chhoti, medium, AUR badi "dekhne ki windows" ek saath use karo. Kuch animals ko close-up details chahiye (chhoti windows), doosron ko zoomed-out views (badi windows). Machine ko decide karne do.

Smart Way (EfficientNet): Sirf ise deeper mat banao. Ise wider banao (zyada parallel lookers), deeper banao (zyada steps), AUR use dekhne ke liye higher-quality photos do—sab ek saath! Ye balanced growth sirf ek change se better kaam karta hai.

Key lesson: koi ek "best" design nahi hai. Tum pick karte ho is basis par ki tum kya recognize kar rahe ho (simple shapes vs complex scenes), tumhare paas kitni computing power hai, aur tum kitna data gather kar sakte ho.

Connections

  • 3.401-convolution-operation — Sabhi CNN architectures ka building block
  • 3.4.02-pooling-layers — Downsampling strategy architecture depth ko affect karti hai
  • 3.4.03-activation-functions — ReLU ne deeper networks enable kiye (AlexNet innovation)
  • 3.4.04-batch-normalization — Bahut deep nets mein training stabilize karta hai (post-2015 standard)
  • 3.5.01-transfer-learning — Pre-trained architectures feature extractors ki tarah
  • 4.2.03-vanishing-gradient — Core problem jo ResNet solve karta hai
  • 5.1.02-hyperparameter-tuning — Architecture choices hyperparameters hain
  • 6.3.01-model-compression — Architectures ko deployment ke liye efficient banana

#flashcards/ai-ml

CNN layer ka receptive field kya hai? :: Input image ka wo spatial region jo ek particular output neuron ko influence karta hai. Depth ke saath convolutions aur pooling ke zariye badhta hai.

Do 3×3 convolutions ek 5×5 ki jagah kyun use karte hain?
Same receptive field (5×5), lekin 28% kam parameters aur do ReLU activations (zyada nonlinearity) ek ki jagah.
ResNet ka skip connection kya problem solve karta hai?
Deep networks mein vanishing gradients. Identity shortcut gradient flow ensure karta hai: ∂H/∂x = ∂F/∂x + 1, jahaan +1 vanishing ko rokta hai.
VGGNet mein har pooling layer ke baad channels kyun double karte hain?
Computational balance maintain karne ke liye. Spatial dimensions aadhi karna (÷4 area) aur channels double karna (×2 per dimension) FLOPs roughly constant rakhta hai.
ResNet mein bottleneck block kya hota hai?
1×1 conv (channels reduce) → 3×3 conv (process) → 1×1 conv (expand). Computation ~70% reduce karta hai expressiveness maintain karte hue.
ResNet-50 mein 1×1 convolutions kyun use hote hain?
Expensive 3×3 convs se pehle dimensionality reduction ke liye, aur baad mein expansion ke liye. Parameters reduce karte hain network depth maintain karte hue.
Inception modules ki key insight kya hai?
Multi-scale features capture karne ke liye multiple filter sizes (1×1, 3×3, 5×5) parallel mein use karo, phir concatenate karo. Network ko seekhne do ki kaunse scales matter karte hain.
Global Average Pooling translation invariance kaise deta hai?
Har feature map ko ek single value mein average karta hai, saari spatial position information hata deta hai. Network ko kisi bhi input size par kaam karne deta hai.

Depthwise separable convolution kya hai? :: Standard convolution ko depthwise (har input channel ke liye ek filter) aur pointwise (channels mix karne ke liye 1×1) mein factorize karta hai. k×k kernels ke liye ~k² se computation reduce karta hai.

EfficientNet mein compound scaling kya hai?
Depth, width, aur resolution ko ek saath fixed ratios ke saath scale karo: d=α^φ, w=β^φ, r=γ^φ. Ek dimension akele scale karne se zyada effective hai.
Skip connections ke bina bahut deep networks (>20 layers) ka TRAINING error zyada kyun hota hai?
Vanishing/exploding gradients optimization mushkil banate hain. Overfitting nahi hai—network sirf poor gradient flow ki wajah se seekh nahi pata. Skip connections ise fix karte hain.
Modern CNNs mein typical channel progression kya hai?
Spatial dimensions aadhi hone par (pooling ke baad) channels double karo. Jaise 64→128→256→512. Layers mein computational balance maintain karta hai.
224×224 images ke liye typically kitni pooling layers chahiye?
5 pooling layers: 224→112→56→28→14→7. Final 7×7 feature maps phir global-pool ya flatten ki jaati hain.
n stacked 3×3 convolutions ke liye receptive field formula kya hai?
RF = 2n + 1. Jaise teen 3×3 layers 7×7 receptive field deti hain 3 nonlinearities ke saath.
Bade kernels (7×7) sirf pehli layer mein kyun use karte hain?
Aggressively downsample karne aur spatial dimensions jaldi reduce karne ke liye. Baad ki layers efficiency aur expressiveness ke liye stacked small kernels use karti hain.

Concept Map

specifies

specifies

specifies

specifies

controls

controls

uses

combats

deeper and wider becomes

smaller 3x3 kernels becomes

fewer params more nonlinearity

CNN Architecture

Depth

Width

Connectivity

Receptive Field

LeNet-5 1998

AlexNet 2012

VGGNet 2014

Skip Connections

Feature Hierarchy

Layer Capacity

Vanishing Gradients