MIRAGE-MD
MIRAGE-MD (multi-dataset) predicts fMRI responses to images and short videos. It reads hidden states from a frozen Qwen3-Omni-30B-A3B-Thinking and maps them to response amplitudes in 1,412 brain parcels. It uses the MIRAGE architecture (NeurIPS 2026), trained on five fMRI datasets instead of one: Courtois NeuroMod (Friends and Movie10, the data of the original MIRAGE), BOLD Moments and McMahon et al. (3 s video clips), and NSD and THINGS-fMRI (natural images). It reads a video's frames; its audio track and a transcript can be added.
Quick start
pip install torch "transformers>=4.57,<5.22" "av>=14" pillow torchvision
from transformers import AutoModel
model = AutoModel.from_pretrained(
"epfl-neuroai/mirage-md", revision="v1", trust_remote_code=True
).to("cuda")
clip = model.encode_video("clip.mp4")
clip.betas.shape # (windows, 1412), one row per ~3 s
clip.windows # [(0.0, 3.0), (3.0, 6.0), ...] in seconds
image = model.encode_image("photo.jpg") # also a PIL image or an HxWx3 uint8 array
image.betas.shape # (1, 1412)
image.windows # None
with_sound = model.encode_video("clip.mp4", audio=True, transcripts="clip_words.tsv")
A transcript is a list of (word, onset_s, duration_s) or a .tsv/.csv file
with word, onset and duration (or end) columns.
Audio and transcripts are off by default. Only the Friends heads were
trained with them. The BOLD Moments, McMahon, NSD and THINGS-fMRI stimuli were
shown without sound, so those heads learned from frames and images alone.
Audio also changes how Qwen reads the frames, and it makes predictions for
silent experiments worse: on the held-out BOLD Moments clips, default drops
from 0.186 to 0.158 with the clips' own soundtracks and to 0.157 with
unrelated speech. A transcript without audio changes little (0.179). Turn
them on for stimuli people hear as well as see, mainly with
readout="dataset:friends".
trust_remote_code=True runs modeling_mirage_md.py from this repository; pin
revision to the version you reviewed. from_pretrained loads the adapter
(1.24 B parameters, from this repository) and Qwen3-Omni, which it downloads
from Qwen's repository
at a pinned revision. Qwen3-Omni passes through CPU memory on its way to the GPU
and needs about 60 GB of GPU memory in bfloat16, so use an 80 GB GPU.
Feature caching
The backbone takes nearly all the compute, so extract features once and reuse them with any readout:
paths = ["clip1.mp4", "clip2.mp4", "photo.jpg"]
features = model.extract_features(paths) # list of Features, one per file
outputs = model.predict(features) # list; outputs[i].betas is (windows, 1412)
nsd = model.predict(features, readout="dataset:nsd")
heads = model.predict(features, readout="subjects") # each .betas is (windows, 30, 1412)
To compute betas from saved features without Qwen, load only the adapter with
AutoModel.from_pretrained(..., load_backbone=False).
paths can mix videos and images; files ending in .jpg, .jpeg, .png,
.bmp, .gif, .webp or .tif(f) are read as images and everything else as
video. Pass kind="image" or kind="video" to override this, audio=True to
read audio tracks, and transcripts=[...] (one per file, or None) to add
words. While the GPU works on one group of files, the next group is decoded on
CPU threads.
Readouts
There is one linear head per training subject (30 in total). A readout chooses which heads to average:
readout= | Heads |
|---|---|
"default" | Videos: Friends + BOLD Moments. Images: NSD + THINGS-fMRI |
"all" | All five datasets |
"dataset:<name>" | One dataset: friends, bold-moments, mcmahon, nsd, things |
"subject:<dataset>:<id>" | One subject, for example "subject:nsd:sub-01" (see model.subjects) |
"subjects" | All 30 heads, stacked |
Group readouts give each dataset the same weight, and each subject the same weight within a dataset. A single subject's output is in that dataset's z-scored units; group outputs mix datasets, so treat their scale as approximate.
Performance
Mean Pearson r over cortical parcels on each dataset's held-out stimuli, averaged over its subjects, with video frames or images as input. Group readouts are scored against every subject of the dataset.
| Readout | BOLD Moments | McMahon | NSD | THINGS-fMRI |
|---|---|---|---|---|
| Each subject's own head | 0.225 | 0.264 | 0.198 | 0.134 |
default | 0.186 | 0.208 | 0.148 | 0.121 |
all | 0.184 | 0.243 | 0.138 | 0.110 |
dataset:bold-moments | 0.204 | 0.192 | 0.113 | 0.096 |
dataset:friends | 0.131 | 0.168 | 0.092 | 0.076 |
dataset:mcmahon | 0.137 | 0.243 | 0.103 | 0.077 |
dataset:nsd | 0.166 | 0.196 | 0.159 | 0.099 |
dataset:things | 0.122 | 0.132 | 0.091 | 0.127 |
default uses the video heads for BOLD Moments and McMahon and the image heads
for NSD and THINGS-fMRI. A dataset's own heads score best on it, or tie with
all (McMahon). For stimuli unlike any training set, use default or all. Friends is not shown: its held-out data are continuous
recordings, which this table does not cover.
Speed
Time after loading, on one GPU, with the default batch_windows=8. Videos: 64
clips from Koala-36M (mostly 360p, 4-20 s, mean 9.2 s). Images: 256 NSD images.
| GPU | Seconds per second of video | Video clips per hour | Images per second |
|---|---|---|---|
| A100 80 GB | 0.35 | 1,100 | 13 |
| H100 80 GB | 0.13 | 2,900 | 52 |
| H200 141 GB | 0.12 | 3,150 | 55 |
Video cost grows with duration: at 0.13 s per second of video, a million 10 s
clips take about 370 H100 hours. predict (any readout) takes 5-20 ms per
file, so trying other readouts on cached features costs almost nothing. Peak
GPU memory is 70 GB; batch_windows=16 is 5-10% faster and needs 75 GB.
Loading takes 7-9 minutes, mostly reading Qwen3-Omni's 60 GB of weights from
disk; the first run downloads them.
How it works
- Input. Videos are decoded with PyAV. Every 0.5 s, the model looks at the
preceding 4 s, sampled at 2 frames per second (at most 8 frames), and, with
audio=True, at the preceding 60 s of sound; a transcript adds the words spoken so far. An image is a single step. This follows how the training features were extracted (frames only for the clip and image datasets; frames, sound and transcripts for Friends and Movie10). - Backbone. Qwen3-Omni's thinker runs on each step in bfloat16, with the sound interleaved with the frames. Its 49 hidden states are pooled per input: the video tokens of the last two frames (all image tokens for an image), the audio token at the step, and the tokens of each word, giving 49 × 2048 features per step.
- Adapter. A MIRAGE encoder (layer pooling with learned queries for each input, then a causal temporal transformer) turns the steps into a sequence of states. Inputs that are missing enter as zeros, as in training. See the paper for the architecture.
- Output. For a video, the states are averaged within windows of about 3 s: a clip of length T gets max(1, round(T / 3)) windows of nearly equal length. Each window, or the single state of an image, is mapped to 1,412 response amplitudes by the readout.
The outputs are response amplitudes (betas): one value per parcel for each window or image, like the targets of the clip and image datasets.
Training data
| Dataset | Stimuli | Subjects | Scan hours |
|---|---|---|---|
| Friends and Movie10 (Courtois NeuroMod) | TV episodes and 44 film segments | 5 | 336 |
| BOLD Moments | 1,102 video clips, 3 s | 10 | 68 |
| McMahon et al. 2023 | 250 video clips, 3 s | 4 | 18 |
| NSD | 70,566 natural images | 8 | 285 |
| THINGS-fMRI | 8,740 object images | 3 | 43 |
For the clip and image datasets, the targets are single-trial GLM betas, averaged over repetitions and z-scored per subject.
Parcels
1,412 parcels, in this order:
| Indices | Atlas | Coverage |
|---|---|---|
| 0-999 | Schaefer 2018, 1,000 parcels, 7 networks | cortex |
| 1000-1357 | Cole-Anticevic network partition (CAB-NP) | subcortex, cerebellum and brainstem |
| 1358-1411 | Tian 2020, scale IV | subcortex |
model.parcels lists each parcel's label, atlas, hemisphere and network.
Parcels 532 (7Networks_RH_Vis_33) and 902 (7Networks_RH_Cont_Cing_1) have
no vertices on the fsLR-32k surface, so they had no training data. The model
returns NaN for them, and the cortical scores above use the other 998.
Intended use and limitations
MIRAGE-MD is meant for research: labeling image and video collections with predicted brain responses, and studying how those responses vary across stimuli.
- The clip and image heads never saw audio or transcripts, and audio makes their predictions worse (see the note under Quick start).
- Group readouts are less accurate than a subject's own head (by 0.01-0.06 r in the table above).
- Inputs longer than about 20 s are untested. Split long videos into clips of 20 s or less; each clip starts without context from the previous one. Every sampled frame of a file is held in memory, so keep inputs to a few minutes.
- Each head models one training subject; the model does not adapt to new people.
Provenance
The adapter was converted from the training checkpoint and checked against the training code: on the same features, the betas agree to within 4e-6 of their standard deviation. From image and video files through Qwen, the betas correlate with the training pipeline's at r ≥ 0.999 on 60 test stimuli, close to the training pipeline's own run-to-run agreement (r ≥ 0.9996).
License
The code and adapter weights are released under Apache-2.0. Qwen3-Omni, which is downloaded from Qwen's repository, is also Apache-2.0. The heads were trained on these datasets, each under its own terms:
| Dataset | Terms |
|---|---|
| Courtois NeuroMod (Friends, Movie10) | CNeuroMod data transfer agreement |
| BOLD Moments | CC0 |
| McMahon et al. 2023 | CC0 |
| NSD | CC0 |
| THINGS-fMRI | CC0 |
Citation
@inproceedings{gokce2026mirage,
title = {{MIRAGE}: Adaptive Multimodal Gating for Whole-Brain f{MRI} Encoding},
author = {Abdulkadir Gokce and Badr AlKhamissi and Martin Schrimpf},
booktitle = {The Fortieth Annual Conference on Neural Information Processing Systems},
year = {2026},
url = {https://openreview.net/forum?id=o0Kim6sdzg}
}