DiffBench is an open-source, reproducible benchmarking framework for evaluating machine learning and deep learning models on diffusion MRI (dMRI) microstructure-based prediction tasks. It enables controlled, systematic comparison across:
- Datasets: HCP, CamCAN, ABIDE
- Tissue types: gray matter (cortical surface), white matter skeleton
- Microstructural metrics: MD, MK, SH power, b0
- Model families: classical ML pipelines, 2D/3D CNNs, and vision foundation models (DINOv2, MedicalNet)
- Prediction tasks: binary classification and regression of cognitive/demographic targets
Jean Zay provides the required Python and PyTorch environment through modules.
module load pytorch-gpu/py3/2.7.0
pip install -e . --no-deps # -no-deps flag prevents reinstalling dependencies already provided by the module environment.Check that Python imports the package from the repository:
python -c "import diff_benchmark; print(diff_benchmark.__file__)"
# Output
/lustre/fswork/projects/rech/qlr/commun/diff_benchmark/src/diff_benchmark/__init__.pyIf the output instead points to a .local directory such as /linkhome/rech/genini01/unc81ab/.local/lib/python3.12/site-packages/diff_benchmark/__init__.py then an old installation is shadowing the editable version. Remove it, reinstall the package and verify again.
rm -rf /linkhome/rech/genini01/unc81ab/.local/lib/python3.12/site-packages/diff_benchmark
rm -rf /linkhome/rech/genini01/unc81ab/.local/lib/python3.12/site-packages/diff_benchmark-*.dist-info
pip install -e . --no-deps
python -c "import diff_benchmark; print(diff_benchmark.__file__)"
# Output
/lustre/fswork/projects/rech/qlr/commun/diff_benchmark/src/diff_benchmark/__init__.pyRun the benchmark configuration:
python -m diff_benchmark.cli.run_jz model=region_pca backend=sklearnTo run experiments on JZ we only care about the src/diff_benchmark/configs/main_jz.yaml configuration file and the rest of configuration files that are in the folders inside src/diff_benchmark/configs/, those will control the experiment.
src/diff_benchmark/configs/main_jz.yaml set the default files that are going to be read
Example:
defaults:
- dataset: hcp
- model: dinov2
- pred_head: binary_classificationdataset, model, pred_head are the directories inside src/diff_benchmark/configs/ and hcp, dinov2, binary_classification are .yaml configuration files inside their respective directories that control the parameters of each section (hcp has variables relative to the dataset information, dinov2 controls the hyperparameters of the model and binary_classification those of the pred_head used)
It's possible to configure all those files and hyperparameters from the command line by defining the directory and the new file we want to read:
python -m diff_benchmark.cli.run_jz dataset=camcanor specific parameters of certain configuration
python -m diff_benchmark.cli.run_jz dataset=camcan dataset.metric_to_compute=rtopRequires Python ≥ 3.12.
# Clone the repository
git clone <repo-url>
cd diff_benchmark
# Install with pip (editable)
pip install -e .
# Or with Poetry
poetry installThe benchmark follows a three-step pipeline:
1. Preprocessing (raw dMRI) → 2. Feature extraction → 3. Training & evaluation
Raw dMRI data must be preprocessed before running the benchmark. This is handled by the diffusion-preprocessing submodule, which wraps dMRIPrep-based pipelines and can be run via Docker or Singularity.
➡️ See diffusion-preprocessing/README.md for full instructions.
Compute microstructural maps (MD, MK, SH, b0) and project them to the cortical surface or white matter skeleton for all subjects in a dataset:
diffbenchmark-features dataset=hcp dataset.metric_to_compute=md dataset.tissue_type=grayOptionally, pre-cache features from frozen deep learning backbone models to disk to speed up subsequent training:
diffbenchmark-cache dataset=hcp model=dinov2Train and evaluate models across cross-validation folds:
diffbenchmark-run dataset=hcp model=pca_forest pred_head=binary_classification target=gender dataset.metric_to_compute=md dataset.tissue_type=grayAll commands use Hydra for configuration. Dataset paths and compute settings are defined in src/diff_benchmark/configs/cluster/. Overrides are passed as key=value arguments.
Compute and store microstructural features for all subjects in a dataset.
diffbenchmark-features dataset=hcp dataset.metric_to_compute=md dataset.tissue_type=grayRun a full benchmark experiment (cross-validation, metrics, per-fold predictions).
diffbenchmark-run \
dataset=hcp \
model=linear \
pred_head=regression \
target=age \
dataset.metric_to_compute=md \
dataset.tissue_type=whitePre-compute and cache features from a frozen backbone model to disk.
diffbenchmark-cache dataset=hcp model=dinov2Analyse experiment results and generate summary tables and plots.
# Both tables and plots (default)
diffbenchmark-analysis
# Only summary tables
diffbenchmark-analysis plots=false
# Only plots
diffbenchmark-analysis tables=false
# Force recompute of all plots
diffbenchmark-analysis force_plots=true
# Include debug plots for incomplete/failed runs
diffbenchmark-analysis analysis.debug=trueThe benchmark is configured via Hydra YAML files in src/diff_benchmark/configs/. The root config is main.yaml.
| Group | Available options |
|---|---|
dataset |
hcp, camcan, abide |
model |
linear, pca_linear, lasso, forest, pca_forest, svm, pca_svm, dummy_classifier, dummy_regressor, dinov2, curia, medicalnet |
pred_head |
binary_classification, regression |
target |
gender, age, dx_group |
dataset.tissue_type |
gray, white |
dataset.metric_to_compute |
md, mk, sh, b0 |
Dataset paths are set per compute environment in src/diff_benchmark/configs/cluster/. Create or copy an existing cluster config file and point it to your data:
# src/diff_benchmark/configs/cluster/my_env.yaml
name: my_env
paths:
hcp:
base_dir: /path/to/HCP/raw
results_dir: /path/to/HCP/preprocessed
csv_file: /path/to/HCP/demographics.csv
camcan:
base_dir: /path/to/camcan/raw
results_dir: /path/to/camcan/preprocessed
csv_file: /path/to/camcan/demographics.csvThen activate it with cluster=my_env in any command.
Experiment results are saved under exp_outputs/experiments/exp_<run_id>/:
exp_outputs/experiments/exp_<run_id>/
├── config.yaml # Full Hydra configuration used
├── metadata.yaml # Run metadata (model, dataset, status, timing)
├── metrics/ # Per-fold metrics (Parquet)
├── predictions/ # Per-fold predictions (Parquet)
├── debug/ # Debug training curves
└── logs/ # Run logs
Summary tables and plots from diffbenchmark-analysis are saved under exp_outputs/.
- Create a new script under
src/diff_benchmark/models/(indeep_models/orsklearn_models/). - Subclass one of the three abstract base classes from
src/diff_benchmark/models/:NumpyAbstractModel— for classicalsklearn-style pipelinesTorchAbstractModel— for PyTorch models with a custom training loop
- Implement the required methods:
fit,predict, and_dataloader_to_numpy. - Register your model in
src/diff_benchmark/models/model_configurations.py. - Add a corresponding YAML config in
src/diff_benchmark/configs/model/.