Interview's MateData Science
Interview's Mate

Data Science

Python → ML → MLOps

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Science topics
Lesson 130/ 160
07. Deep Learning & NLP

Transfer Learning & Pre-trained Vision Backbones

Fine-tune ImageNet backbones instead of training vision models from scratch.

IntermediateBackbones · Fine-tune3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Instead of teaching a computer to see from nothing, you start with one that already knows what edges, shapes and textures look like and just teach it your specific pictures.

Think of it like…

Hiring an experienced photographer for a new assignment. They already know light, composition and framing (the pretrained backbone), so you only teach them your client's specific subjects (the new head), and if the subject is very different you give them some extra training time at a gentle pace (fine-tuning).

Where you’ve seen it

A team has 2,000 labelled photos of five plant diseases. They load a ResNet-50 (about 25.6 million parameters) pretrained on ImageNet and swap the 1,000-way output for a 5-way head: 2,048 × 5 + 5 = 10,245 trainable parameters, about 0.04% of the model. Preprocessing matches the backbone: resize to 224 × 224 and normalise with the ImageNet means (0.485, 0.456, 0.406) and standard deviations (0.229, 0.224, 0.225). Stage 1 freezes the backbone and trains the head for a few epochs; because the backbone is frozen they can even cache the 2,048-dimensional features once (2,000 × 2,048 × 4 bytes ≈ 16.4 MB) and train the head in seconds. Stage 2 unfreezes the last residual block with a learning rate of 1e-4 for the backbone and 1e-3 for the head (discriminative rates, 10× lower for pretrained layers). They keep BatchNorm layers in evaluation mode while the backbone is frozen so running statistics don't drift on a small batch. In a typical small-data comparison like this, a from-scratch ResNet might reach around 71% accuracy while the fine-tuned model reaches around 93% (illustrative figures); they confirm on a held-out set and run a per-class check, since one rare disease still lags. For aerial or microscope imagery, very different from ImageNet photos, they would unfreeze more layers and expect smaller gains.

Words you’ll hear

Backbone
The pretrained feature-extraction layers, before the task-specific head.
Feature extraction
Freezing the backbone and training only a new head.
Fine-tuning
Continuing to train some or all pretrained layers at a low learning rate.
Discriminative learning rates
Different learning rates for different layer groups, lower for pretrained ones.

Visual diagram

Loading interactive diagram

Theory & deep dive

Why it works and which mode to use

Early convolutional layers learn generic features (edges, colour blobs, textures) that transfer across tasks; later layers become increasingly specific to the source classes. That is why you can reuse most of the network and replace only the last layer. The choice of mode depends on data size and domain similarity: with a small dataset and a similar domain, freeze the backbone and train the head; with more data or a somewhat different domain, fine-tune the last blocks; with a large dataset in a very different domain, fine-tune the whole network at a low learning rate (or consider a different pretrained source).

Replacing the head is simple: for ResNet-50 the final feature vector is 2,048-dimensional, so a 5-class head has 2,048 × 5 + 5 = 10,245 parameters, a tiny fraction of the 25.6 million in the backbone. Because the frozen backbone is a fixed function, you can precompute and cache features once (2,000 images × 2,048 values × 4 bytes ≈ 16.4 MB) and train a logistic regression or small MLP on them in seconds, a strong baseline that is also cheap to iterate on. Move to full fine-tuning only if this baseline underperforms.

What changes in the model

Backbone: 25.6M parameters, frozen in stage 1. Head: 2,048 × 5 + 5 = 10,245 trainable parameters. Stage 2 unfreezes the last block (a few million parameters) at lr 1e-4 while the head stays at 1e-3.

Key takeaway: Start with a frozen backbone and a new head, then unfreeze progressively as data and domain distance justify.

Practical details that cause silent failures

Preprocessing must match what the backbone was trained with: input size, channel order and the ImageNet mean and standard deviation, or the pretrained features see out-of-distribution inputs. BatchNorm is the usual trap: with a small batch, updating running statistics on your data can degrade a frozen backbone, so keep BatchNorm layers in eval mode (and their parameters frozen) when you freeze the body, or use a backbone with LayerNorm or GroupNorm. Learning rates: pretrained layers need small values (1e-5 to 1e-4 with Adam-style optimisers, about 0.001 to 0.01 with SGD) or the first steps wipe out what was learned (catastrophic forgetting); use warm-up and discriminative rates.

Evaluation: keep a held-out set from the same distribution as deployment, check per-class metrics and calibration, and compare against a from-scratch and a feature-extraction baseline so the benefit is measured. Watch for data leakage between train and test (near-duplicate images from the same plant or patient must be split together). Consider newer backbones (EfficientNet, ConvNeXt or a vision transformer) and mixed precision to speed fine-tuning. Document the backbone, weights version and licence, because the pretrained model is a dependency like any other.

Discriminative learning rates

Parameter groups: head lr 1e-3, last backbone block lr 1e-4, earlier blocks frozen (lr 0). After a few epochs, optionally unfreeze the next block at 3e-5. Each stage is validated before moving on.

Key takeaway: Match preprocessing, protect BatchNorm, use small learning rates for pretrained layers and split near-duplicates before evaluating.

How it works, step by step

Step 1 of 4
Data scientist

1. Choose and load a backbone

Pick a pretrained model suited to the compute budget and load it with its matching preprocessing.

ResNet-50 · ImageNet mean/std
Key numbers at this step
Record
weights version

When to use it & trade-offs

What it is

Transfer learning starts from a model pretrained on a large dataset (for vision, usually ImageNet) and adapts it to your task. There are two standard modes. In feature extraction you freeze the backbone, replace the final classification layer with a new head and train only that head. In fine-tuning you also unfreeze some or all backbone layers and train them with a small learning rate, often with discriminative learning rates (smaller for early layers, larger for the head). The pretrained layers already encode edges, textures and object parts, so the model needs far fewer labelled images and far less compute than training from scratch.

Why it matters: Labelled images are expensive, and a deep network trained from scratch on a few thousand examples will overfit. A pretrained backbone brings features learned from over a million images, so a small dataset can reach accuracy that would otherwise need orders of magnitude more data. The practical skills are choosing between freezing and fine-tuning, matching the preprocessing the backbone expects, handling BatchNorm layers correctly, setting learning rates so you don't destroy the pretrained weights and recognising when the source and target domains are too different.

When to reach for it

  • Image classification with hundreds to a few thousand labelled examples
  • Feature extraction plus a simple classifier as a baseline
  • Starting point for detection and segmentation models

When to avoid or be careful

  • Training a large CNN from scratch on a small dataset
  • Feeding images that skip the backbone's normalisation
  • Fine-tuning everything at a high learning rate

Ways to use a pretrained backbone

Feature extraction (frozen)
Best for: Small datasets close to the source domain

Strengths: Fast; hard to overfit; cacheable.

Watch out: Limited adaptation to the new domain.

Partial fine-tuning
Best for: Moderate data, some domain shift

Strengths: Good accuracy for modest compute.

Watch out: Needs careful learning rates.

Full fine-tuning
Best for: Large datasets or distant domains

Strengths: Maximum adaptation.

Watch out: Costly; risk of forgetting and overfitting.

Training from scratch
Best for: Very large datasets or unusual input types

Strengths: No source bias.

Watch out: Data hungry and expensive.

Interview signals & numbers to know

When this topic comes up

  • “How would you build an image classifier with 2,000 labelled images?”
  • Freezing versus fine-tuning
  • Discriminative learning rates
  • BatchNorm during fine-tuning
  • Domain shift from ImageNet

Benchmarks & rules of thumb

25.6M -
approximate ResNet-50 parameter count
10,245 -
parameters in a 2,048 → 5 head
≈ 16.4 MB -
cached 2,048-d float features for 2,000 images

Common mistakes & follow-ups

Common interview mistakes

  • Updating BatchNorm statistics on tiny batches while the backbone is meant to be frozen.
  • Using a head learning rate for the whole pretrained network.
  • Splitting near-duplicate images across train and test.

Likely interviewer follow-ups

  • When would you unfreeze the entire backbone?
  • What preprocessing does a pretrained model expect?
  • How do you know transfer learning actually helped?
Interview tip: Propose a frozen-backbone baseline with cached features first; it is cheap, fast and sets the bar for anything more elaborate.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Transfer Learning & Pre-trained Vision Backbones with data science interview Q&A and hands-on practice.

Open Data Science Q&A →Machine Learning Q&A
Previous topic
Convolutional Neural Networks (CNNs)
Next topic
Object Detection & Image Segmentation Basics