Modules / Deep Learning / Transfer Learning

What is Transfer Learning in CNN?

Select a pre-trained model, choose a strategy, and selectively unfreeze layers to see how fine-tuning impacts the learning curve and final accuracy.

Model Architecture

Click Conv layers to toggle Freezing

Understanding Transfer Learning

Why reinvent the wheel? Learn how to reuse powerful models trained by giant tech companies for your own custom tasks.

What is Transfer Learning?

Training a Deep Convolutional Neural Network from scratch requires millions of images (like the ImageNet dataset), massive amounts of computing power (GPUs), and weeks of training time. Furthermore, early layers in a CNN generally learn the exact same things regardless of the dataset: generic edges, colors, and basic textures.

Transfer Learning is the practice of taking a pre-trained model (whose weights have already been optimized on a massive dataset) and repurposing it for a new, related task. You are transferring the "knowledge" of visual features to a new domain.

How it Works: Modifying the Architecture

A standard pre-trained model (like ResNet-50 or VGG-16) is split into two conceptual parts:

  • The Convolutional Base: Extracts features. We keep this part and its pre-trained weights.
  • The Classification Head (Dense Layers): Outputs predictions for the original 1000 classes. We remove this part, because we want to predict our own classes (e.g., 2 classes for Medical X-Rays).

After removing the original head, we attach a new, randomly initialized Dense layer matching our target class count. Now, we have to decide how to train this new hybrid model.

The Three Strategies

  1. Train from Scratch:

    We ignore pre-trained weights and initialize the entire network randomly. The network has no prior knowledge. The accuracy climbs very slowly, and on a small dataset, heavy models like VGG-16 will likely overfit and fail to reach high performance.

  2. Feature Extraction (Freeze the Base):

    We load the pre-trained weights into the Conv Base and freeze them (set them to untrainable). During training, only the weights of our newly added Dense Head are updated. The frozen base acts as a powerful feature extractor. Training is extremely fast, and accuracy jumps up quickly because the network already knows how to "see".

  3. Fine-Tuning (Selective Unfreezing):

    First, we perform Feature Extraction. Then, we unfreeze specific layers of the Convolutional Base (usually the top layers) and train them alongside the Dense Head using a very small learning rate. (In the app, select Fine-Tune and click layers to unlock them). We keep early layers frozen (generic edges), but let later layers adapt their specific shape-detectors to our custom images. This pushes the accuracy to its absolute maximum limit.

Catastrophic Forgetting

In Fine-Tuning mode, try unfreezing all the Convolutional layers. You will notice the accuracy curve might drop or cap lower than expected. If you unfreeze the entire network and train it on a small dataset, the massive gradients from the randomly initialized Dense Head propagate backward and wreck the delicate, pre-trained weights of the entire base. This is called Catastrophic Forgetting.

Key Takeaways

  • Transfer Learning reuses Convolutional layers from models trained on huge datasets.
  • Freezing a layer means its weights are locked and not updated during backpropagation.
  • Optimal Fine-Tuning usually involves unfreezing only the top 1 or 2 Convolutional blocks.
  • Different architectures (VGG vs ResNet) have vastly different parameter counts and training speeds.
Cheat sheet

Transfer Learning with CNN

Training a Deep Convolutional Neural Network from scratch requires millions of images (like the ImageNet dataset), massive amounts of computing power (GPUs), and weeks of training time. Furthermore, early layers in a CNN generally learn the exact same things regardless of the dataset: generic edges, colors, and basic textures.

COMPUTER VISION · vizlearn.in/computer_vision/transfer_learning_with_cnn.html