(कन्वोल्यूशन क्या है?)
🔶 1. Convolution क्या होता है?
Convolution एक mathematical operation है जो दो functions (या arrays) को combine करता है ताकि तीसरा function निकाला जा सके जो दोनों का अर्थपूर्ण interaction बताता है।
Deep Learning में, convolution का उपयोग image से features निकालने के लिए किया जाता है — जैसे edges, patterns, curves आदि।
🧮 Convolution in Math (1D):

जहाँ:
- x = input
- w = filter/kernel
- ∗ = convolution operation
📸 2. Convolution in Images (2D Case)
✅ Image = 2D Matrix of Pixels
✅ Filter/Kernel = Small matrix (e.g. 3×3, 5×5)
Operation:
- Filter को image के ऊपर slide किया जाता है (called stride)
- हर जगह पर input और filter के corresponding values multiply और sum होते हैं
- Result: एक नया feature map तैयार होता है
🧠 Example (3×3 Filter over 5×5 Image):
Input Image (5×5):
1 1 1 0 0
0 1 1 1 0
0 0 1 1 1
0 0 1 1 0
0 1 1 0 0
Filter (3×3):
1 0 1
0 1 0
1 0 1
Apply convolution → Output feature map (3×3)
🔁 Steps:
- Filter top-left पर रखें
- Overlapping values का element-wise product लें
- उनका sum लें → यह output feature का एक value बनेगा
- Filter को आगे move करें (stride से)
- Repeat until entire image covered
🔍 3. Why Convolution?
Feature | Benefit |
---|---|
Locality | Nearby pixels के relationships capture होते हैं |
Parameter Sharing | Same filter पूरे image पर use होता है → कम parameters |
Translation Invariance | Object कहीं भी हो, features detect होते हैं |
🖼 4. Visual Summary:
[Input Image]
↓
[Filter/Kernel Slides]
↓
[Feature Map Generated]
🔧 5. PyTorch Code Example:
import torch
import torch.nn as nn
conv = nn.Conv2d(in_channels=1, out_channels=1, kernel_size=3, stride=1, padding=0)
# Dummy input image: 1 channel, 1 image of size 5x5
input = torch.randn(1, 1, 5, 5)
output = conv(input)
print(output.shape) # → torch.Size([1, 1, 3, 3])
🎯 Summary:
Term | Meaning |
---|---|
Convolution | Operation to extract features |
Kernel/Filter | Small matrix that slides over image |
Feature Map | Output of convolution |
Stride | Step size of filter movement |
Padding | Extra pixels added to retain size |
📝 Practice Questions:
- Convolution operation image पर कैसे काम करता है?
- Kernel क्या होता है? इसका आकार क्यों छोटा रखा जाता है?
- Convolution में parameter sharing का क्या फायदा होता है?
- PyTorch में 2D convolution कैसे implement किया जाता है?
- Padding और stride का output shape पर क्या असर पड़ता है?