Repository for: "Explainable AI Methods for Neuroimaging: Systematic Failures of Common Tools, the Need for Domain-Specific Validation, and a Proposal for Safe Application"
Read our preprint here: arXiv:2508.02560
This project was computationally very demanding. Many steps required multiple days of runtime on an HPC cluster with a high degree of parallelization. This made building an automated end-to-end pipeline impractical.
Instead, the repository consists of a set of scripts and notebooks that must be run in the correct order to reproduce the results. The pipeline is divided into numbered segments, described below.
While the full pipeline must be executed to reproduce results, the following scripts are the core entry points for the main analyses:
-
1-idp_correction/mass_decorrelate.py
Performs IDP correction for a given IDP across a range of principal components. -
2-model_training/models/ResNet/main.py
Defines the ResNet model architecture and training logic. -
3-compute_explanations/get_expls.py
Computes model explanations for a specified tasks and trained model checkpoint using selected XAI methods. -
4-xai_validation/cidp_based/compute_rma_scores.py
Evaluates explanations against ground-truth targets using the RMA metric.
brain-xai-benchmark/
├── 0-prep/ # Preparation scripts
├── 1-idp_correction/ # IDP correction and visualization
├── 2-model_training/ # Model definitions, configs, and training scripts
├── 3-compute_explanations/ # XAI implementations and scripts to compute model explanations
├── 4-xai_validation/ # Validation metrics and evaluation scripts
└── 5-natural_image_comparison/ # Natural image benchmark
Each folder corresponds to one segment of the pipeline, and the following sections explain them in order:
Scripts to compute basic elements required for IDP correction:
save_lin_reg_imgs.py→ saves linearly registered MRI images to diskfit_masker.py→ fits brain maskerprep_mass_decorrelate.py→ creates dataframe mapping IDPs to MRI image paths
Transforms raw IDPs into localized/corrected IDPs (cIDPs):
- mass_decorrelate.py → performs correction for a given IDP across a range of principal components
- Config files:
config_cortical.csvconfig_subcortical.csv
(contain IDP name strings, UKBB field IDs, keys for binary brain atlas)
Visualization notebooks:
visualize_cidp_across_npcs.ipynb→ effect of correction across PCsvisualize_cidps_given_npcs.ipynb→ plots for multiple cIDPs before/after correction- Cutout experiment:
2-model_training/models/ResNet/main_cutout.py
Scritps for training models to predict cIDPs and other targets.
- Implemented with PyTorch Lightning (
LightningModuleclasses in/models) - Configurations stored in
*.yamlfiles under/run_models - Required inputs:
split.json→ train/val/test splitdata_loader_table.csv→ target variable + paths to images/warp coefficients
Setup training files:
create_dataloader_table.ipynb(from corrected cIDPs)create_basic_split.ipynb(random 80/10/10 split)adapt_basic_split.ipynb(removes subjects with missing cortical IDPs)
table_and_split_for_art_dis.ipynb→ combines cIDPs into binary disease targets
create_dataloader_table.ipynbusing UKBB lesion load fieldadapt_basic_split.ipynbto drop subjects without T2 image from base split
create_dataloader_table.ipynbfor T1/T2 MRIs- Healthy train split from Siegel et al. (2025)
adapt_t1_brain_age_split.ipynbby removing subjects without T2 images
get_expls.py→ generates model explanations- Requires:
split.json, dataloader table, model checkpoint - Uses Lightning
Trainerclass and modeltest_step()functions
- Requires:
- XAI method implementations in:
xai_methods.py
Prerequisite: inverse-warp atlas target regions from nonlinear MNI space to participants' linear MNI space using prewarp_atlas.py
- Scripts for computing RMA, TPR, and FRP in
cidp_based/ - Metrics definitions:
metrics.py - Logic for generating ground-truth atlas targets:
1-idp_correction/atlas_methods.py
lesions/evaluate_lesion_expls.py- Warps lesion masks, calculates RMA scores, plots explanations
brain_age_ranking/compute_aging_marker_overlap.py- Ranks brain regions by explanation density or 99th percentile of explanation within region's mask; computes the overlap of the highest ranked regions and known biological markers of aging
- Requires table with known makers of aging (
aging_volume_table.csv; from Walhovd et al., 2011)
/brain_age_ms_contrast/disease_diff_effect_sizes.ipynb- Computes effect size maps for group differences masked by significance
- Requires matching file (patients vs. controls;
/brain_age_ms_contrast/files/matching_file.json)
eval_expls_with_seg_masks.py- Computes explanations for pretrained ResNet on ImageNet test/validation images
- Evaluates explanations with RMA metric and segmentation masks from ImageNet-S (Gao et al., 2021)
filter_rma_score_eval.ipynb- Creates result dataframe for heatmap plot (Fig. 4) by filtering previously computed RMA scores (e.g. by mask size and explanation cutoff), and by grouping scores with regards to ImageNet supercategories
git clone https://github.com/brain-tools/brain-xai-benchmark.git
cd brain-xai-benchmarkconda create -n brain-xai python=3.10
conda activate brain-xaipip install git+https://github.com/brain-tools/brain-deform.gitconda env update --file environment.yaml- UK Biobank (UKBB): Restricted-access dataset. You need UKBB approval to obtain IDPs and images.
- ImageNet-S: Available from https://github.com/LUSSeg/ImageNet-S.
If you use this code, please cite:
@article{siegel2025explainable,
title={Explainable AI Methods for Neuroimaging: Systematic Failures of Common Tools, the Need for Domain-Specific Validation, and a Proposal for Safe Application},
author={Siegel, Nys Tjade and Cole, James H and Habes, Mohamad and Haufe, Stefan and Ritter, Kerstin and Schulz, Marc-Andr{\'e}},
journal={arXiv preprint arXiv:2508.02560},
year={2025}
}