Search
The main task is to fine-tune a pretrained CNN for a new classification task (transfer learning).
Skills: data loader from an image folder, data preprocessing, loading pretrained models, remote GPU servers, training part of the model. Insights: convolutional filters, error case analysis
In this lab we start from a model already pretrained on the ImageNet classification dataset (1000 categories and 1.2 million images) and try to adjust it for solving a small-scale but otherwise challenging classification problem.
It is a good time now to start working with GPU servers. Check How To page. The recommended setup is as follows:
SOTA pretrained architectures are available in PyTorch. We will use the following models:
import torchvision.models model1 = torchvision.models.squeezenet1_0(weights=torchvision.models.SqueezeNet1_0_Weights.DEFAULT) model2 = torchvision.models.resnet18(pretrained=True)
print(model)
The dataset is available on the gpu cluster at the path /mnt/datasets/PACS_cartoon/PACS_cartoon. You can also download it from here: PACS_cartoon (84Mb)
/mnt/datasets/PACS_cartoon/PACS_cartoon
The PACS_cartoon dataset contains colored images of cartoons with 227×227 pixels and of 7 categories:
PACS_cartoon
01: Dog 02: Elephant 03: Giraffe 04: Guitar 05: Horse 06: House 07: Person
Before we leverage the power of pre-trained models (Transfer Learning), we must first establish a baseline. In any machine learning project, a baseline serves as a “control group.” It answers the question: “How hard is this dataset to learn from scratch?”
By training a small CNN from scratch on your specific dataset, you will likely encounter the challenge of data scarcity. Without the millions of images used to train models like ResNet or VGG, your custom model may struggle to generalize or may start overfitting (memorizing the training data) quickly. This section effectively demonstrates the problem that Transfer Learning is designed to solve.
Steps:
Now that you have a baseline, we will use Transfer Learning to improve performance. We will compare three distinct strategies:
Strategy A: Linear Probing
requires_grad = False
Strategy B: Bias tuning
Strategy C: Tuning Last $N$ Layers
Visually prove that your training process actually organized the chaos of the initial random weights into structured feature detectors.
cmap=“viridis”
You should upload your results as a pdf file to BRUTE. The report is free-form. You can use LaTeX, docs, pdf export from Jupyter Notebook, etc. Make sure to include everything bolded in assignments in your report.
pdf