Back to portfolioModel weights

RESEARCH CASE STUDY

Microglomeruli Segmentation

Fine-tuning a foundation model to count synaptic boutons in a fly brain, and proving it against the state of the art

M.SC. THESIS · RWTH AACHEN · 3D INSTANCE SEGMENTATION · MICROSAM / NNU-NET V2 / SWINUNETR

A reproducible deep-learning pipeline that fine-tunes a foundation model for 3D instance segmentation of synaptic boutons in confocal Z-stacks of the Drosophila mushroom body calyx, then benchmarks it head-to-head against three SOTA 3D architectures — nnU-Net v2, Cellpose, SwinUNETR — under a physically-calibrated, instance-matching evaluation protocol.

Supervised by Prof. Dr. Abigail Morrison (Software Engineering Group, RWTH Aachen), with Prof. Dr.-Ing. Johannes Stegmaier as second examiner. Built for the Tavosanis lab, who count these structures by hand today.

01

What it looks like

Raw confocal microscopy volume of the Drosophila mushroom body calyx, rotating in 3D. Boutons appear as faint overlapping blobs against background signal.
Raw input
What the microscope gives you.
Hand-annotated ground-truth instance labels for the same volume, each bouton rendered as a distinctly coloured 3D object.
Ground truth
Hand-annotated in napari, one label per bouton.
Predicted instance segmentation from the fine-tuned MicroSAM model on a held-out volume, closely matching the ground-truth labels.
Prediction
Fine-tuned MicroSAM (vit_l_lm), held-out volume.
One held-out volume, rotating. Left is what the microscope produces. Middle is what a human said the answer was. Right is what the fine-tuned model said, having never seen this volume. Each colour is one bouton instance.
02

Why this is hard

INSTANCES, NOT PIXELS
Boutons touch, and touching is the whole point

Microglomeruli sit packed against each other in the calyx. Semantic segmentation would happily paint one confluent blob across a dozen of them and score well on pixel overlap while being useless: the biological question is how many boutons there are and how big each one is. That makes this an instance problem, and it makes the interesting failure mode a merge, not a miss.

3D, AND ANISOTROPIC
A confocal Z-stack is not a cube of equal voxels

Z resolution is coarser than XY. A model that reasons in voxels rather than micrometres will systematically misjudge volume along one axis, so evaluation has to happen in physical units. Instance matching here accounts for voxel volume rather than counting voxels as if they were isotropic.

NO DATASET EXISTED
The annotations had to be made before the models could be trained

There is no public benchmark for this structure at this acquisition setting. The ground truth was hand-annotated from scratch in napari, which caps how much data there is and makes the choice of a foundation model with a strong prior a practical decision rather than a fashionable one.

THE END USER IS NOT AN ENGINEER
A checkpoint on a cluster helps nobody

The people who need these counts are biologists, not PyTorch users. If the deliverable had stopped at a weights file and a table of scores, the thesis would be complete and the work would be worthless. That is why BoutonViewer is part of this project rather than a follow-up to it.

03

The benchmark, and why each model is in it

Four architectures, one dataset, one evaluation protocol. The dataset is 13 volumetric stacks hand-annotated from scratch in napari across seven Drosophila brain preparations and two acquisition systems (confocal LSM and Airyscan), split nine train / two validation / two test. The point of including nnU-Net v2 and Cellpose 3D is not to have them lose. It is that a fine-tuned foundation model beating a self-configuring U-Net and the community default is a claim worth making, and beating nothing is not.

MicroSAM (vit_l_lm)Foundation model, fine-tunedselected

A microscopy-specialised SAM variant. Strong prior, so it can be fine-tuned on a small hand-annotated set. Trained here in 2D with Kornia augmentations and custom post-processing to assemble instances.

Cellpose 3DGeneralist cell segmentation

The default in the microscopy community, and the honest baseline to beat. If a general-purpose tool already solves this, the rest of the thesis is unnecessary.

nnU-Net v2Self-configuring U-Net

The standard against which medical and biological segmentation is measured, precisely because it removes architecture tuning as an excuse. Included so that a win is a real win.

SwinUNETRTransformer encoder, 3D (MONAI)

Tests whether native 3D attention beats a 2D foundation model with a strong prior, on a dataset this size. A genuinely open question at small n.

Each trained across four preprocessing variants

originalRaw

Unprocessed acquisition. The control.

dogDifference-of-Gaussians

Classical blob enhancement. Tests whether a hand-designed prior still buys anything once a foundation model is doing the work.

psfPSF-deconvolved

Richardson-Lucy against the measured point-spread function. Physically motivated, and expensive.

allCombined

All variants pooled into one training set.

Four architectures times four variants is a grid, not a single run, which is why training is launched through HTCondor submit files on the LFB cluster rather than by hand.

04

Results

Recall is the headline metric, not accuracy or Dice, and that is deliberate: a missed bouton is a permanent counting error, while a false positive can be filtered downstream. Evaluation prioritises recall, matched-instance mIoU, and a recall-weighted panoptic quality score. Test set: matched two-image test set · 33 ground-truth boutons.

Bouton instance-segmentation benchmark: recall, matched mIoU, recall-weighted panoptic quality and false-positive count across models.
ModelRecallMatched mIoURWPQFalse pos.
MicroSAM Largevit_l_lm · All-PSF1.0000.7870.78716
MicroSAM Basevit_b_lm · All-PSF1.0000.7710.7716
CellposeSAM2D XYZ · All-DoG0.9470.7680.7263
Swin UNETRAll-PSF0.9470.7320.6931
nnU-NetAll-PSF0.8950.6780.6092
Imarissemi-manual · current lab tool0.7350.5050.3715

The fine-tuned MicroSAM Large checkpoint recovered every bouton — perfect recall — and posted the highest matched-instance mIoU of any model evaluated, ahead of three SOTA 3D backbones and far ahead of the lab's current Imaris workflow. The Base variant matches that recall and gives up only 0.016 mIoU while cutting false positives from 16 to 6, which is why the card recommends it when GPU memory is tight.

The honest limitation, stated on the card: MicroSAM Large trades that perfect recall for a higher false-positive count (16 on the deconvolved condition), several of them large boutons split into multiple predicted components rather than spurious detections in empty regions. The card is explicit that predictions should be reviewed before unsupervised quantification — which is exactly why BoutonViewer surfaces oversized and merged predictions instead of silently filtering them. The model was fine-tuned on a comparatively small annotated set drawn from two brain specimens, so performance under substantially different imaging or labelling has not been verified.

RWPQ = recall-weighted panoptic quality (PQ_rec). Figures are the deconvolved All-PSF condition; the full evaluation set spans 61 ground-truth instances across the two held-out specimens.

Full model card

Evaluation is instance matching, not per-pixel overlap, and it weights by physical voxel volume so that anisotropic Z spacing does not quietly inflate or deflate a score. The code is in tools/evaluate_segmentation.py.

05

Two decisions worth defending

DECISION 1 · A 2D FOUNDATION MODEL FOR A 3D PROBLEM
Prior beats dimensionality when the dataset is hand-made

The obvious move on a 3D problem is a native 3D architecture, which is why SwinUNETR and nnU-Net v2 are in the benchmark. But every training example here was annotated by hand, which puts a hard ceiling on n. A model carrying a strong microscopy prior can be fine-tuned into that regime; a 3D transformer trained from a much weaker starting point has to learn more from less. Running both was the only honest way to find out which effect dominates, rather than asserting it.

DECISION 2 · TWO ACQUISITION PIPELINES, NOT ONE AVERAGE
LSM and Airyscan are different instruments and get different preprocessing

BoutonViewer runs rolling-ball background subtraction plus Richardson-Lucy deconvolution for confocal LSM stacks, and lightweight normalisation for Airyscan, which is already deconvolved by the microscope. Collapsing both into one path would have been less code and quietly wrong: you would be deconvolving already-deconvolved data. Voxel calibration is auto-derived from acquisition type and image size (LSM uses the confocal pitch 0.3 × 0.0709 × 0.0709 µm; a native super-resolution Airyscan image gets the finer 0.3 × 0.0425 × 0.0425 µm), and the stats are live-recomputed if a user overrides those fields, because the failure mode of getting this wrong is a plausible number in the wrong units rather than a crash. The Base variant on LSM also skips deconvolution entirely and takes the lighter path, so a GPU-limited run stays fast without a separate code branch.

06

Shipping it: BoutonViewer

A napari desktop application that runs the pipeline on a confocal or Airyscan TIFF stack, shows the raw channels and predicted labels in 3D, and reports per-bouton volume and surface area in µm³ and µm². A biologist loads a file and gets a table.

  • Interactive stats table: hover or click a bouton in the viewer to inspect it, or delete a false positive without touching the model
  • Prediction caching, so changing a display setting does not re-run inference
  • Oversized and merged predictions are deliberately not auto-removed. A silent filter would hide exactly the failure mode that matters, so the tool surfaces them and lets a human decide
  • Model and data notes shipped alongside the tool: what it was trained on, at which voxel sizes, and where it should not be trusted
Model & data notes
07

Reproducibility

The thesis claim is reproducibility, so the repo has to earn it. Training, inference and evaluation are separate scripts with a --dataset flag selecting the preprocessing variant, cluster jobs are committed as submit files rather than remembered, and the selected checkpoints are published on Hugging Face with the rejected experiment runs left out. Two environment definitions exist on purpose: the annotation machine runs napari tooling under mamba, the training machine runs pip, because micro_sam is not reliably installable from PyPI and pretending otherwise would break the first person who tried to reproduce this.