Skip to main content

MindGlide

Brain MRI segmentation for multiple sclerosis — any modality, any quality.

Built with PyTorch + MONAI, trained on >23 000 scans. Nature Communications (2025)

CI License: MIT Python ≥3.9 DOI Model on HF

MindGlide segmentation example

Get started

pip install git+https://github.com/MS-PINPOINT/mindGlide.git
mindglide -i scan.nii.gz -o scan_seg.nii.gz

That's it. Python ≥ 3.9; runs on GPU (seconds per scan) or CPU (a few minutes) — picked automatically. The trained model (~123 MB) downloads and caches on first run. Point -i at a folder to segment every NIfTI file in it:

mindglide -i scans/ -o segs/   # writes segs/<name>_seg.nii.gz for every scan

(python -m mindglide … works too.)

No scan at hand? Try the public MNI152 template:

curl -O https://templateflow.s3.amazonaws.com/tpl-MNI152NLin2009cAsym/tpl-MNI152NLin2009cAsym_res-01_T1w.nii.gz
mindglide -i tpl-MNI152NLin2009cAsym_res-01_T1w.nii.gz -o mni_seg.nii.gz

To get per-region volumes (mm³) as a CSV:

mindglide-volumes scan_seg.nii.gz --out-csv scan_volumes.csv

Options

Option Meaning
--device {auto,cpu,cuda,mps} Compute device (default: auto — a working GPU if present, else CPU).
--sw-batch-size N Sliding-window batch size (default 4). Lower it if the GPU runs out of memory.
--model-path FILE Use a local .pt checkpoint instead of the automatic download (offline use).
--resume Folder mode: skip scans already segmented in the output folder.
--no-klc Keep all connected components (skip largest-component cleanup).
--no-reorient Skip internal RAS re-orientation. Output always matches the input scan's grid.

Output labels

Code Structure Code Structure
0 Background 10 Optic_chiasm
1 CSF 11 Cerebellar_vermis
2 Ventricles_3_4_5 12 Corpus_callosum
3 DGM 13 White_matter
4 Pons 14 Frontal_lobe_GM
5 Brainstem 15 Limbic_cortex_GM
6 Cerebellum 16 Parietal_lobe_GM
7 Temporal_lobe 17 Occipital_lobe_GM
8 Temporal_horn_lateral_ventricle 18 Lesion
9 Lateral_ventricle 19 Ventral_diencephalon
Troubleshooting

"Warning: not using the GPU — … this PyTorch build cannot run on it" — the default pip PyTorch wheels no longer include kernels for older GPUs (e.g. Pascal cards: GTX 10xx, Quadro P series). MindGlide falls back to CPU automatically. To use such a GPU, install a compatible PyTorch first:

pip install "torch==2.6.0+cu118" --index-url https://download.pytorch.org/whl/cu118
pip install git+https://github.com/MS-PINPOINT/mindGlide.git

GPU out of memory — try --sw-batch-size 1, or --device cpu.

Apple Siliconauto uses MPS when available. If an operation is unsupported, run with --device cpu or set PYTORCH_ENABLE_MPS_FALLBACK=1.

Offline / air-gapped machines — download the checkpoint once and pass --model-path /path/to/model.pt (or set MODEL_PATH).

Model cache location — the auto-downloaded model lives in the Hugging Face cache (~/.cache/huggingface by default); set HF_HOME to move it.

Docker / Apptainer

Build once (model weights are baked in, so the container works offline):

git clone https://github.com/MS-PINPOINT/mindGlide.git
cd mindGlide
docker build -t mindglide .

Run (drop --gpus all on CPU-only hosts; --user makes the output files owned by you rather than the container user):

docker run --gpus all --ipc=host --user $(id -u):$(id -g) -v /data:/data \
  mindglide -i /data/scan.nii.gz -o /data/scan_seg.nii.gz

For Apptainer/Singularity on HPC:

apptainer build mindglide.sif docker-daemon://mindglide:latest
apptainer run --nv -B /data:/data mindglide.sif -i /data/scan.nii.gz -o /data/scan_seg.nii.gz
Model weights

The checkpoint (_20240404_conjurer_trained_dice_7733.pt) is downloaded automatically from Hugging Face: MS-PINPOINT/mindglide on first run. Additional and legacy checkpoints are archived in the same repository. Models were trained on the datasets described in the paper.

From a source checkout you can also fetch the weights as a git submodule (requires Git LFS):

git submodule update --init --recursive
git submodule foreach 'git lfs pull'
Development & tests
git clone https://github.com/MS-PINPOINT/mindGlide.git
cd mindGlide
pip install -e ".[test]"

pytest                          # fast unit tests (seconds, no model download)
MINDGLIDE_RUN_SLOW=1 pytest -v  # + end-to-end on a public MNI scan (CPU, and GPU if present)

The original container-based training/fine-tuning pipeline was retired from the main branch and is preserved at the legacy-container tag.

Citation

If you use MindGlide, please cite:

Goebl P, Wingrove J, Abdelmannan O, et al. Enabling new insights from old scans by repurposing clinical MRI archives for multiple sclerosis research. Nature Communications. 2025;16(1):3149. doi:10.1038/s41467-025-58274-8

BibTeX
@article{Goebl2025,
    author = {Goebl, Philipp and Wingrove, Jed and Abdelmannan, Omar and {Brito Vega}, Barbara and Stutters, Jonathan and Ramos, {Silvia Da Graca} and Kenway, Owain and Rossor, Thomas and Wassmer, Evangeline and Arnold, Douglas L. and Collins, Louis and Hemingway, Cheryl and Narayanan, Sridar and Chataway, Jeremy and Chard, Declan and Iglesias, {Juan Eugenio} and Barkhof, Frederik and Parker, Geoffrey J. M. and Oxtoby, Neil P. and Hacohen, Yael and Thompson, Alan and Alexander, Daniel C. and Ciccarelli, Olga and Eshaghi, Arman},
    title = {Enabling new insights from old scans by repurposing clinical {MRI} archives for multiple sclerosis research},
    journal = {Nature Communications},
    volume = {16},
    number = {1},
    pages = {3149},
    year = {2025},
    month = apr,
    doi = {10.1038/s41467-025-58274-8},
    pmid = {40195318},
    pmcid = {PMC11976987}
}

Acknowledgements

This study/project is funded by the UK National Institute for Health and Social Care (NIHR) Advanced Fellowship to Arman Eshaghi (Award ID: NIHR302495). The views expressed are those of the author(s) and not necessarily those of the NIHR or the Department of Health and Social Care.

NIHR logo

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mindglide-1.2.0.tar.gz (27.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mindglide-1.2.0-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file mindglide-1.2.0.tar.gz.

File metadata

  • Download URL: mindglide-1.2.0.tar.gz
  • Upload date:
  • Size: 27.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mindglide-1.2.0.tar.gz
Algorithm Hash digest
SHA256 8a27ab24d412b34319b586e83a93da4798caf2ab5b4c67ac0376b1d2c982bc02
MD5 c9246063891b154ee0194ff40c9a32e6
BLAKE2b-256 5c928e3c1d08871227a07bc2c9480a6294a7c668095aa5748f569f0e5b130685

See more details on using hashes here.

Provenance

The following attestation bundles were made for mindglide-1.2.0.tar.gz:

Publisher: publish.yml on MS-PINPOINT/mindGlide

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mindglide-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: mindglide-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mindglide-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 19cdb8d67b810423e6fcf6e1db8c5d80ef4fda58d1cd86781dd928cb26382f7b
MD5 d6d1ead1221b723c057715a173ee62bb
BLAKE2b-256 6f057cbf683070dc932497c56244d88c01deb626920bd042b88d536ed96f0b19

See more details on using hashes here.

Provenance

The following attestation bundles were made for mindglide-1.2.0-py3-none-any.whl:

Publisher: publish.yml on MS-PINPOINT/mindGlide

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page