Skip to content
All projects
CAP 5516 Medical Image Computing2025

Teaching a foundation model to see nuclei

The Segment Anything Model knows what an object is but has never seen a cell nucleus. Adapting it with low rank updates trains one percent of its weights and gets most of the way there.

SAMLoRAHistopathologyPUMAPyTorch

0.8233

Dice

0.6197

AJI

instance separation

0.5724

Panoptic Quality

1.04%

Trainable weights

6.69M of 643.7M

The question

SAM is trained on 11 million natural images and generalises remarkably well, but H&E stained tissue does not look like anything in that distribution. Nuclei are small, densely packed, and touch each other, which is exactly the case where a promptable segmenter tends to merge instances. Fully fine tuning 643 million parameters on a few hundred histopathology tiles would overfit immediately.

Approach

I froze the entire backbone and injected low rank adapters into the attention projections, so gradients only ever reach 6.69 million parameters, just over one percent of the model. Training ran with five fold cross validation on the PUMA melanoma dataset, scored with Dice, Aggregated Jaccard Index and Panoptic Quality, since Dice alone leaves open whether two touching nuclei were separated or merged into one region.

An H&E stained tile with its ground truth instance mask. Nuclei are small, densely packed and frequently touching, which is exactly the regime where a promptable segmenter merges neighbours.
Input tile, ground truth instances and prediction on a held out fold.

Outcome

Average Dice 0.8233, AJI 0.6197 and Panoptic Quality 0.5724 across folds, with the strongest fold reaching 0.8536 Dice and 0.6808 AJI. The gap between the Dice and the AJI is the interesting part: the model finds nuclei reliably and separates adjacent ones less reliably.

What it taught me

Instance level metrics tell a different story from pixel level ones, and the pixel level number on its own leaves out the distinction that matters clinically. It also made adaptation feel much less mysterious: most of what a foundation model needs in a new domain is a small correction, not a retraining.

More output

Dice across folds and epochs.
Aggregated Jaccard Index, which penalises merged instances.
Panoptic Quality across folds.