Implementation of:
-
The Wisdom of a Crowd of Brains: A Universal Brain Encoder — Roman Beliy*, Navve Wasserman*, Amit Zalcher, Michal Irani. arXiv:2406.12179
* Stands for equal contribution.
Environment requirements are in env.yml. To create the conda environment:
conda env create -f env.yml
conda activate brain-itThis repository implements the Universal Brain Encoder (image-to-fMRI encoding), as described in the paper above.
├── data/
│ ├── nsd_data/ # NSD dataset files
│ └── scripts/ # Data processing scripts
├── models/ # Model architectures
├── train/ # Training scripts
├── train_transfer/ # Transfer learning scripts
├── inference/ # Encoder inference / prediction
├── utils/ # Utility functions
└── results/ # Output directory
└── saved_models/ # Trained model checkpoints
Download NSD stimulus images, fMRI beta maps, and ROI masks for all 8 NSD subjects:
bash data/scripts/run_all_downloadsNote: If you are interested in per-ROI analysis, you can download the relevant ROI masks from this Google Drive folder.
Download the pretrained encoder checkpoint from Hugging Face:
python data/scripts/download/download_encoder.pyThis places the encoder checkpoint in results/saved_models/.
Run all data processing steps:
bash data/scripts/run_all_data_processingOr run individual steps manually:
python data/scripts/data_processing/prepare_imgs.py
python data/scripts/data_processing/prepare_fmri.pyTrain the Universal Brain Encoder:
python train/train_encoder.pyEvaluate the encoder on the shared NSD test set (predictions + voxel correlations):
python inference/encoder_inference.pyStep-by-step walkthrough: inference/encoder_inference.ipynb.
Predict fMRI for a custom image array (optional ROI / hemisphere):
python inference/predict_fmri_for_images.py --images path/to/images.npy --subjects 1 2 5 7
python inference/predict_fmri_for_images.py --images path/to/images.npy --region floc-faces --hemisphere bothROI helpers live in utils/roi_utils.py. Region can be full, an ROI family (e.g. floc-faces), or a single ROI (e.g. EBA). Challenge-space ROI masks should be placed under data/nsd_data/roi_masks/subjXX/roi_masks/ (see the Drive link in Data Download).
To adapt pretrained models to held-out NSD subjects, follow the transfer learning pipeline in train_transfer/README.md.
This code accompanies the arXiv preprint linked at the top of this README. The PDF is shared under the license stated on the arXiv record (see the “license” icon on the abstract page). If you use this code, please cite the paper. Third-party or vendored code may have its own terms—check the relevant subdirectories.
For questions or inquiries: roman.beliy@weizmann.ac.il.