CNN architecture
A typical CNN consists of three stages:1. Convolutional layers
A convolution slides a small filter (kernel) across the input, computing a dot product at each position: Key hyperparameters: kernel size, stride, padding, number of filters (channels).2. Pooling layers
Pooling reduces spatial dimensions while retaining dominant features. Max pooling selects the largest value in each local window, making representations more robust to small translations.3. Fully connected layers
After several conv+pool blocks, the feature maps are flattened and passed through standard dense layers to produce class logits.Training a CNN with PyTorch
1
Prepare data loaders
Use
torchvision.datasets and DataLoader to load and batch your images with on-the-fly augmentations.2
Define the model
Build a custom CNN or load a pretrained architecture from
torchvision.models.3
Set loss and optimizer
Cross-entropy loss is standard for multi-class classification. Adam is a reliable default optimizer.
4
Run the training loop
Iterate over epochs, perform forward and backward passes, and update weights.
Transfer learning with pretrained models
Training from scratch requires large datasets. Transfer learning repurposes a model pretrained on ImageNet (1.2 M images, 1000 classes) by replacing only the final classification head.Common pretrained architectures
Evaluation
After training, evaluate on a held-out test set:Resources
Exercise E05: CNN Training
Hands-on exercise: train a CNN from scratch in Google Colab.
VisionColab: Image Classification
Collection of CNN examples and notebooks from the course.
Video: CNN Lecture (2021)
Recorded lecture covering CNN architecture and training.
Video: Complementary CNN
Additional video resource on convolutional neural networks.
