Transfer learning

Transfer learning

How transfer learning reuses a model trained on a large source task to solve a new task with little data, through feature extraction, fine-tuning and domain adaptation.

What it is

Transfer learning is the practice of taking knowledge learned on one problem and applying it to a different but related problem. In deep learning this usually means starting from a pretrained model, a network already trained on a large data set such as ImageNet (images), a large text corpus (language) or a large collection of molecules, and adapting it to a new task where labeled data are scarce. The early layers of such networks learn general features (edges, textures, word meanings, atomic environments) that are useful for many tasks, so the new model does not need to learn them from scratch. Transfer learning is the standard approach for medical imaging, microscopy, remote sensing, natural language processing and many scientific applications where labeling is costly, and it is the basis of today’s foundation models (see transformers).

It answers questions such as: How can a good classifier be built from a few hundred labeled images? Can a model trained on one instrument, site or material family work on another? How can a language model be specialized to scientific text? How much training time and compute can be saved? The benefits depend on how similar the source and target problems are.

Fundamentals

Source and target, and why transfer works

A domain consists of a feature space and a data distribution, and a task of a label space and a prediction function. Transfer learning improves learning on a target task using knowledge from a source domain or task. In a deep network, lower layers capture generic, reusable features and higher layers become increasingly task-specific, as visualization studies of convolutional networks showed (see CNNs). Pretraining therefore gives a good initialization, a starting point in weight space that is already near a useful solution, which speeds up convergence, reduces the data required (sometimes by 10 to 100 times) and often improves final accuracy. Pretraining can be supervised (ImageNet classification), self-supervised (predict masked words or image patches, contrastive learning such as SimCLR, which needs no labels and scales to huge unlabeled data), or on related scientific data (such as protein language models or molecular property models).

Main strategies

  • Feature extraction: freeze the pretrained backbone, use its outputs as features, and train only a new head (a linear classifier or small network). It is fast, needs little data, and avoids overfitting, and works best when source and target are similar.
  • Fine-tuning: initialize with pretrained weights, replace the output layer, and continue training some or all layers on the target data with a small learning rate (typically 10−5 to 10−3, much lower than from scratch) so the pretrained features are not destroyed. Gradual unfreezing (training the head first, then unfreezing blocks from top to bottom) and discriminative learning rates (lower rates for earlier layers) improve stability.
  • Parameter-efficient fine-tuning: adapters, prompt tuning and LoRA (low-rank updates ΔW = BA with few trainable parameters) adapt very large models cheaply and reduce forgetting.
  • Domain adaptation: the task is the same but the data distribution differs (a new scanner, a simulated versus real image). Methods align source and target features, using statistics such as maximum mean discrepancy, adversarial training (DANN), or style transfer, and test-time adaptation.
  • Multi-task, few-shot and zero-shot learning: training on several tasks, learning from a handful of examples, or using a prompt-conditioned foundation model with no additional training.

Practical decisions: what, when and how much

The choice depends on target data size and similarity to the source. With little data and a similar domain, use feature extraction or light fine-tuning of the top layers. With much data and a similar domain, fine-tune the whole network. With little data and a different domain, take features from earlier layers and use strong regularization and augmentation, or look for a more related pretrained model. Input preprocessing must match the pretraining (image size, color channels, normalization means and standard deviations; tokenizer and vocabulary for language models), and one-channel scientific images may need to be replicated across channels or the first layer adapted. Batch normalization layers need care: keeping their pretrained statistics or retraining them can matter when the target data differ strongly.

Pitfalls: negative transfer, forgetting and evaluation

Negative transfer occurs when the source is too different and pretraining hurts rather than helps. Catastrophic forgetting is the loss of earlier knowledge during fine-tuning, which matters if the model must still serve the source task, and is reduced by low learning rates, regularization toward the pretrained weights, rehearsal or LoRA. Overfitting is a risk when a large pretrained model is fine-tuned on a very small data set, so use early stopping, data augmentation and cross-validation. Evaluation must be honest: always compare with a model trained from scratch and with a simple baseline, and avoid data leakage, since ImageNet-pretrained models or large language models may have seen test examples, or near-duplicates, in their pretraining data. Split by independent unit (patient, site, material family). Inherited bias and errors in pretraining data pass to the target model, and models can pick up shortcut cues.

Typical applications and limits

Limits: dependence on the similarity between tasks, large pretrained models are expensive to store and run, and the origin and licensing of pretrained weights may restrict use.

Basic operation

  1. Define the target task. State the data, labels and metric, and gather a labeled set.
  2. Select a pretrained model. Choose one trained on data related to your domain, with a suitable size.
  3. Match preprocessing. Resize, normalize and tokenize exactly as in pretraining.
  4. Replace the head. Add an output layer for your classes or values.
  5. Train the head first. Freeze the backbone and fit the new layers.
  6. Fine-tune. Unfreeze layers gradually with a small learning rate and augmentation.
  7. Validate against baselines. Compare with training from scratch and check for leakage.
  8. Collect the output. You obtain an adapted model with measured performance; choosing layers to unfreeze and domain adaptation are covered in the video.

Good practice

  • Use a small learning rate for fine-tuning. Large steps destroy pretrained features.
  • Match the preprocessing. Mismatches silently reduce accuracy.
  • Compare with scratch training. Check that transfer actually helps.
  • Check for test-set overlap. Pretraining data may contain your test examples.
  • Validate on the deployment domain. Test under new devices, sites or conditions.
  • Check licenses and bias. Respect model and data terms, and audit inherited bias before using models for decisions about people.

Key terms

  • Pretrained model — a model already trained on a large data set before adaptation.
  • Fine-tuning — further training of a pretrained model on a new task.
  • Feature extraction — using a frozen network’s outputs as input features.
  • Domain adaptation — adjusting a model to work when the data distribution changes.
  • Negative transfer — pretraining that makes target performance worse.
  • Catastrophic forgetting — losing earlier learned knowledge during fine-tuning.
  • LoRA — a method that fine-tunes large models through small low-rank weight updates.

Video coming soon

About five minutes on Transfer learning: how it works in detail, how the data is acquired, and how it is analyzed.

Shopping cart

0
image/svg+xml

No products in the cart.

Continue Shopping