Training-Free Medical Image Segmentation vs Trained Networks

A multi-domain data-efficiency study — frozen-foundation-model assembly (an LLM polygon drawer in the deployed path on 1/6 domains, else SAM / op_sam / SegGPT) + a numpy genome, zero gradient training on the target task.

6 modalitiesmeasured, from scratch GT-free at inferenceLLM-agnostic skills updated · 2026-07-07

Data-efficiency

The crossover — one panel per domain

Dice vs. label budget: training-free LLM vs. the strongest baseline = max(trained nets, few-shot SAM-HQ ft) per budget, from the same combined grid as the detailed CI figure below (so they agree). Error bars: LLM = test-set bootstrap 95% CI (deterministic run); baseline = 3-seed 95% t-CI (hollow □ = † fewer than 3 seeds, no CI drawn).

▬ LLM training-free · □/▪ strongest baseline (nets ∪ SAM-HQ ft) · large dot = N=100 · = baseline below the panel floor

ISIC 2018 · dermoscopyLLM leads all N
0.80.850.90.951.051025501000.8800.854
Kvasir · endoscopy polypLLM leads all N
0.60.70.80.91.051025501000.8650.864
MSD Spleen · CTLLM ends ahead
0.60.70.80.91.051025501000.9200.912
MSD Prostate · MRIbase ends ahead
0.60.70.80.91.051025501000.8010.846
Chest X-ray · lungLLM leads all N
0.80.850.90.951.051025501000.9500.945
HC18 FetalHead · ultrasoundunder revision
withheldsubject-level HC18 leak found & being fixedclean-split numbers pending re-eval

The trained-NN grid is now fully locked (30/30 3-seed, incl. the CXR N=100 nnU-Net). The SAM-HQ ft baseline now uses the LLM-generated box at inference (fair localization), not the deployed pipeline box — with a fair box, few-shot SAM-HQ collapses on localization-hard domains (Kvasir ~0.3, Spleen ~0.25), so the strongest baseline reverts to the trained nets there and the LLM leads Kvasir at low N. Fair SAM-HQ is the strongest baseline only at ISIC N=5 (hollow □ = no seed-level CI available). FetalHead is withheld — temporarily removed pending a subject-disjoint re-split + clean re-eval (HC18 same-pregnancy planes were split across train/test); its old numbers are not shown. Numbers are the refreshed grid; the deployed Results table above is unchanged.

Detailed data-efficiency figure — 5 settled domains, LLM vs strongest baseline (locked nets ∪ few-shot SAM-HQ ft), both curves with 95% CIs (FetalHead withheld)
Matched data-efficiency: training-free LLM pipeline (flat, measured) vs best trained NN across N
Five settled domains, five budgets (FetalHead withheld — leak fix, see below). Each panel: the training-free LLM (teal) vs the strongest baseline = max(locked trained nets, few-shot SAM-HQ ft) (blue dashed). The trained-NN grid is now fully locked (30/30 3-seed), including the CXR N=100 nnU-Net. Both curves carry 95% CIs — LLM = test-set bootstrap (deterministic run); baseline = 3-seed 95% t-CI (hollow □ = fewer than 3 seeds, no CI). Green shading marks where the LLM leads. The SAM-HQ ft baseline uses the LLM-generated box at inference (fair localization), not the deployed pipeline box; with a fair box, few-shot SAM-HQ collapses on localization-hard domains (Kvasir ~0.3, Spleen ~0.25), so the strongest baseline reverts to the trained nets there and the LLM leads Kvasir at low N. Fair SAM-HQ is the strongest baseline only at ISIC N=5 (hollow □, no seed-level CI). The deployed Results table above is unchanged.

Results — best trained NN across N vs the frozen-assembly pipeline

Strongest trained NN per cell — max of SegFormer (mit_b2), pretrained U-Net (resnet34), and nnU-Net, 2-seed means — at matched budgets N = 10 / 25 / 50 / 100, against the LLM pipeline (re-measured from scratch via eval_all_domains.py). The LLM's only label-fit module is a ~5–8-param genome; localization and SAM are GT-free/frozen — so the LLM number is ~flat in N while the NN climbs. Caveat: the N=100 column is a set of within-noise near-ties — best-NN@100 sits inside the LLM bootstrap 95% CI on 5/6 domains (stats.md), and 0/4 apparent N=100 leads survive as significant. The honest, CI-separated lead is at N≤25. Amber = within-CI near-tie; a green cell reflects the point estimate only, not significance.

Domainbest NN N=10N=25N=50N=100training-free LLMfew-shot decoder
N=100 (oracle)
ISIC 2018 (derm)0.8150.8290.8320.8680.8800.911
MSD Spleen (CT)0.6330.8020.8590.9070.9200.953
Kvasir-SEG (endo)0.7560.8240.8330.8890.86460.944
ChestXray (X-ray)0.9380.9480.9520.95460.9497
SegGPT in-context; fs-deploy 0.9488
0.9535
HC18 Fetal-Head (US)— under revision (HC18 subject-level leak; withheld)
MSD Prostate (MRI) ·new0.6790.7200.7720.8150.7877
SegGPT⊕op_sam ensemble; was 0.760
0.938
Two LLM columns: the training-free pipeline (zero gradient training — the study's headline) and the few-shot tuned decoder (generic-SAM init, encoder frozen, ~4M-param mask decoder tuned on N=100 labels, GT-box oracle). The few-shot decoder beats the from-scratch NN on four of six domains given a good box (ISIC/Spleen/Kvasir/Prostate) and ties the other two (CXR — near-ceiling NN at ~0.95; HC18 withheld) — the residual between it and the deployed training-free pipeline is mostly localization (the exception was CXR, where the frozen SAM decoder was the wall — now moved training-free by swapping in a different frozen decoder, the SegGPT in-context drawer, to 0.9497), detailed below.
CXR is now training-free again at 0.9497 — a swapped 4th frozen drawer backend (SegGPT in-context). The old CXR training-free headline (0.922, frozen box-SAM) is superseded by a different frozen decoder: SegGPT (BAAI/seggpt-vit-large, generic → leak-free, non-SAM) paints the whole lung mask in-context from K=8 spread-sampled train (image,mask) support pairs — no box, no SAM, no localizer, ZERO gradient training. Deployed 0.9497 (median 0.9616, n=107), within 0.005 of the from-scratch NN's 0.9546 — a near-tie, still not a win. This is the 4th backend at the model-coupled drawer seam (LLM polygon · frozen SAM · few-shot tuned decoder · in-context SegGPT): the seam is genuinely swappable, and CXR's gap was neither architectural nor requiring our labels — it was the particular frozen decoder (SAM). A separate, non-training-free few-shot lane remains documented: tuning only the ~4M-param SAM mask decoder on N=100 CXR labels (generic-vit_l init, encoders frozen, box-jittered, leak-free) + mask-bbox re-decode reaches 0.9488 (median 0.9608, 102/107 improve) — but the deployed CXR is now the training-free SegGPT 0.9497, which supersedes it. Frozen-decoder study (leak-free generic): among frozen alternatives the generic in-context SegGPT wins; SAM2 / SAM1-vit_h merely tie frozen SAM-HQ (no gain), and text-prompted CLIPSeg fails on grayscale X-ray (0.00) — the interesting frozen alternative is a generic in-context segmenter (few-shot at inference, zero gradient), not another SAM variant.
The pipeline wins the EXTREME scarce-label regime (N≤25) where the target is GT-free-localizable — ISIC and Spleen are CI-separated leads at N≤25 (fewshot_matched.md); at N=100 the numbers below (ISIC 0.880 vs 0.868, Spleen 0.920 vs 0.907) are within-CI near-ties, not significant leads (stats.md) — and on Kvasir polyp a frozen-DINOv2 dense-correspondence localizer (OP-SAM CPG + peak-CC box) lifts it 0.659→0.8646 — the gap was localization (frozen GT-box oracle 0.914 > NN), and this closes 89% of it; the median 0.9484 now beats the NN mean, though the mean stays just below best-NN 0.889. On Chest X-ray the deployed training-free path is now a swapped 4th frozen drawer — the SegGPT in-context drawer (K=8 support pairs, zero gradient) — reaching 0.9497 ≈ NN 0.9546 (−0.005, a near-tie), superseding the earlier box-SAM 0.922 and the separate few-shot-tuned decoder 0.9488 lane; the old "frozen-decoder cap ~0.93" was specific to SAM, not to architecture. HC18 fetal-head is withheld — under revision pending a subject-disjoint re-split (HC18 subject-level leak); its numbers are not shown as valid results. Honest headline: at N=100 these are within-CI near-ties — 0/4 apparent leads survive bootstrap 95% CIs (stats.md), and the Spleen "+0.019" is a seed-averaging artifact (best single U-Net seed 0.9323 > LLM 0.9262). The defensible lead is at N≤25 on localizable targets (ISIC / Kvasir / Spleen / Prostate), budget-matched and CI-separated. All 6 deployed paths are gradient-free frozen-model assembly, but the LLM drawer is out of the mask-producing path on 5/6 (llm_ablation.md) — Prostate, the last domain lifted off its floor, is a complementary 2nd frozen drawer (a SegGPT⊕op_sam edge-gated keep-best ensemble). SegFormer is the strongest NN in 10 of 12 sweep cells.

Segmentation galleries

Per-case GT-vs-prediction overlays for the deployed pipeline on every test image (all 465, sorted worst-Dice first) — open the 6-domain gallery hub → (ISIC · Kvasir · Spleen · Prostate · CXR · FetalHead). Green = ground truth, red = deployed prediction; overlays rendered from the committed mask_cache/.

Where is the wall — the decoder, or localization? A fair few-shot probe

Is the residual to the trained NN a decoder limit or a localization limit? MedSAM (SAM fine-tuned on ~1M medical masks) beats box-prompted SAM — but it is data-leaky (its training set likely includes these test distributions), so it is really "import a trained medical net." The fair, leak-free counterpart of the same operation: init from the generic SAM (no medical data), freeze the image + prompt encoders, and fine-tune only the ~4M-param mask decoder on our own N-label train split — GT never touches test. Given a good box (the GT-box oracle, which isolates the decoder), this few-shot-tuned decoder beats the from-scratch NN at every budget on 4 of 6 domains (ISIC/Spleen/Kvasir/Prostate — Prostate by +0.12) and ties on the other two (CXR — near-ceiling NN at ~0.95; HC18 withheld), and it saturates at N=10 (pretrained features + a tiny adapted head), so its curve is flat-high while the NN climbs:

Domain (tuned decoder, oracle)N=10N=25N=50N=100best NN N=100
ISIC 2018 (derm)0.9050.9040.9070.9110.868
MSD Spleen (CT)0.9570.9600.9600.9530.907
Kvasir-SEG (endo)0.9360.9340.9370.9440.889
ChestXray (X-ray)0.9330.9460.9550.95350.9546
HC18 Fetal-Head (US)— under revision (HC18 subject-level leak; withheld)
MSD Prostate (MRI) ·new0.9060.9310.9320.9380.815
Mostly localization — with CXR the telling exception. The oracle hands the decoder a good box; on most domains the gap between it and the deployed pipeline is localization. Kvasir is the proof: tuned-decoder oracle 0.944 vs the original deployed 0.659 — 0.285 of pure localization headroom, zero decoder; the frozen dense-correspondence localizer has since realized most of it (0.659→0.8646), exactly as this predicted, leaving only ~0.05 to the oracle box. Where localization is already solved, the tuned decoder is a clean deployable win over both production and the NN: CXR few-shot decoder 0.9488 > the earlier box-SAM production 0.922 ≈ NN 0.9546 (though the deployed training-free CXR is now the SegGPT in-context drawer 0.9497, which supersedes both); Spleen (3D volume-prior box) 0.942 > production 0.920 > NN 0.907. This is few-shot (N=100 labels = the NN's budget), not training-free — an explicit, leak-free counterpart to MedSAM. CXR is the exception that sharpens the rule: its wall was the particular frozen decoder (SAM), not localization and not architecture — swapping in a different frozen decoder, the SegGPT in-context drawer, moves it training-free to 0.9497 (≈ NN, zero gradient), and a few-shot-tuned SAM decoder independently reaches 0.9488. So of the residual "structural / architectural ceilings," the polyp boundary was a localization gap in disguise, while the CXR "decoder wall" was a SAM-specific wall breachable by another frozen decoder with none of our labels.

Is the medical pretraining (MedSAM) worth it? — a leaky benchmark

MedSAM is SAM already fine-tuned on ~1M medical masks — a leaky upper reference (its training likely saw these test distributions). Arch-matched (both vit_b, GT-box oracle, N=100), few-shot tuning of the GENERIC SAM matches or beats the leaky MedSAM on 3 of 6 domains, and stays within 0.015 on the other 3 — its own pretraining distributions (derm/US/MRI). Medical pretraining buys no consistent edge once the decoder is adapted, and where generic SAM is already strong (Kvasir/Spleen) it starts above MedSAM even frozen. Bold = better of the two few-shot columns.

Domain (N=100 oracle, vit_b)from-scratch NNgeneric frozengeneric few-shot (fair)MedSAM frozen (leaky)MedSAM few-shot (leaky)
ISIC 2018 (derm)0.8680.8700.9150.9210.943
MSD Spleen (CT)0.9070.9410.9560.9090.946
Kvasir-SEG (endo)0.8890.9170.9360.8880.918
ChestXray (X-ray)0.95460.9250.9540.9350.952
HC18 Fetal-Head (US)— under revision (HC18 subject-level leak; withheld)
MSD Prostate (MRI) ·new0.8150.8950.9280.8070.941
Fair few-shot generic SAM vs leaky MedSAM benchmark, N=100 oracle
Fair few-shot tuning of generic SAM (dark blue) vs the leaky MedSAM (orange), each frozen + few-shot-tuned, vs the from-scratch NN (gray) — arch-matched vit_b, N=100 GT-box oracle. The fair generic few-shot ≥ leaky MedSAM few-shot on Spleen/Kvasir/ChestXray (3/6); MedSAM leads on its own pretraining distributions — derm (ISIC), US (HC18), MRI (prostate) — but by <0.015 once the generic decoder is tuned, and generic-frozen still beats MedSAM-frozen on prostate (0.895 vs 0.807). Medical pretraining helps most exactly where MedSAM saw the data, yet few-shot tuning of the generic decoder nearly erases it — decoder adaptation, not medical pretraining, is the lever.
The MedSAM attack inverts once it is prompted fairly and tested OOD (ood_medsam.md). The oracle-box column above is a leaky upper reference. Give MedSAM a fair box (learned from N GT, not the oracle) and it drops +0.16..+0.59 Dice below the deployed pipeline in-distribution; take it out-of-distribution (DRIVE retinal vessels — a distribution MedSAM never trained on) and the gap widens to +0.51 while MedSAM collapses to 0.220 even handed the ORACLE box (vs ~0.90 in-distribution). MedSAM's in-distribution edge was its decoder recognizing box-shaped targets it had trained on — memorization that does not transfer; the pipeline's few-shot-refit GT-free localization is distribution-robust.

Can it be ONE domain-agnostic pipeline? — few-shot skills + a router, SAM frozen

Each domain has a distinct setup — so can it be a single domain-agnostic pipeline that few-shot-fits per domain WITHOUT tuning SAM? We test the transferable skill — a frozen-SAM-feature localizer prototype fit from N labeled images — with identical code across all six domains, SAM never touched.

Domain-agnostic few-shot skill transfer: skills few-shot-fit, topology is routed not tuned
(A) One fixed pipeline (prototype-sim localizer): the skill few-shot-fits — saturates by ~N=10 on every domain — and scores high where the target is prototype-localizable (ISIC 0.71, CXR 0.62; HC18 withheld), mid where it is a central structure (Prostate MRI 0.51), low where it needs a specialized localizer (Kvasir 0.35, Spleen 0.12). (B) Routing the per-domain topology (genome / static-box / op_sam dense-correspondence / volume-prior / ellipse-snap / volume-trajectory) + the few-shot skill recovers most of the deployed number (Kvasir 0.35→0.77→0.86, Prostate 0.51→0.76, Spleen 0.14→0.66→0.83@N=50).
Yes — a domain-agnostic pipeline = frozen SAM + a GT-free router + few-shot skills. The learning (localizer prototype + gate weights + genome) is domain-agnostic, few-shot (~10 labels; ~50 for the isodense spleen), and SAM-frozen — it transfers with identical code. The per-domain "distinct setup" you'd notice is which localizer topology to route to — a GT-free routing choice (learned config, the project's route.py), not SAM tuning. So onboarding a new domain is ~10 labels + a routing decision, zero gradient training. Robust localizer skill: the deployed default is now the op_sam frozen-DINOv2 dense-correspondence localizer (kvasir/HC18/prostate) — it transfers 10-shot support masks through the full patch cross-correlation, and superseded the earlier SAM+DINOv2 AMG-ranker ensemble on Kvasir (0.655→0.8646). The lesson holds and is now stronger: the polyp/fold and faint-skull walls yield to the right frozen feature space — dense correspondence, plus feature-diverse supports — not to distractor-verification tricks. The AMG-ranker ensemble (at/near the best single feature space on all three, Kvasir 0.65 / Spleen 0.64 / ISIC 0.67, never catastrophic where SAM-alone fails the isodense spleen 0.40) remains the LLM-agnostic fallback where a support set is too small for correspondence.

GPU-free lane — per-stage skill loop — research (default-off)

A separate lane from the deployed comparison above. This is the training-free / GPU-free pipeline — an LLM polygon draw + numpy-only skills, no SAM, no SegGPT, no gradient training. Each domain runs a per-stage loop: research → literature-grounded preprocessing → a numpy skill → a per-stage GT-free feedback gate. It is default-off research; the deployed pipeline and every Results-table / data-efficiency number above is untouched. Visual before→after recoveries: per-stage gallery →.
DomainGPU-free base → per-stageΔ (best N)with-NN lanedriver stageGT-free gatesource
CXR0.664 → 0.854+0.190 (deg +0.35)nullLOCALIZE (lung atlas+CLAHE)valid ρ+0.58PR #78
MSD Spleen0.555 → 0.60+0.019..+0.043 (deg +0.247)nullLOCALIZE (LUQ prior)valid ρ+0.64PR #77
HC18 FetalHead— under revision (HC18 subject-level leak; withheld)
MSD Prostate0.619 → 0.652+0.033 @N=5nullREPAIR (isodense boundary)valid via preprocessingPR #76
ISIC 2018trace 0.714 → 0.923+0.005 [CI≠0 @N=10/25/100]nullREPAIR (color-constancy cc_band)valid ρ+0.6PR #80
Kvasir0.347 → 0.38headroom +0.087..+0.108, NULLnullLOCALIZE (gate wall)INVALID |ρ|<0.12PR #79
Scorecard: 5/6 wins + 1 gate-wall null. The per-stage LOCALIZE agent wins on CXR (+0.190), Spleen (+0.043) and FetalHead (withheld — under revision, HC18 subject-level leak); the REPAIR agent wins on Prostate (+0.033) and ISIC (+0.005, CI excludes 0 @N=10/25/100, beats best-NN @N≤50; trace ISIC_0012292 0.714→0.923). Kvasir is the honest null: real oracle headroom (+0.087..+0.108) but a gate wall (every GT-free signal |ρ|<0.12) — nothing harvests it. The with-NN lane is null on all 6 (a predicted asymmetry: the deployed NN drawer already solves the stage the GPU-free lane repairs), so the NN drawer's value scales with how broken GPU-free localization is — huge on Kvasir/Spleen, ~0 on ISIC/FetalHead at N=5.
Takeaway. Where the GPU-free failure is location and a valid GT-free anatomical cue exists (CXR atlas, spleen LUQ, FetalHead ring), the per-stage LOCALIZE agent lifts the training-free lane substantially; it is an honest null where the cue is ungateable (Kvasir gate wall) or the deployed pipeline already solved location (all with-NN lanes). Honest sub-result (ISIC): a FRONT CLAHE / illumination-equalization enhancer was a negative (−0.018..−0.030, it washes out the pigment cue) and shipped gated OFFcontrast-equalization preprocessing HURTS hand-crafted-cue pipelines, the opposite of what it does for trained nets. CI completing — ISIC/Kvasir per-stage agents still finishing.