Spaces:
Runtime error
Runtime error
File size: 5,509 Bytes
898f6fe 041602e 898f6fe 21d2cdc 041602e 898f6fe 3115340 041602e 898f6fe 041602e 3115340 041602e 3115340 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | ---
title: BrainAnytime Demo
emoji: π§
colorFrom: purple
colorTo: yellow
sdk: gradio
sdk_version: 6.14.0
python_version: '3.10'
app_file: app.py
pinned: false
license: mit
arxiv: 2605.13059
models:
- Simmonstt/BrainAnytime
---
# BrainAnytime
Official implementation of **BrainAnytime: Anatomy-Aware Cross-Modal Pretraining for Brain Image Analysis with Arbitrary Modality Availability**.
## Paper
**BrainAnytime: Anatomy-Aware Cross-Modal Pretraining for Brain Image Analysis with Arbitrary Modality Availability**
- arXiv: [2605.13059](https://arxiv.org/abs/2605.13059)
- PDF: [https://arxiv.org/pdf/2605.13059](https://arxiv.org/pdf/2605.13059)
## Congrats: This paper has been early accepted (top 9%) by MICCAI 2026.
## Pretrained Weights
**Finetuned checkpoints are available on Hugging Face: [Simmonstt/BrainAnytime](https://huggingface.co/Simmonstt/BrainAnytime).**
Pretrained weights are also available at [Google Drive](https://drive.google.com/file/d/1L49zJ_Apj2jJe88_iy6jLcmd6KUlnc5h/view?usp=sharing).
## Overview
BrainAnytime is a self-supervised pretraining framework for multi-modal 3D brain imaging (T1, T2, Flair, PET) that handles **arbitrary missing modality combinations** at both training and inference time.
### Key Features
- **Multi-modal Masked Autoencoder (MultiMAE3D)**: Shared ViT encoder with per-modality input/output adapters, supporting 4 modalities (T1, T2, Flair, PET)
- **Cross-Modal Mutual Prediction**: EMA teacher-student framework for MRI-PET cross-level feature alignment
- **Anatomy-Aware Adaptive Masking**: Three-phase curriculum masking guided by AAL116 brain atlas and AD-relevant region priors
- **Missing Modality Robustness**: Handles arbitrary missing modality combinations via attention masking and observed indicators
## Project Structure
```
BrainAnytime/
βββ models/
β βββ multimae3d.py # MultiMAE3D model architecture
β βββ multimae3d_utils.py # Patchify, masking, positional embeddings
βββ anatomy_masking.py # Anatomy-aware adaptive masking module
βββ pretrain_dataloader_v2.py # Multi-modal pretraining data loader
βββ train_multimae.py # Pretraining script (single/multi-GPU DDP)
βββ finetune_main.py # Downstream finetuning (CN vs AD, CN vs MCI, MMSE, AGE)
βββ test_main.py # Test-only evaluation
βββ altas/
βββ AAL116_standard.nii.gz # AAL116 brain atlas (128x128x128)
```
## Requirements
- Python >= 3.8
- PyTorch >= 1.12
- torchio
- nibabel
- timm
- einops
- tensorboardX
- scikit-learn
- pandas
- scipy
- tqdm
## Data Preparation
Organize your data as follows:
```
./data/
βββ Match_data_path/
β βββ pretraining_processed/ # Pretraining Excel files
β βββ modality_data_A4.xlsx
β βββ modality_data_ADNIDOD.xlsx
β βββ modality_data_AIBL.xlsx
β βββ modality_data_BraTS.xlsx
β βββ modality_data_NACC.xlsx
βββ Pretrain/ # Preprocessed NIfTI files for pretraining
βββ Downstream/
βββ ADNI/ # Downstream task data
βββ ADNI_Division/
βββ modality_data_train.xlsx
βββ modality_data_val.xlsx
βββ modality_data_test.xlsx
```
Each Excel file should contain columns for subject IDs and file paths to the corresponding NIfTI images for each modality.
## Attention
To save training time, we preprocess the 3D multimodal image by following skull stripping, MN152 template co-registration, minβmax normalization, and resampling to 128 Γ 128 Γ128 in advance. The data loader only contains data augmentation during training.
## Usage
### Pretraining
```bash
# Single GPU
python train_multimae.py --batch_size 4
# Multi-GPU DDP (8 GPUs)
torchrun --nproc_per_node=8 train_multimae.py \
--batch_size 16 \
--enable_cross_modal \
--use_anatomy_masking \
--atlas_path altas/AAL116_standard.nii.gz
```
### Downstream Finetuning
```bash
# Finetune on all tasks (3 seeds each)
python finetune_main.py \
--pretrained ./pretrain_checkpoints/multimae/best_model.pth
# Specific task only
python finetune_main.py \
--pretrained ./pretrain_checkpoints/multimae/best_model.pth \
--tasks "CN vs AD"
```
### Testing
```bash
# Test all tasks for finetune mode
python test_main.py --mode finetune
# Test a specific task
python test_main.py --mode finetune --tasks "CN vs AD"
```
## Downstream Tasks
| Task | Type | Metric |
|------|------|--------|
| CN vs AD | Classification | ACC, AUC, Sensitivity, Specificity, F1 |
| CN vs MCI | Classification | ACC, AUC, Sensitivity, Specificity, F1 |
| MMSE | Regression | MAE, RMSE, Pearson |
| AGE | Regression | MAE, RMSE, Pearson |
## License
This project is released for academic research purposes only.
## Citation
If you use BrainAnytime in your research, please cite:
```bibtex
@misc{yang2026brainanytimeanatomyawarecrossmodalpretraining,
title={BrainAnytime: Anatomy-Aware Cross-Modal Pretraining for Brain Image Analysis with Arbitrary Modality Availability},
author={Guangqian Yang and Tong Ding and Wenlong Hou and Yue Xun and Ye Du and Qian Niu and Shujun Wang},
year={2026},
eprint={2605.13059},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2605.13059},
}
```
Paper page: https://arxiv.org/abs/2605.13059
|