Work / 03 / Trustworthy ML · medical imaging
MRITrust
How much of a brain-MRI classifier’s accuracy survives when the same patient can’t be on both sides of the split?
Audit the data for duplicates and shared patients before training, pin patient-grouped splits by checksum, and report every number at the unit it was measured — slice or patient — with cluster-bootstrap intervals.
-
0.983 → 0.927
ResNet-18 slice accuracy, random split vs patient-grouped split
Mean of 3 seeds on curated Figshare tumour slices (3-class tumour type). Same model, same data — only the split changed. source for “ResNet-18 slice accuracy, random split vs patient-grouped split” ↗
-
0.997 vs 0.688
accuracy on Kaggle test images that duplicate or near-duplicate training images vs images with no detected link
Kaggle Brain Tumor MRI official split, ResNet-18, 3 seeds; about 1,016 vs 199 images per seed (rounded means). source for “accuracy on Kaggle test images that duplicate or near-duplicate training images vs images with no detected link” ↗
-
87.7%
of a candidate external test set duplicated existing public data
5,208 of 5,941 BDNeuro-MRI images matched Figshare or Kaggle; the external-validation claim was withdrawn under the protocol fixed before download. source for “of a candidate external test set duplicated existing public data” ↗
- Status
- Research prototype
- Period
- Nov 2026 – present
- Context
- Independent open-source project
- Stack
- Python · PyTorch · scikit-learn · FastAPI
- Code
- Repository ↗
Public brain-MRI classifiers often report 97–99% accuracy. MRITrust asks how much of that survives when duplicated images and shared patients are removed from the evaluation. It builds the audit, the grouped splits, the training matrix and the statistics needed to answer that. The leakage itself is a known problem in these datasets; this project reproduces and measures it independently. Its own contribution is finding that a candidate external test set was mostly copies of the data it was meant to be independent from.
In one paragraph
Not a medical device. The models classify the tumour type (glioma, meningioma, pituitary) of curated 2-D slices already known to contain a tumour. They cannot tell anyone whether they have one.
The problem
A brain-MRI dataset usually holds several slices per patient. If slices are split at random, the test set ends up with slices from patients the model has already seen in training: same anatomy, same scanner, same tumour, sometimes the same image. The model can score well by recognising the patient instead of learning the tumour type. The score answers a different question from the one being asked.
Train
- Patient A, slice 3
- Patient A, slice 4
- Patient A, slice 5
- Patient B, slice 1
- Patient B, slice 2
- Patient B, slice 3
- Patient B, slice 4
- Patient C, slice 1
- Patient C, slice 2
- Patient C, slice 4
- Patient C, slice 5
- Patient C, slice 6
- Patient D, slice 1
- Patient D, slice 2
- Patient D, slice 3
- Patient E, slice 1
- Patient E, slice 2
- Patient E, slice 3
- Patient E, slice 4
- Patient E, slice 5
- Patient F, slice 3
- Patient F, slice 4
- Patient G, slice 1
- Patient G, slice 3
- Patient G, slice 4
- Patient H, slice 1
- Patient H, slice 2
- Patient H, slice 3
- Patient H, slice 4
- Patient H, slice 5
- Patient I, slice 1
- Patient I, slice 3
- Patient J, slice 1
- Patient J, slice 2
- Patient J, slice 5
- Patient J, slice 6
- Patient K, slice 1
- Patient K, slice 2
- Patient K, slice 3
- Patient K, slice 4
- Patient L, slice 1
- Patient L, slice 2
- Patient L, slice 3
Test
- Patient A, slice 1 , patient also in training
- Patient A, slice 2 , patient also in training
- Patient C, slice 3 , patient also in training
- Patient F, slice 1 , patient also in training
- Patient F, slice 2 , patient also in training
- Patient G, slice 2 , patient also in training
- Patient I, slice 2 , patient also in training
- Patient J, slice 3 , patient also in training
- Patient J, slice 4 , patient also in training
- Patient L, slice 4 , patient also in training
- Patient L, slice 5 , patient also in training
11 of 11 test slices come from patients the model has already seen in training.
Grouping by patient instead puts every slice of a patient on one side: 0 of 11 test slices are then from seen patients.
Each square is one MRI slice; the letter is its patient. marks a test slice whose patient also appears in training.
Fig. 1 An illustration of the leak: the same 54 slices from 12 synthetic patients, split two ways.
The pipeline
Each stage is a command. Each one writes a file the next stage checks, so a result can’t silently come from a different split or dataset than the one reported.
-
mritrust audit
Find duplicates and shared patients
SHA-256 and pixel MD5 for exact copies; perceptual hash plus normalised cross-correlation, best of 8 flips and rotations, for near-duplicates. Matches are linked into groups.
data/audit.py -
mritrust split
Split by group, pin by checksum
StratifiedGroupKFold keeps every patient or duplicate group on one side. The split files are committed with SHA-256 sums.
data/split.py -
mritrust train
Train 4 CNNs × 3 seeds
Training refuses a split whose checksum differs from the committed one. The checkpoint is chosen on validation macro-F1, and the test set is evaluated exactly once.
models/train.py -
mritrust report
Score at the right unit
Slice-level and patient-level metrics, with confidence intervals from a bootstrap that resamples patients (or leak groups), not slices.
evaluation/metrics.py -
mritrust gradcam · sanity
Check the explanations
Grad-CAM maps are compared with expert tumour masks and against a centre-of-image prior, and checked with label-randomisation sanity tests.
evaluation/gradcam_eval.py -
mritrust bdx
Try an external dataset
A protocol fixed before download: audit BDNeuro-MRI against the training sources first, evaluate only if it is independent.
Withdrawn — 87.7% duplicates
docs/EXTERNAL_BDNEURO.md
Fig. 2 The audit-first pipeline, from download to explanation.
Source src/mritrust/cli.py
Results
| Condition | Accuracy |
|---|---|
| Random slice split F-R · ± 0.006 SD | 0.983 [0.977, 0.989] |
| Patient-grouped split F-P · ± 0.031 SD | 0.927 [0.896, 0.958] |
Fig. 3 The same model on the same data, split two ways (slice-level accuracy, mean ± SD over 3 seeds).
Figshare brain-tumour dataset (3,064 T1-CE slices, 233 patients), 3-class tumour type. Mean ± SD over 3 seeds. F-R splits slices at random; F-P keeps every patient on one side (StratifiedGroupKFold on patient id). Test sets: 613 slices from 195–196 patients (F-R, patients also appear in training) and 613–614 slices from 46–47 patients (F-P), per seed.
Source reports/results/RESULTS.md
The drop is 5.6 points. Slices from one patient are correlated, so the fairer summary scores each patient once. Averaged over each patient’s slices, the patient-grouped model reaches 0.943 ± 0.026 on 46–47 test patients per seed. That is still below the random split, and it is measured on far fewer independent units than the 614 slices suggest.
Unit of analysis
Seed 0, patient level: 0.913 with a 95% patient-bootstrap interval of [0.826, 0.978] over 46 patients. That interval is wide, and the limitations section says so.
The popular Kaggle version of the dataset shows the effect more sharply. Its official test set contains copies of training images. Scoring the official split separately by what the audit found splits one headline number into three very different ones:
| Condition | Accuracy |
|---|---|
| Duplicate or near-duplicate of a training image n = 1,016 | 0.997 |
| Same patient, not a duplicate n = 386 | 0.977 |
| No detected link to training n = 199 | 0.688 |
Fig. 4 Kaggle’s official split: accuracy by how each test image is linked to the training set.
Kaggle Brain Tumor MRI v2, its official train/test split, 1,600 test images, linkage found by the leakage audit. n is the mean group size per seed, rounded (so groups can sum to 1,601).
Source reports/results/RESULTS.md
The external test that wasn’t. The plan was to test on BDNeuro-MRI, a separately published dataset, under a protocol fixed before downloading it: audit first, evaluate only if independent. The audit found that 5,208 of its 5,941 images (87.7%) duplicate Kaggle or Figshare images, 3,322 of them pixel-identical. The claim of external validation was withdrawn. The remaining images were analysed once, descriptively, and reported as such, not as evidence of cross-site performance.
Corrected
Recorded as a protocol deviation in docs/EXPERIMENTS.md. Every model also named a tumour type for all 101 unmatched no-tumour images, as it must with no “no tumour” class.
Which model is best? This test set can’t say
| Condition | Accuracy 95% CI |
|---|---|
| ResNet-18 (fine-tuned) | 0.953 [0.906, 0.986] |
| EfficientNet-B0 (fine-tuned) | 0.951 [0.900, 0.984] |
| ResNet-18 (frozen) | 0.878 [0.822, 0.924] |
| Small CNN | 0.757 [0.665, 0.839] |
Fig. 5 Four model configurations on the patient-grouped split, with 95% patient-bootstrap intervals (seed 0).
Seed 0, F-P split, slice accuracy with 95% cluster-bootstrap CI over 46 test patients. The top two differ by 0.002, far inside either interval; telling them apart would need a paired comparison on the same patients.
Source reports/results/RESULTS.md
Do the explanations point at the tumour?
Mostly not. Expert masks cover about 1.7% of each image. In the pointing game, a Grad-CAM map scores a hit when its peak falls inside the mask. The best model hits 45% of the time, and the fine-tuned ResNet-18 barely beats a fixed guess at the centre of the image.
| Condition | Hit rate |
|---|---|
| EfficientNet-B0 | 0.451 |
| ResNet-18 (fine-tuned) | 0.301 |
| ResNet-18 (frozen) | 0.231 |
| Small CNN | 0.049 |
Centre-of-image prior (no model): 0.252
Fig. 6 Pointing game: share of test images whose Grad-CAM peak lands inside the expert tumour mask.
Seed 0, F-P test set (n = 614). Expert tumour masks cover ~1.7% of the image. Pointing game = share of images whose Grad-CAM peak falls inside the mask.
Source reports/results/RESULTS.md
Where it stops
- One primary dataset. All patient-grouped results come from one Figshare collection: 233 patients, two hospitals, one MRI sequence. Nothing here says how a model would do elsewhere.
- Small test sets. 46–47 patients per seed in the patient-grouped split. Differences of one or two points between models are smaller than the uncertainty of each estimate, as Fig. 5 shows; separating them would need a paired comparison.
- The test sets have been used. Any future model choice needs a fresh test set that this dataset can no longer provide.
- Partial patient grouping on Kaggle. Only about two-thirds of Kaggle images inherit a patient ID, so its regrouped split is only partly patient-grouped.
- Coarse explanations. Grad-CAM on these networks is a 7 × 7 map upsampled to the image. It is not evidence of clinical reasoning.
A reliability layer is being built on top of the published results: calibration with temperature scaling, abstention below a confidence threshold, and out-of-distribution detection. It is not yet in the public repository, so this page doesn’t quote its numbers.
In progress
This page will be updated when that work is published.
Read the implementation
- audit.candidate_pairs Near-duplicate candidates: pHash + NCC over 8 transforms
- split.verify_split_file Training refuses a split that differs from the committed checksums
- metrics.cluster_bootstrap Bootstrap that resamples patients, not slices
- test_saved_splits_have_no_cross_partition_leakage Saved splits have no cross-partition leakage
Evidence
Every number on this page comes from one of these files, pinned to the commit it was read from.