Image Classification
Module: Computer Vision | Difficulty: Beginner
ResNet Skip Connections
Enables training of very deep networks (100+ layers).
EfficientNet Scaling
Compound scaling: depth , width , resolution
subject to
Data Augmentation
- Random horizontal flip
- Random crop with padding
- Color jittering
- Cutout: zero out random patches
- Mixup: blend two images:
Transfer Learning
Fine-tune last layers with small learning rate.
import torch
import torch.nn as nn
import torchvision.models as models
def create_classifier(num_classes, pretrained=True):
model = models.efficientnet_b0(pretrained=pretrained)
model.classifier[1] = nn.Linear(model.classifier[1].in_features, num_classes)
return model
class Cutout:
def __init__(self, length):
self.length = length
def __call__(self, img):
h, w = img.shape[1:], img.shape[2:]
mask = torch.ones_like(img)
cy = torch.randint(h, (1,))
cx = torch.randint(w, (1,))
y1 = (cy - self.length // 2).clamp(0, h)
y2 = (cy + self.length // 2).clamp(0, h)
x1 = (cx - self.length // 2).clamp(0, w)
x2 = (cx + self.length // 2).clamp(0, w)
mask[:, y1:y2, x1:x2] = 0
return img * mask
Key Takeaways
- Residual connections enable very deep network training
- EfficientNet provides optimal accuracy-efficiency trade-off
- Transfer learning dramatically reduces data requirements