3.4.1 · HinglishConvolutional Neural Networks

Convolution operation and filters

2,253 words10 min readRead in English

3.4.1 · AI-ML › Convolutional Neural Networks

Overview

Convolution operation CNNs (Convolutional Neural Networks) ka fundamental building block hai. Yeh ek mathematical operation hai jo ek chhoti matrix (jise filter ya kernel kehte hain) ko input image ke upar slide karti hai, taaki local patterns jaise edges, textures, ya shapes detect ho sakein. Fully connected layers ki tarah nahi jo har pixel ko independently treat karti hain, convolution spatial relationships ko neighboring pixels ke beech preserve karta hai.

Figure — Convolution operation and filters

Convolution ki Mathematics

Discrete 2D Convolution Kya Hai?

Yeh technically cross-correlation hai, lekin deep learning mein hum ise "convolution" kehte hain (true mathematical convolution kernel ko flip karta hai, lekin hum weights waise bhi seekhte hain, isliye flip irrelevant hai).

First Principles se Derivation

Yeh formula kyun? Hum measure karna chahte hain ki "image ka yeh local patch kitna filter mein encoded pattern se match karta hai?"

Step 1: Local receptive field
Filter input ki ek window dekhta hai. Position par ek 3×3 filter pixels dekhta hai.

Step 2: Element-wise multiplication
Har filter weight corresponding input pixel se multiply hota hai. Yeh ek weighted sum hai jahan filter weights decide karte hain ki hum kaunsa pattern dhundh rahe hain.

Step 3: Accumulation
Hum saare products sum karte hain. Bada positive sum matlab "strong match," zero ke kareeb matlab "pattern present nahi."

Step 4: Filter ko slide karna
Input mein har valid position ke liye repeat karo. Stride control karta hai ki hum kitne pixels skip karte hain: 1 ki jagah se increment karte hue.

jahan padding hai (input borders ke around add kiye gaye zeros), stride hai.

Padding kyun? Iske bina, output har dimension mein pixels shrink ho jaata hai. Padding spatial size preserve karta hai. Stride kyun? Output ko downsample karta hai, computation reduce karta hai (pooling ki tarah).


Filter Actually Kya Detect Karta Hai?


Worked Examples

Example 1: 5×5 Input par 3×3 Filter (Stride 1, No Padding)

Input :

Filter (vertical edge):

Output size: , isliye output.

Top-left output element compute karo :

Yeh step kyun? Hum filter ko top-left 3×3 patch pe overlay karte hain, corresponding elements multiply karte hain, aur sum karte hain. Positive result (3) indicate karta hai ek weak vertical edge (right side thoda brighter than left).

Full output (baaki 8 positions similarly compute karte hue):

Example 2: Stride aur Padding ka Effect

Same input/filter, stride , padding .

Padded input (saare sides par zeros ki ek row/column add karo) → :

Output size: .

Top-left computation ab padded position se start hoti hai, lekin zyaadatar elements 0 hain:

Stride 2 kyun? Hum har doosri position skip karte hain, isliye filter se se tak move karta hai, phir , etc. Output chhota hai lekin compute karna faster hai.

Example 3: Multi-Channel Input (RGB Image)

Real images mein 3 channels hote hain (R, G, B). Filter mein bhi 3 channels hone chahiye.

Input: (height, width, channels)
Filter: (har input channel ke liye ek slice)

Convolution:

Yeh form kyun? Hum filter ko alag-alag har channel pe apply karte hain, phir ek single output value produce karne ke liye channels across sum karte hain. Filter color channels ke across correlations seekhta hai (jaise, "red aur green high, blue low" = yellow).

Multiple filters: Ek CNN layer mein typically filters hote hain (maan lo 64). Har apna feature map produce karta hai, isliye output hai.


Common Mistakes aur Fixes


Active Recall Flashcards

#flashcards/ai-ml

Position (i,j) ke liye discrete 2D convolution formula kya hai? ::

Convolution ke baad output height formula kya hai?
jahan p=padding, k=kernel size, s=stride
Images ke liye hum fully connected layers ki jagah convolution kyun use karte hain?
1) Parameter sharing: wahi filter image across slide karta hai, drastically kam weights. 2) Translation invariance: learned feature detectors image mein kahin bhi kaam karte hain.
Vertical edge detection filter (3×3) kaisa dikhta hai?
(negative left, positive right)
Stride aur dilation mein kya difference hai?
Stride control karta hai filter input across kitna move karta hai (downsampling). Dilation filter elements ke beech spacing control karta hai (parameters add kiye bina receptive field expand karta hai).
RGB image (3 channels) ke liye filter ki shape kya honi chahiye?
— teesra dimension (depth) input channels se match karna chahiye. Output depth = number of filters.
CNNs mein translation invariance kya hai?
Wahi learned filter same feature (edge, texture) detect karta hai, chahe woh image mein kahin bhi appear ho. Billi top-left ya bottom-right dono mein recognize hoti hai.
Agar input 32×32×3 hai, filter 5×5×3 hai, stride=1, padding=2 toh output shape kya hai?
, isliye 32×32×1 per filter. Agar 64 filters hain, output 32×32×64 hai.

Feynman Explanation

Recall Ek 12-Saal ke Bachche ko Explain Karo

Socho tumhare paas apne kuttey ki ek badi photo hai, aur tum sabhi jagah dhundna chahte ho jahan vertical line hai (jaise ek darwaze ka kinara). Tum poori photo ek saath nahi dekh sakte—yeh bahut zyada hai! Isliye, tum ek magnifying glass (the filter) use karte ho jo ek baar sirf ek chhota 3×3 square dekhta hai.

Us magnifying glass ke andar, tumne ek special pattern banaya hua hai: "Agar left side dark hai aur right side bright hai, yeh ek vertical edge hai!" Tum har pixel jo dikh raha hai use is pattern se multiply karte ho aur add karte ho. Agar sum bada hai, tum ek naye kaagaz par likhte ho "Yahan edge mili!"

Ab magnifying glass ko ek step right slide karo, aur dobara check karo. Slide, check, slide, check—poori photo mein, row by row. Naya kaagaz (the feature map) tumhe dikhata hai kahan-kahan vertical edge pattern appear hua.

Kamaal ki baat? Tumne magnifying glass pattern sirf ek baar design kiya, lekin tumne ise photo mein hazaaron baar use kiya. Yeh har single pixel ke liye alag magnifying glass banane se kahin zyada easy hai!

CNN mein, computer seekhta hai ki kaunse patterns dhundhe (edges, colors, shapes) lakho examples try karke. Early layers simple cheezein dhundti hain jaise edges. Deeper layers un edges ko complex cheezein jaise "kuttey ke kaan" ya "cycle ke pahiye" mein combine karti hain.


Connections

  • 3.4.02-Pooling-layers — Convolution ke baad, pooling feature maps ko downsample karta hai
  • 3.4.03-CNN-architectures — Convolution + pooling stack karo networks jaise LeNet, AlexNet banane ke liye
  • 3.3.01-Backpropagation — Filters kaise seekhte hain: gradients convolution ke through wapas flow karte hain
  • 2.2.05-Receptive-fields — Har output neuron local input region "dekhta" hai
  • 3.4.10-Depthwise-separable-convolutions — Efficient variant jo spatial aur channel-wise convolution alag karta hai
  • 4.1.03-Transfer-learning — Pretrained filters (ImageNet) low-level features naye tasks mein transfer karte hain
  • 3.4.06-Batch-normalization — Feature maps ko normalize karta hai training stabilize karne ke liye

Mnemonic

Channels ke liye: "Filter Depth Must Match Input Depth" (FD = ID).


Key Takeaways

  1. Convolution = local pattern matching: Filters templates encode karte hain (edges, textures), output har location par match strength measure karta hai.
  2. Parameter sharing: Wahi chhota filter poori image mein reuse hota hai → fully connected se kahin kam weights.
  3. Translation invariance: Learned features image mein kahin bhi kaam karte hain.
  4. Dimensions matter karte hain: Filter depth = input channels. Output channels = number of filters.
  5. Stride & padding control: Stride downsample karta hai, padding size preserve karta hai. Formula: .
  6. Learned representations: Backprop filter weights tune karta hai task ke liye useful features extract karne ke liye.

Convolution master karo, aur tum computer vision models ka dil samajh jaoge.

Concept Map

built from

slides

replaces

preserves

enforces

acts as

scores produce

controlled by

uses

affects

affects

reuses weights so reduces params

Convolutional Neural Networks

Convolution Operation

Filter / Kernel

Fully Connected Layers

Spatial Relationships

Translation Invariance

Feature Map

Template Matching

Stride s

Padding p

Output Dimensions