Transfer Learning: Standing on the Shoulders of Large Models

How pre-trained models (ImageNet, medical foundation models) can be fine-tuned for your specific clinical task with far less data than training from scratch.


A radiology resident doesn't start by learning what an edge is. They arrive with twenty-odd years of looking at the world, several years of anatomy, and a general idea of what a chest contains. Residency teaches the last, specialized part.

Transfer learning gives a model the same head start. We take a network that has already been trained on a very large dataset for some other purpose, and continue training it on our own, much smaller dataset for our own task. It is the standard way of working in medical imaging, mainly because clinical datasets are small and this makes small datasets go a lot further.

Why it works

A deep network learns in layers. As 1.3 Common AI Architectures in Medicine describes, the early layers respond to simple things like edges, gradients and textures, the middle layers to combinations of those, and only the last layers to anything specific to the task.

Edges and textures are much the same whether the picture is of a dog or a liver. So the early and middle layers of a network trained on one kind of image are useful for another kind, and only the later layers need substantial retraining. A network trained from scratch has to spend its data learning what an edge is. A pretrained network can spend its data on your disease.

Where pretrained models come from

ImageNet

For about a decade the default starting point was a network trained on ImageNet, a collection of everyday photographs. The version used for pretraining has about 1.2 million images in 1,000 categories, a good number of which are dog breeds.

It seems odd that a network trained to tell a husky from a malamute should help with mammograms, but it does. In 2016 Nima Tajbakhsh and colleagues compared training from scratch with fine-tuning ImageNet-pretrained networks across several medical imaging tasks, and found that fine-tuning did as well or better in every case, with the largest advantage when training data was limited.

The benefit has limits. As mentioned in 2.2 How Much Data Do You Need?, Maithra Raghu and colleagues showed in 2019 that on large medical datasets ImageNet pretraining mostly made training faster without improving the final result much. Pretraining helps most when your own data is scarce, which for most clinical researchers is most of the time.

Medical pretraining

Photographs differ from medical images in obvious ways: they are colour, two-dimensional and 8-bit, and the object of interest usually fills the frame. A model pretrained on medical images should be a closer starting point, and there are now several sources.

Some are supervised on large labeled medical collections. RadImageNet, published by Xueyan Mei and colleagues in 2022, is a set of about 1.35 million CT, MRI and ultrasound images with labels, built specifically to be a radiology counterpart to ImageNet.

Most of the newer ones are self-supervised, which removes the need for labels and so allows much larger collections (see 1.2 Supervised, Unsupervised, and Self-Supervised Learning). In 2021 Shekoofeh Azizi and colleagues at Google showed that adding a round of self-supervised pretraining on unlabeled medical images, on top of ImageNet pretraining, improved both chest radiograph and dermatology classifiers. Since then, self-supervised "foundation models" have been released for chest radiographs, pathology slides, retinal photographs and CT, among others (see 1.4 Foundation Models and Large Language Models in Clinical Research).

Is medical pretraining always better than ImageNet? Usually somewhat, when the modality matches, though the margin varies a lot from task to task and it's an easy thing for your engineers to test both.

Models you can use as they are

At the far end of the scale are pretrained models that already do the task. TotalSegmentator, released by Jakob Wasserthal and colleagues in 2023, outlines over a hundred anatomical structures on CT without any training on your part. Promptable segmentation models in the Segment Anything family will outline whatever you click on. If one of these does what you need, the "development" project becomes an evaluation project: you still have to show it works on your patients, but you may not need to train anything.

Ways of using a pretrained model

There are a few options, and they differ in how much of the pretrained network is allowed to change.

Feature extraction keeps the pretrained network completely fixed. Each image is run through it, the output of the last layers is taken as a list of numbers describing the image, and a small, simple classifier is trained on those numbers. This is fast, needs no GPU to speak of once the features are computed, and works with very little data, sometimes a few dozen cases per class. Engineers also call it linear probing.

Fine-tuning continues training the pretrained network on your data, so that its weights shift toward your task. This usually gives better results than feature extraction if there is enough data to support it. It is done gently, with a low learning rate, so that the new data adjusts what the network knows without wiping it out.

In between, the early layers can be frozen while the later ones are fine-tuned. A common recipe is to train only the new final layer first, then unfreeze the rest and fine-tune everything at a low learning rate.

As a rough guide, the less data you have and the closer the pretraining data is to yours, the more of the network you leave alone. Your engineers will know this. What is useful for you to know is that these are different methods with different data appetites, and that "we used a pretrained model" in a paper should say which.

What you still have to supply

Transfer learning reduces the amount of labeled data needed for training. It doesn't change anything else in the project.

You still need labels of good quality for fine-tuning. A pretrained model fine-tuned on inconsistent labels learns the inconsistency just as readily (see 2.3 Data Annotation and Labeling for Clinical AI).

You still need a full-sized test set. The test set's size is set by the precision you want in the result, and a head start in training does nothing for that.

You still need data from the range of sites and scanners the model will meet. Pretrained models often generalize somewhat better than models trained from scratch, but a model fine-tuned on one hospital's images still has to be shown to work at another.

What you inherit

A pretrained model comes with a history, and some of it comes along into your project.

Mismatched formats

An ImageNet model expects a small, square, three-channel colour image with 8 bits per channel. A CT is a three-dimensional volume of 12-bit greyscale values. To use the one on the other, engineers typically feed slices one at a time, copy the grey channel three times or put three different window settings into the three channels, and shrink the image. Each of these is a compromise, and the shrinking in particular can lose small findings (see 2.5 Data Preprocessing and Augmentation). Models pretrained on 3D medical volumes avoid some of this.

The pretraining data, which you probably can't inspect

Whatever was in the pretraining data shaped the model. If that data under-represented some patient groups or scanner types, the model's features may serve those groups less well, and you won't be able to check the pretraining data to find out. The practical response is to check the outcome: evaluate the fine-tuned model by subgroup on your own data (see 7.2 Demographic Fairness).

Possible overlap with your test set

Many medical foundation models were pretrained on the well-known public datasets. If your test set comes from one of those same datasets, the model may have seen your test images during pretraining. It didn't see your labels, so this is a milder problem than the leakage described in 3.2 Training, Validation, and Test Sets, but it does make the test less independent than it looks. It's worth finding out what the model was pretrained on and saying so in the paper.

Licence terms

Pretrained weights come with licences. Some allow any use. Some are restricted to non-commercial research, which is fine for a paper and a serious obstacle if the work is later spun out. The ImageNet images themselves were collected from the web and are offered for non-commercial research. If commercial use is a possibility, it's worth having someone check the licences of the model and its training data before building on it.

Questions from regulators

For a medical device, the pretrained model is part of the device. A reviewer will want to know where it came from, what it was trained on and how you have controlled for what you can't know about it. Third-party software components have their own requirements under the software lifecycle standard (see 6.9 Software Lifecycle Requirements: IEC 62304). A model with documented provenance is a good deal easier to defend than one downloaded from a link in a forum post.

When it doesn't help

There are a few situations where transfer learning adds little or even hurts.

With a very large labeled dataset, training from scratch catches up, as the Raghu study found.

When the pretraining data is very unlike yours, the head start is smaller. Features learned from photographs transfer reasonably to radiographs and less obviously to, say, raw ultrasound signal data or ECG traces. Occasionally a pretrained start does worse than a random one, which is called negative transfer. It is uncommon in imaging.

And for tabular clinical data there has, until recently, been not much to transfer from. A gradient-boosted model on your own table is still the usual starting point.

The simple check, in every case, is to run the comparison: the same model with and without pretraining, on the same validation set.

Key takeaways

  • Transfer learning starts from a model already trained on a large dataset and adapts it to your task. It is the default in medical imaging because it works with far less labeled data.
  • It works because early and middle layers learn general visual features that carry over between kinds of image.
  • Starting points include ImageNet models, models pretrained on medical images such as RadImageNet, self-supervised foundation models, and ready-made tools such as TotalSegmentator.
  • Feature extraction keeps the pretrained network fixed and suits very small datasets. Fine-tuning adjusts the network and usually does better with more data.
  • You still need good labels, a full-sized test set and data from several sites.
  • A pretrained model brings its training data's biases, possible overlap with public test sets, licence terms and provenance questions with it.
  • The benefit shrinks as your own dataset grows, so compare with and without pretraining.

This article is part of the AI in Clinical Research Knowledge Base.