Computer Vision
Brain MRI Screening with Few Labels
Case study: A medical imaging startup
About 1,500 brain MRI scans, only 100 labeled by doctors: can a model learn to spot tumors when almost nothing is labeled?
Explore the scan mapThe problem
Case study: a medical imaging startup wants to detect brain tumors on MRI scans. It has about 1,500 scans, and only 100 of them are labeled by doctors as healthy or tumor. Labels are expensive, and the next step would be 4 million images with a 5,000 € labeling budget. Two questions: can a model learn when almost nothing is labeled, and can labeling at that scale be done mostly by AI?
What the demo does
The demo is a map of the dataset, about 1,400 scans. A pretrained vision model (DINOv2) turns each scan into a list of numbers that describes what it looks like, and similar scans end up close together. Doctor-labeled scans are colored (healthy or tumor), the rest are gray. Tap any point to see the scan and its nearest neighbours.
A slider adds doctor labels a few at a time. You watch them spread to nearby unlabeled scans, which is the idea behind semi-supervised learning: a few labels plus a lot of unlabeled data.
The last button is the discovery. It recolors the map by the angle the scan was taken from and by its brightness. Those two details have nothing to do with a tumor, yet they already split the two classes.
This is a demonstration of method, not a medical tool. It must not be used to interpret real scans.
Results
- 0.986AUC with 72 doctor labels
- Show the model one tumor scan and one healthy scan: 98.6% of the time it rates the tumor scan as more suspicious. With no doctor label at all it still reaches 0.964. Scores this high deserved a closer look.
- 96%Top-down views among scans called healthy
- In this dataset, healthy scans are almost all top-down views while tumor scans are often side or front views. The model picked up that shortcut: 96% of the scans it calls healthy are top-down views (22 of 23 checked by hand).
- 0.79AUC from lighting alone
- Even among scans all taken from the same angle, a model that only measures how bright the brightest pixels are still guesses the label far better than chance (0.5). That is a second shortcut, unrelated to tumors.
Step 1, checking the data before any model. I found 1,506 files instead of the announced 1,500, JPEGs instead of PNGs, and no metadata at all, so there is no way to know whether two scans come from the same patient. Comparing file fingerprints found 96 duplicate files. 31 doctor-labeled scans were also sitting in the unlabeled pool under another name: without cleaning, the model would have been graded on scans it had already seen. A second pass by visual similarity removed 21 near-duplicates (re-saved copies with different bytes). That left 1,389 scans, 97 of them labeled.
Step 2, grouping without labels. Two pretrained models, ResNet50 and DINOv2, turned each scan into a vector without any training. Clustering the DINOv2 vectors matched the doctor labels with an ARI of 0.660 (0 is chance, 1 is a perfect match). Those groups became rough "weak labels" for the 1,292 unlabeled scans.
Step 3, training. I fine-tuned a ResNet18 three ways and scored it with 4-fold cross validation on the 97 labeled scans:
| Model | Doctor labels used | AUC |
|---|---|---|
| Supervised | 72 | 0.986 |
| Semi-supervised (weak labels first, then doctor labels) | 72 | 0.974 |
| Weak labels only | 0 | 0.964 |
With only 10 doctor labels, the semi-supervised model reached 0.978. The supervised model stays ahead at every number of labels, but only by 0.003 to 0.025. Two classic semi-supervised methods on the DINOv2 vectors, pseudo-labeling (0.958) and label spreading (0.950), matched a supervised logistic regression (0.955). At equal recall the supervised model still wins: to catch 95% of tumors it raises 8 false alarms for every 100 correct alerts, against 17 for the semi-supervised one.
Step 4, doubting the score. Near-perfect results on a few dozen test images called for a closer look, and the first step had already pointed to the problem:
- 96% of the healthy scans are top-down views, against 42% of the tumor scans. The rule "not a top-down view, so tumor" is right 29 times out of 31 without looking for a tumor at all. A few scans even carry a website banner: the set seems to have been gathered from web pages, different ones for each class.
- After training, I checked the model's answers on the unlabeled scans whose angle I had noted by hand. Of the 23 it calls healthy, 22 (96%) are top-down views. It learned the shortcut.
- Lighting is a second, separate leak. Five numbers that describe only how the image is lit (average brightness, contrast, share of dark background, symmetry, level of the brightest pixels) already reach an AUC of 0.82. Keeping only top-down views, the brightest-pixel level alone still reaches 0.79, and a permutation test over 300 shuffles rules out luck.
I could neutralize the angle. A small classifier learned the angle from my 196 hand annotations (99% accurate) and filtered the set down to 734 top-down views. On those, the clustering score rose from 0.606 to 0.711 while the lighting-only baseline stayed below 0.26, so what remains is more than the shortcut. The lighting leak is still there: normalizing each image on its own did not remove it.
My conclusion: semi-supervised learning keeps its promise on cost (going from 72 doctor labels to none costs 0.022 AUC), but as long as both leaks are there, none of these scores cleanly measures tumor detection. Computing power is not the obstacle, since at the measured speed of 190 scans per second one GPU would process 4 million scans in about 6 hours. The data collection has to be fixed before scaling: same machine and protocol for both classes, patient IDs in the metadata, and a validation set labeled by radiologists and kept out of the training loop.
Limits: 97 labeled scans, so 24 or 25 test scans at a time; a 50/50 split between classes that does not reflect how rare tumors really are; and no patient-level split, for lack of metadata.
How it's built
Architecture, stack and technical choices.
Diagram as text
flowchart LR
A["1,506 files"] --> B["Duplicates removed:<br/>file hash, then visual similarity"] --> C["1,389 scans<br/>97 labeled"]
C --> D["Frozen ResNet50 and DINOv2<br/>one vector per scan"]
D --> E["PCA to 50 dimensions<br/>+ agglomerative clustering"] --> F["Weak labels<br/>for 1,292 scans"]
F --> G["ResNet18 fine-tuned:<br/>weak only, supervised, semi-supervised"]
C --> H["Leak checks:<br/>scan angle, brightness"]
H -.-> GStack
- Python
- PyTorch
- torchvision
- timm
- DINOv2
- ResNet
- scikit-learn
- NumPy
- pandas
- Matplotlib
- uv
- Preprocessing: resize to 224×224 and ImageNet normalization, which both models expect. I also tried normalizing each image on its own to erase brightness differences. It changed nothing, because the leak is carried by the brightest pixels relative to the rest of the image.
- Features: ResNet50 at two depths (the final
avgpoollayer, 2,048 numbers, and the middlelayer3, 1,024 numbers, captured with a hook) and DINOv2 ViT-S/14 (384 numbers), all frozen. Extracting all 1,410 unique scans took 7.4 seconds on a GPU. The middle ResNet layer beat the final one with k-means (ARI 0.443 against 0.208): the last layer is specialized in everyday photos. - Clustering: k-means, agglomerative and DBSCAN, scored with ARI against the doctor labels and against the scan angle. DBSCAN found no usable structure in 50 dimensions (ARI 0.068). Before any of this, I set a baseline to beat: the five lighting-only numbers.
- Training: ResNet18 with its early layers frozen and only the last block and the decision layer trained (8.4 M of 11.2 M weights). Learning rate and number of epochs were tuned on a split inside the training data, never on the test scans, and recall on that validation split ranged from 0.22 to 1.00 depending on the setting. I also varied the number of doctor labels (10, 20, 40, all) to see where weak labels help most.
- Metrics: missing a tumor is the costly error, so recall on the tumor class comes first, with F2 (recall weighted twice as much as precision) and AUC to compare models without depending on a threshold. With a 50/50 test set, accuracy would be misleading.
The code for this project is not published on GitHub.
Next steps
- Ask how the scans were collected, and for patient IDs, before writing any model code. The two leaks come from collection, not modeling.
- Build the leak checks into the pipeline from day one: a lighting-only baseline to beat and a score broken down by scan angle, so the warning comes with the first results instead of after them.
- Try a backbone pretrained on medical images rather than everyday photos.
- Find a way to remove the brightness leak (intensity standardization per scanner, or a set where both classes come from the same machines), then measure again.
- Repeat the cross validation with several random splits. With 24 test scans per split, the differences between methods are real but their size is uncertain.