Medical Imaging and Clinical ML
You'll be able to:
You can describe how segmentation (U-Net) and classification models are built and scored for medical images, explain why a model that performs well in one hospital often fails in the next (dataset shift and shortcut learning), and measure whether a model's probabilities can be believed (calibration, reliability diagrams, temperature scaling).
Two tasks, one architecture family
Medical imaging ML mostly does two things. Classification maps an image to a label: pneumonia or not, tumour grade, referable retinopathy. Segmentation maps every pixel (or voxel, in 3D) to a label: this is tumour, this is healthy liver, this is background. Segmentation is the workhorse of radiotherapy planning and organ volumetry, and it is where the U-Net lives.
How a U-Net works
The U-Net paper by Ronneberger and colleagues, in this module's materials, describes an encoder that progressively downsamples the image while increasing feature channels, and a decoder that upsamples back to full resolution. The part that matters is the skip connections: at each resolution, the encoder's feature map is concatenated onto the decoder's. Without them, the decoder must reconstruct fine boundaries from a coarse bottleneck and the edges come out blurry. With them, it gets both "what is here" (from the deep layers) and "exactly where" (from the shallow ones). The original paper trained on about thirty microscopy images using heavy elastic augmentation, which is a reminder that in medical imaging the augmentation and preprocessing choices usually matter more than the architecture. The later nnU-Net work made that point systematically: a plain U-Net with carefully self-configured preprocessing beat most bespoke architectures.
Segmentation is scored with the Dice coefficient — twice the overlap divided by the sum of the two areas — and often with a boundary distance such as the Hausdorff distance, because Dice can be high while a segmentation includes a small but clinically dangerous spur into healthy tissue.
Why the model from hospital A fails at hospital B
Zech and colleagues trained a pneumonia classifier on chest X-rays from two US health systems and tested it on a third. Performance dropped on external data. More telling, a model could identify which hospital an image came from with very high accuracy, and pneumonia prevalence differed between hospitals and between departments. The network had learned that "images that look like they came from the inpatient portable scanner" are more often pneumonia — a true correlation in the training data and a useless one anywhere else. This is shortcut learning: the model finds the cheapest feature that predicts the label.
Related: hidden stratification. A pneumothorax classifier can score well overall while failing on the subset without a chest drain, because in training data the drain (a treatment marker) was the easiest cue. Average metrics hide the subgroup where the model is clinically needed most.
The general name is dataset shift: the joint distribution of images and labels in deployment differs from training. Module 7 covers how to monitor for it; here the lesson is that an internal test set cannot detect it, by construction.
Can the probabilities be believed?
A classifier outputs a score. A clinician will read 0.8 as "80% likely". That is only true if the model is calibrated: among all cases scored 0.8, about 80% should be positive. Guo and colleagues showed that modern deep networks are systematically over-confident — the more capacity and the longer the training, the worse — even as their accuracy improves.
You check calibration with a reliability diagram: bin predictions by score, plot observed positive rate per bin against mean predicted score, and look for the diagonal. Expected calibration error (ECE) summarises the gap as a weighted average over bins. The Brier score combines calibration and discrimination in one number.
The standard fix is temperature scaling: divide the logits by a single scalar T fitted on the validation set to minimise negative log-likelihood. It leaves the ranking — and therefore AUROC — unchanged, and usually brings ECE down substantially. Fit T on validation data, never on the test set, and re-check calibration at each new site, because calibration shifts even when discrimination does not.
Worked procedure: a reliability diagram
- Collect the model's predicted probabilities and true labels on the test split.
- Split the probability range into ten equal bins.
- For each bin, compute the mean predicted probability, the fraction of true positives and the count.
- Plot fraction-positive against mean-prediction with a diagonal reference line; make the marker size follow the count.
- ECE equals the sum over bins of (count divided by total) times the absolute gap between the two values.
- Fit a temperature on the validation split, re-run steps 1–5, and report before and after.
Choosing the metric
AUROC is insensitive to prevalence and is the default in papers. AUPRC is more informative when positives are rare. Neither tells a clinician whether using the model at a given threshold does net good; decision-curve analysis (net benefit across thresholds) does, and it is rarely reported. When you read "radiologist-level AUC", ask which population, which prevalence, and which threshold.
What is still unsettled
Whether imaging foundation models pre-trained on millions of scans reduce dataset shift or merely hide it is an active question. How many "radiologist-level" claims hold under prospective evaluation is, so far, a short list.
What to remember
- Skip connections give a U-Net both context and precise localisation; preprocessing and augmentation matter more than architectural novelty.
- Report Dice and a boundary metric; neither alone describes clinical safety.
- A model learns the easiest predictive feature, which is often the hospital, not the disease; an internal test set cannot reveal this.
- Deep networks are over-confident by default; check a reliability diagram and fit temperature scaling on validation data.
- Calibration must be re-checked at every new site.
Curated Materials
2hThe deep work happens here — the lesson is your briefing.
- U-Net: Convolutional Networks for Biomedical Image Segmentation (Ronneberger et al.)Paper· 40 min
- Variable Generalization Performance of a Deep Learning Model to Detect Pneumonia in Chest Radiographs (Zech et al., PLOS Medicine)Paper· 40 min
- On Calibration of Modern Neural Networks (Guo et al.)Paper· 40 min
Live on aiqbench
This lesson's subject on the rest of the site, today.
In the news, last 30 days
- Can Registry Revision Histories Improve Point-in-Time Forecasts of Clinical Trial Progression?arXiv ·
- Implementation Variability Makes Sepsis-3 an Inconsistent Measuring Model for Early AI Prediction on Clinical DataarXiv ·
- Spectral Parameterization Reveals a Dissociation Between Chronological Age Prediction and Clinical Discrimination in EEG Brain-Age ModelingarXiv ·
Test your knowledge
5 questions in 100 seconds, on a page of its own. Read everything above first.
Test your knowledge →Module Mission
40–45 minInstall the medmnist package (free, pip; the data downloads automatically) and train a small CNN on PneumoniaMNIST for a few epochs on CPU. On the official test split, report AUROC and accuracy, then draw a reliability diagram (ten probability bins) and compute expected calibration error. Apply temperature scaling fitted on the validation split and report the before/after ECE. Save the two plots and a five-line summary.
Loading your work…