(छवि वर्गीकरण में CNN का उपयोग)
🔶 1. Image Classification क्या है?
📌 परिभाषा:
Image Classification एक ऐसा task है जिसमें input image को एक predefined class में classify किया जाता है।
उदाहरण: एक model को बताना कि image में dog है या cat।
🎯 2. CNN क्यों बेहतर है Image Classification के लिए?
CNN में मौजूद:
- Convolution layers → local patterns और textures पहचानती हैं
- Pooling layers → size reduce कर feature को concentrate करती हैं
- Dense layers → final decision लेती हैं
👉 ये सब मिलकर CNN को image data पर बहुत सक्षम बना देती हैं।
🧠 3. Typical Image Classification Pipeline (Using CNN)
[Input Image]
↓
Convolution Layers (Feature Extraction)
↓
ReLU + Pooling Layers
↓
Flatten Layer
↓
Fully Connected (Dense) Layers
↓
Softmax (Output → Class Probabilities)
📷 4. Real-world Examples:
Dataset | Classes | Application |
---|---|---|
MNIST | 10 (digits) | Handwritten digit recognition |
CIFAR-10 | 10 (animals, vehicles) | Object classification |
ImageNet | 1000+ | Large-scale classification |
🔍 5. Feature Hierarchy in CNN:
Layer Depth | Learns What |
---|---|
Shallow (1-2) | Edges, corners, color blobs |
Mid (3-4) | Textures, patterns |
Deep (5+) | Objects, faces, full shapes |
🔧 6. PyTorch Code Example: CNN for Image Classification (CIFAR-10)
import torch.nn as nn
class CIFAR10CNN(nn.Module):
def __init__(self):
super(CIFAR10CNN, self).__init__()
self.net = nn.Sequential(
nn.Conv2d(3, 32, 3, padding=1),
nn.ReLU(),
nn.MaxPool2d(2, 2),
nn.Conv2d(32, 64, 3, padding=1),
nn.ReLU(),
nn.MaxPool2d(2, 2),
nn.Flatten(),
nn.Linear(64 * 8 * 8, 128),
nn.ReLU(),
nn.Linear(128, 10) # 10 output classes for CIFAR-10
)
def forward(self, x):
return self.net(x)
📊 7. Output Layer (Softmax)
nn.Softmax(dim=1)
- Converts raw outputs (logits) to probabilities
- Highest probability class is the predicted label
📈 8. Training Process (Overview)
Step | Description |
---|---|
Data Preparation | Image resize, normalization |
Forward Pass | Prediction |
Loss Calculation | CrossEntropyLoss |
Backward Pass | Gradients calculate |
Optimization | SGD, Adam, etc. |
Evaluation | Accuracy, Precision, Recall |
✅ 9. Advantages of CNNs in Image Classification
Benefit | Explanation |
---|---|
Local Feature Extraction | Captures spatial hierarchy |
Translation Invariance | Position of object doesn’t matter |
Parameter Efficiency | Filters shared across image |
End-to-End Learning | No need for manual feature extraction |
📝 Practice Questions:
- CNN image classification में कैसे मदद करता है?
- एक simple CNN architecture लिखिए जो 10-class classification कर सके।
- Feature map क्या होता है?
- CNN में object recognition की hierarchy क्या होती है?
- PyTorch में prediction probabilities कैसे निकाली जाती हैं?
🎯 Summary:
Concept | Use in Classification |
---|---|
Convolution | Extract features from images |
Pooling | Downsample and focus on important parts |
Dense Layers | Final decision making |
Softmax | Class probability distribution |
CNN | End-to-end feature learning system |