MindEye2

One model, pretrained on seven brains, redraws what a new person saw after just one hour of their scan. Forty hours of data bought a better picture, but one hour already finds the right image 79% of the time.

Pick a model. Watch two things: how close the decoded picture is to the real scene, and how many of 300 test scans it matches to the right image. Then we build, piece by piece, how MindEye2 turns a brain scan into a picture.

You need a rough idea of what a neural network is and what a vector is (a list of numbers). We build the rest from zero: fMRI, ridge regression, CLIP, contrastive learning and diffusion.

Based on Scotti, Tripathy, Torrico Villanueva, Kneeland, Chen, Narang, Santhirasegaran, Xu, Naselaris, Norman and Abraham, “MindEye2: Shared-Subject Models Enable fMRI-To-Image With 1 Hour of Data”, ICML 2024 (PMLR 235), arXiv 2403.11207. It is a reading of the lecture LLMs and the Language Brain. Every idea is re-taught here in our own words and devices; every real number comes from the paper’s tables.

Decode a brain scan

The retrieval rates and two-way identification scores are the paper’s Table 1 (average of subjects 1, 2, 5 and 7; 300 candidates, chance 0.3%). The toy scene and its noise are illustrative: the blur grows as AlexNet(2) accuracy falls, so it shows rank, not real reconstructions.

Chapter 0

Why a Brain Decoder Needs Forty Hours

See why decoding a picture from a brain scan used to cost one person a full work week in a scanner, and what MindEye2 changes

Picture a volunteer lying inside a magnetic resonance imaging (MRI) scanner. A screen above her shows a photo for three seconds: a surfer on a wave. A blank gap follows, then a photo of a cat on a table. The scanner hums and records her brain the whole time.

Later, a computer sees only the recordings. It never sees the photos. Its job is to redraw the surfer and the cat from the brain activity alone. This task is called fMRI-to-image reconstruction: turning a scan of the brain back into the picture the person was looking at.

The idea sounds like science fiction, and a few years ago it was. By 2023 it worked well. Models such as MindEye1 drew pictures with the right objects, the right layout and often the right colours. The hero at the top of this page lets you compare them.

The catch: one model per person

Every earlier method had one hidden cost. It trained a separate model for each person. A model trained on the brain of person A does not work on person B, because the two brains are wired and shaped differently.

So each new person had to lie in the scanner for a long time first. The Natural Scenes Dataset (NSD), the data these papers use, scanned each of 8 volunteers for 30 to 40 hours. That is dozens of visits. A scanner hour is expensive, and few patients can lie still for 40 hours.

The authors say plainly why this matters. A method that needs 40 hours per person cannot reach a clinic. The paper hopes for uses such as new ways to assess patients and, one day, brain-computer interfaces (BCIs, systems that read the brain to control a device). All of them need a short session.

The claim, written as a trade

MindEye2 does reconstruction from 1 hour of a new person’s data where earlier methods needed about 40 hours, because of how it is trained. It pretrains one model on 7 other people first. Then it fine-tunes that model on the new person. Only a small, simple first layer is private to each person.

One hour is 2.5% of the full dataset. The authors report that this gives quality similar to a single-person model trained with 40 times the data. Press MindEye2, 1 hour in the hero and compare it with MindEye1, 40 hours. The one-hour picture is fuzzier, but the object is often still there.

Three ideas you need to hold

First, the brain scan is a long list of numbers, one for each tiny cube of cortex (a voxel). The model does not look at a picture of the brain. It looks at about 12,700 to 17,900 numbers per scan. Chapter 1 explains where they come from.

Second, the model does not paint pixels directly. It first predicts an embedding, a short summary of the image as a list of numbers, taken from a model named CLIP. Then a second, already trained model turns that summary into a picture. Chapters 4 and 7 cover this split.

Third, the new person can reuse what other people taught the model. Only the first layer is private to each person, and that layer is as simple as a model can be. Chapters 2 and 3 show why that works.

Count the scanner hours

Each block is one hour of a volunteer in the scanner. Drag the slider to choose how many hours the new person gives. The row below shows how many of the 40 the model was spared.

1

One session is 750 image presentations and the paper calls it about one hour (Section 3). Forty sessions is the full NSD protocol for subjects 1, 2, 5 and 7. The quality you get at each hour count is in Chapter 8.

Slide to 1. One block is filled and 39 are empty. That emptiness is the paper’s whole promise: the model has to do well while 39 of 40 sessions are missing. The next chapters build the machinery that makes that possible.

The road

  1. What an fMRI scan is: voxels, trials, and why one hour is only 750 examples.
  2. Why little data breaks big models: ridge regression and overfitting.
  3. One model for many brains: the shared-subject alignment step.
  4. The target: a CLIP embedding: what the model predicts instead of pixels.
  5. Retrieval and contrastive learning: finding the right image, and BiMixCo and SoftCLIP.
  6. Diffusion prior and low-level submodule: the loss that ties the parts together.
  7. From embedding to pixels: SDXL unCLIP, captions and refinement.
  8. What the tables show: results, ablations and limits.
  9. Field Guide: numbers, checklist, core code, and where to go next.
Why did earlier fMRI-to-image models need dozens of hours from every new person?

Chapter 1

What One Hour of Scan Gives You

Count the voxels and the trials, and see why an hour of data is a thin strip of examples

A volunteer looks at a photo of a zebra. Blood flows to the brain cells that fire hardest. Blood that carries more oxygen changes the magnetic signal there, and the scanner can measure that change. That measure is functional magnetic resonance imaging (fMRI).

So fMRI does not see neurons fire. It sees the blood that follows them, a slow and indirect echo. The paper says it plainly: fMRI “indirectly measures neural activity by detecting changes in blood oxygenation”.

From a brain to a list of numbers

The scanner divides the brain into small cubes. Each cube is a voxel, a 3D pixel of cortical tissue. In this dataset a voxel is 1.8 millimetres on a side. Each voxel gets one number per image: how strongly it responded.

MindEye2 keeps only the voxels of the back of the brain that respond most to what the eyes see. The dataset authors call this region nsdgeneral. It has between 12,682 and 17,907 voxels, depending on the person (Figure 2 lists all eight).

Now flatten those voxels into one long row. For subject 1 the row has 15,724 numbers. One image seen once gives one such row. We call this pair, a row of voxels and the image that caused it, a trial. The shape of one input is (15,724,).

How the data were collected

The Natural Scenes Dataset (NSD) is a public 7-tesla fMRI dataset. Eight volunteers each looked at photos from the COCO collection (everyday scenes with people, animals and objects). A session showed 750 photos for 3 seconds each. Each volunteer completed 30 to 40 sessions.

Each photo appeared three times over the sessions. Most photos were unique to one volunteer. Only 1,000 photos were seen by everybody. The field uses those 1,000 as the test set, and so does MindEye2. Training photos never appear in the test set.

The 1,000 test brain samples are averaged across the three repeats of each photo, which cuts noise. The training samples are not averaged. The model trains on single trials. The paper counts 30,000 training samples for a 40-session subject.

Stack the trials

Each row of the block is one trial and each column is one voxel of subject 1. The width is fixed. Drag the sessions and watch the block grow taller. The dashed line marks the point where trials equal voxels.

1

Voxel count (15,724) is subject 1 from the paper’s Figure 2. Trials are 750 per session, as the paper states in Section 3. The block is drawn to scale.

At 1 session the block is a thin strip: 750 rows against 15,724 columns. A model that fits 15,724 unknown weights from 750 examples has more unknowns than examples. Chapter 2 shows how that fails and how a simple rule repairs it.

Cleaning the numbers

Raw voxel values drift between sessions and differ in scale between voxels. The paper uses single-trial estimates from a tool called GLMSingle, then z-scores each voxel. To z-score is to subtract the voxel’s average and divide by its spread.

z
The cleaned value: how many spreads above the usual response this trial sits.
x
One voxel’s raw response on one trial.
μtrain
The average response of that voxel over the training trials only.
σtrain
The spread (standard deviation) of that voxel over the training trials only.

Illustrative: μ = 2.0, σ = 0.5, x = 3.0 → z = (3.0 − 2.0) / 0.5 = 2.0 (two spreads above normal)

Statistics come from the training set only. The paper adds a careful note. It normalises first, then keeps only the first N sessions for training. This keeps the test set the same across experiments. It may give a small normalisation advantage to models trained on little data, because the statistics used extra data.

Chronological slices

One more rule matters for honesty. A model trained on “1 hour” uses the subject’s first session, in order. It does not pick the 750 best trials. The test set stays the same 1,000 photos whatever the amount of training data, and none of them appears in training.

A worked count, and a failure to avoid

Count the numbers in one hour. A session has 750 trials, and each trial is a row of 15,724 voxels. That is 750 × 15,724 = 11,793,000 numbers. The full 40 sessions hold 30,000 × 15,724 = 471,720,000 numbers. The one-hour model sees 2.5% of this.

Now the failure. Suppose you z-score with statistics from all trials, test trials included. The test voxels then carry a faint trace of the training data, and scores rise for no real reason. The symptom is a result that looks too good. The measurement is a drop when you recompute with training-only statistics. The fix is the rule above: compute μ and σ from the training set and apply them to the test set.

The repeats help in one place. Averaging the three repeats of a test photo lowers the noise in that brain sample. A standard statistic says the noise spread falls by about the square root of 3, roughly 1.7 times. This is general statistics, not a number from the paper. The training samples keep their full noise, which is why the model must tolerate it.

Subject 1 has 15,724 voxels. How many examples does the one-hour model train on, and why does that matter?

Chapter 2

Why Little Data Breaks Big Models

Fit a flexible model to a few noisy points, watch it memorise the noise, and fix it with one penalty

You ask five friends to guess the price of a house, and you draw a curve through their guesses. A stiff curve, a straight line, ignores small quirks. A wiggly curve hits every guess exactly, even the one friend who was joking. Which curve predicts the next house better?

The wiggly curve fits the old guesses perfectly and the new house badly. This failure is called overfitting: the model learns the noise in its examples and mistakes it for signal. It happens when a model has many knobs and the data are few.

The linear decoder

MindEye2’s first step is the simplest model there is: a linear map. It multiplies the voxel row by a table of weights and adds up. In shapes, voxels (15,724,) times weights (15,724 × 4096) gives a (4096,) latent, a short list of 4,096 numbers.

To fit it, you pick weights so the predictions match the targets on the training trials. The usual score is the sum of squared errors. With one target number the fit looks like this. Read “argmin” as “the weights that make the total below as small as possible”.

ŵ
The best weights we are looking for.
‖y − Xw‖2
The squared error. X holds the trials (one row each), w the weights, y the targets. The bars mean “add up the squares”.
λ
A dial you set. A larger λ punishes large weights more.
‖w‖2
The sum of the squared weights: the L2 penalty. It is the price of using large weights.

With λ = 0 this is plain least squares. With λ > 0 it is ridge regression. Deep learning code calls the same penalty weight decay. The paper uses both names for its per-subject layer: “a separate linear layer with weight decay”.

The closed form, step by step

Set the slope of the objective to zero. The slope with respect to w is −2XT(y − Xw) + 2λw. Setting it to zero gives XTXw + λw = XTy. Group the w terms and solve.

w = (XTX + λI)−1 XTy

The added λI is the key. When voxels outnumber trials, XTX cannot be inverted: infinitely many weight tables fit the data exactly. Adding λ on the diagonal makes the inverse exist and picks the table with small weights.

Try one feature to see the pull. Three trials: x = (1, 2, 3), y = (1.1, 1.9, 3.2). Then XTy = 1.1 + 3.8 + 9.6 = 14.5 and XTX = 1 + 4 + 9 = 14. With λ = 0, w = 14.5 / 14 = 1.036. With λ = 1, w = 14.5 / 15 = 0.967. With λ = 14, w = 14.5 / 28 = 0.518. A bigger λ shrinks the weight toward zero. This is illustrative arithmetic, not the paper’s data.

Penalise the wiggles

The blue curve is the truth. Dots are noisy samples. The warm curve is a 9th-degree polynomial fitted with ridge. Set few samples, then raise the penalty.

12
-6

Illustrative toy: truth sin(2.2x), noise 0.25, 10 weights, seeded so every visit shows the same points. The error is the root-mean-square gap between the fit and the truth on 100 test positions. It shows the mechanism, not the paper’s numbers.

At 12 samples and a tiny penalty the curve swings wildly between points. This is the symptom. The measurement is the test error in the read-out: it is large. The fix is to raise λ until the error drops. With 60 samples the wiggles fade even with no penalty, because data replace the penalty.

Why MindEye2 wants a linear layer

MindEye1 used a bigger first step: a multi-layer network with dropout. MindEye2 replaces it with one linear layer plus L2. The paper argues that “simple mappings are less likely to overfit to noise” in low-sample, high-noise settings. fMRI is exactly that.

The paper tests this in Table 4. With the first step swapped back to MindEye1’s version, PixCorr falls from 0.292 to 0.225 and image retrieval from 97.4% to 84.9%. These models were trained from scratch in reduced capacity on 10 sessions of subject 1. We read the table fully in Chapter 8.

Choosing lambda, and what goes wrong at each end

Lambda is a dial. Too small and the fit memorises noise. Too large and every weight shrinks toward zero, so the model predicts nearly the same output for every input. Take the one-feature example: as λ grows to infinity, w = 14.5 / (14 + λ) falls to zero.

So there is a middle. The usual way to find it is to hold some trials back, fit with several values of λ, and keep the value with the lowest error on the held-back trials. The device in this chapter does the same job by eye: it shows the error against the truth, which you cannot see in real data. The paper reports the final layer as a linear map with weight decay; it does not list the value of the decay in the main text.

The failure has a symptom you can watch for. If predictions from a ridge layer look nearly constant across different photos, λ is too big. If they swing wildly between similar photos, λ is too small. Both are cheap to check, because you only need the predictions, not the pictures.

Read more on this idea in Regularization and Optimization, Linear Regression and Bias and Variance.

There are 15,724 voxels and 750 trials. Why does plain least squares fail, and what does the ridge term do?

Chapter 3

One Model for Many Brains

Give each person a private first layer, share everything after it, and let a new person borrow what seven others taught the model

Seven people each write you a letter in their own handwriting and their own language. You want one reader to understand all of them. You could hire seven readers, one per person. Or you could hire one translator per person, who rewrites each letter in a common language, and then one reader for the common language.

MindEye2 takes the second route. The private translator is a linear layer. The common language is a list of 4,096 numbers. The reader is everything after that, shared by all.

Why brains cannot be stacked directly

Every brain has its own shape and its own map of what each region does. Voxel number 5,000 of subject 1 and voxel number 5,000 of subject 2 are not the same place. Subjects even have different counts: subject 1 has 15,724 voxels, subject 2 has 14,278, subject 7 has 12,682.

The classic fix is anatomical alignment: warp every brain into one template brain. The paper notes this is imperfect. MindEye2 does functional alignment instead. It leaves each brain in its own space and learns a map from that space to a shared one.

Older functional alignment needs everyone to see the same images, so the maps can be matched. NSD does not allow that: 90% of each person’s images are unique to them. MindEye2 needs no shared images. The alignment is learned by training the whole network end to end, and the shared pipeline forces all subjects into one language.

The data flow, with shapes

Take one training batch. It has 63 trials: 9 from each of 7 subjects. Subject A’s 9 trials form a table of shape (9, 15,724). Subject B’s form (9, 14,278). The tables have different widths, so each goes through its own layer.

Each subject’s linear layer outputs (9, 4096). Stack the seven outputs and you get (63, 4096). From here on the rows are in one language. The residual MLP backbone (4 residual blocks) and the later parts handle all 63 rows the same way. The loss is computed on the whole batch, and the gradients flow back into the shared parts and into each private layer.

Route the brains

Bars on the left are subjects, as tall as their voxel counts. Choose the stage. Lit paths carry data that stage uses.

Voxel counts are from the paper’s Figure 2. The batch of 63 (9 samples from each of 7 subjects) is from Section 2. Weight counts are voxels times 4,096, computed here; they leave out biases. Subject 1 is the held-out subject in the paper’s schematic.

Each private layer is large. For subject 1 it holds 15,724 × 4,096, about 64 million weights. This is the layer that ridge regression (Chapter 2) must fit from 750 trials. That sounds heavy, and it is why the layer is linear with weight decay. Only the layer is private; the rest already knows how to read the common language.

Pretrain, then fine-tune

In pretraining, the model trains on subjects 2 to 8 together. It samples equally from each, so no subject dominates. In fine-tuning, a new private layer is made for the held-out subject and the model trains on their small dataset. The paper reports the single-subject runs used 150 epochs at batch size 24.

The effect is large at small data. The paper reports that models without pretraining, trained on 10 or 30 minutes of data, “suffered significant instability” and may have collapsed to near-identical outputs for any input. Pretrained models degrade gracefully. As data grows, the two curves meet.

How many pretraining subjects are needed?

Appendix A.11 runs a test. It fine-tunes subject 1 on 1 hour after pretraining on subjects 2, 5 and 7, or on subject 5 only, instead of all seven. Image retrieval was 94.0% with all seven, 92.7% with three and 90.6% with one. PixCorr was 0.235, 0.234 and 0.232. The authors conclude that the number of pretraining subjects does not seem to play a major role.

How this differs from older alignment work

The paper compares itself with Ferrante et al. (2023a), who also used ridge regression to a shared space. Their method first trains a model on one subject, then maps each other subject into that model’s space. Quality is capped by that first model, and fine-tuning is only linear. They also used a reduced dataset of images seen by all subjects.

MindEye2 differs in three ways. A single network is trained across all subjects at once. The whole pipeline can be fine-tuned, not only a linear map. And the subjects need not have seen the same pictures. The paper calls it unique in showing a single network pretrained across subjects with unique stimuli and then robustly fine-tuned on few data points.

One failure to keep in mind: if one subject supplied far more trials than the rest, the shared parts would learn that person’s quirks. Equal sampling per batch, 9 from each, is the paper’s guard against it. The symptom would be good scores for the big subject and poor scores for the others. You would measure it with a per-subject table such as the paper’s Tables 7 and 8.

In one pretraining batch, why does each subject need its own first layer?

Chapter 4

The Target Is a CLIP Embedding, Not Pixels

Learn what an embedding is, how cosine similarity compares two of them, and why the brain model predicts one instead of a picture

Imagine describing a photo to a friend over the phone. You do not read out a million pixel colours. You say “a surfer riding a big wave, bright sky”. That short description keeps what matters and drops the rest. The friend can then draw something close.

An embedding is such a description, written as a list of numbers. A trained image network reads a picture and outputs the list. Pictures with similar content get similar lists. The network is trained so that this is true.

CLIP in plain words

CLIP is a pair of networks, one for images and one for captions, trained on hundreds of millions of image and caption pairs. Training pulls the list of a photo toward the list of its caption and pushes it away from other captions. After training, a photo of a cat and the words “a cat” land close together.

MindEye2 uses OpenCLIP ViT-bigG/14, a large open copy of this idea. “ViT” means vision transformer, which cuts an image into patches. “14” is the patch size in pixels. The paper keeps this network frozen: it is never changed, only used to measure images.

The shape of the target

A simple embedding is one list for the whole image. MindEye2 predicts more. It predicts one list per image patch: (256, 1664), which is 256 patches with 1,664 numbers each, or 425,984 numbers. For comparison, MindEye1 used CLIP ViT-L/14, with shape (257, 1024).

Where does 256 come from? A 224 by 224 image cut into 14-pixel patches gives 16 × 16 = 256 patches. That input size is the usual one for this network; the paper itself only says 256 patch tokens.

The last step of the brain network is a linear layer from 4,096 numbers to those 425,984. By arithmetic, that one layer has about 1.74 billion weights. The paper trains on a node of eight A100 GPUs, with DeepSpeed Stage 2 and CPU offloading.

Why the bigger target pays off

The paper tests the target directly in Appendix A.6. It feeds the true bigG embedding of a photo into its image generator. The result is a near copy of the photo. So the 256 × 1664 list holds the layout and colours as well as the meaning. Versatile Diffusion with CLIP-L embeddings does worse: FID 22.04 against 13.69, PixCorr 0.266 against 0.676 (lower FID is better).

Table 4 repeats the idea inside the brain model. With the target switched to CLIP-L, PixCorr falls from 0.292 to 0.243 and image retrieval from 97.4% to 89.6%. A richer target gives the brain model more to aim at.

Comparing two embeddings

To ask whether two lists are alike, the field uses cosine similarity: the cosine of the angle between the two lists drawn as arrows. It equals 1 for the same direction, 0 for a right angle and −1 for opposite.

cos(a, b)
The similarity score between lists a and b, from −1 to 1.
a · b
The dot product: multiply the lists number by number, then add.
‖a‖ ‖b‖
The lengths of the two arrows multiplied. Dividing by them removes size and keeps direction.

Illustrative: a = (3, 4), b = (4, 3) → a · b = 12 + 12 = 24; ‖a‖ = ‖b‖ = 5 → cos = 24 / 25 = 0.96

Aim the prediction

Blue dots are image embeddings, here squashed to 2 numbers. The warm dot is what the brain model predicted. Drag it. The nearest direction is the retrieved image.

Illustrative: real embeddings have 425,984 numbers, not 2. Image names are made up to show that neighbours share content. Only the cosine rule is the paper’s.

Drag the dot across a gap between two neighbours. The retrieved image flips at the line where the two cosines are equal. A prediction that points between “cat” and “zebra” may pick either. The picture generator in Chapter 7 faces the same blur.

Why not predict a label or a caption instead?

A label such as “zebra” keeps almost none of the picture: not the pose, the colours or the place. A caption keeps more but still drops the layout. The embedding keeps the most of the three, and a generator trained on real embeddings knows how to turn one back into pixels.

The embedding also gives the model a smooth target. If the brain scan is only partly clear, the prediction lands near the true embedding, and the picture comes out as a near neighbour of the seen photo. A label would give a hard right-or-wrong answer instead. For scans this noisy, the smooth target is the kinder one.

One honest caution comes from Appendix A.8. When the authors searched a large pool of images that did not contain the true one, the nearest neighbours from bigG latents were often unrelated in meaning and look. They suggest CLIP-L latents would suit that task better. A target that is best for drawing is not automatically best for searching.

What does the brain network of MindEye2 output before any picture exists?

Chapter 5

Retrieval and Contrastive Learning

Train the brain latent to point at its own image and away from the other images in the batch

A teacher hands out eight photos and eight sealed notes, each describing one photo. You must match them. A good student does not need to draw anything. She only needs to feel which note fits which photo best.

This matching game trains one part of MindEye2. It is the retrieval submodule. Given a brain scan, it finds the right image out of a pool. It is also a good test of the whole idea: if a brain latent can find the right photo among 300, it holds fine detail about that photo.

Why a separate branch is needed

The model has two goals. The diffusion prior (Chapter 6) wants its output to match the CLIP target by mean squared error (MSE). Retrieval wants a latent that ranks the right image first. MindEye1 found these goals fight each other if they share one output: the model “could not effectively learn a single embedding to satisfy both objectives”.

The fix is to give each goal its own output. A small MLP projector hangs off the backbone and feeds only the contrastive loss. The prior gets only the MSE loss. They share the backbone but not the final embedding.

The contrastive loss, derived

Take a batch of N pairs: brain latent bi and the CLIP embedding ci of the image that caused it. Compute the cosine between every brain and every image. That gives an N × N table. The right match is the diagonal.

Divide each cosine by a temperature τ so differences are sharper. Turn row i into probabilities with a softmax: raise e to each score, then divide by the row total, so the row sums to 1. The loss for row i is the negative log of the probability on the diagonal. This is the InfoNCE loss.

L
The loss. Small when each brain latent puts most probability on its own image.
sii
The score of the right pair, brain i with image i.
sij
The score of brain i with image j, right or wrong.
τ
The temperature. A small τ makes the softmax sharper. The paper does not list its value in the main text.

Illustrative, one row: cosines (0.8, 0.2, 0.1), τ = 0.5 → s = (1.6, 0.4, 0.2) → exp = (4.95, 1.49, 1.22), sum 7.67 → pright = 0.646 → loss = −ln 0.646 = 0.44

Match the eight pairs

Rows are brain latents and columns are images. Brighter cells get more probability. The outlined diagonal is the right match. Raise the noise until matches fail, then try soft labels.

0.8
0.30

Illustrative toy: 8 unit vectors in 16 numbers, images 0 and 1 and images 4 and 5 are made similar on purpose, and each brain latent is its image plus Gaussian noise. The loss is computed live from the formula above. The paper’s own batches and τ differ.

With no noise every diagonal cell is bright and the loss is small. Add noise and the diagonal fades. Matches fail first between the similar pairs, as they should: a surfer latent drifts toward the sailboat photo before it drifts toward a bus.

BiMixCo and SoftCLIP

MindEye2 inherits two tricks from MindEye1. For the first third of training it uses BiMixCo: it mixes two brain samples into a blend (MixCo, a data augmentation) and trains the blend to match both images in proportion. “Bidirectional” means the same mixing is applied from the image side too. It adds variety when data are scarce.

For the last two thirds it uses SoftCLIP, with no augmentation. The target is no longer one-hot. It is a soft table made from the dot products between the batch’s CLIP image embeddings. Two photos of zebras then share credit. The device’s second mode shows this.

How retrieval is scored

For the test, pick one brain sample and 299 random others, making 300 candidates. Score cosine against the true image embedding. The sample is a hit if the right one scores highest. Chance is 1 in 300, or 0.3%. The paper repeats this 30 times to average out the random draws.

MindEye2 with all 40 sessions reaches 98.8% image retrieval and 98.3% brain retrieval in Table 1. MindEye1 reaches 90.0% and 84.1%. With only 1 hour, MindEye2 still reaches 79.0% and 57.4%. Appendix A.8 adds a caution: in a huge pool without the true image, bigG latents retrieve less semantically close neighbours than CLIP-L latents.

The two directions of retrieval

The table in the device can be read two ways. Read along a row: given one brain, which image fits best? The paper calls this image retrieval (forward). Read down a column: given one image, which brain scan fits best? This is brain retrieval (backward). Table 1 reports both. For MindEye2 trained on 1 hour, brain retrieval is 57.4%, lower than image retrieval at 79.0%.

Now the failure mode. Suppose the temperature is too small. The softmax becomes spiky, and one lucky wrong image can take almost all the probability. The symptom is a loss that jumps between batches. The measurement is a retrieval score that stays flat while the loss moves. The fix is to raise τ or to use soft labels so that near-duplicates are not punished as hard errors. This matters here because the test set holds many similar images, for example 14 zebras, so the model must pick the exact image and not just the topic.

Why does the retrieval submodule get its own projector instead of reading the diffusion prior’s output?

Chapter 6

The Diffusion Prior, the Low-Level Branch, and One Loss

Close the gap between a brain latent and a real CLIP embedding, keep the colours and layout, and train all three outputs at once

You trace a drawing from memory. Your tracing gets the story right but lands a little off the page: shifted, a bit small. A good editor does not redraw it. She nudges it back onto the page, step by step, until it sits where a real drawing would.

The brain model has the same problem. Its latent lives near the CLIP embeddings of real images but not on them. The picture generator was trained on real embeddings. A latent that sits off the page produces warped pictures. The diffusion prior is the editor.

Why a contrastive latent is off the page

Contrastive training puts both kinds of data, brain and image, into a shared space. The paper cites the “modality gap”: each kind squeezes into its own narrow cone. Two latents can rank images correctly and still sit far apart in distance. Ranking needs direction. Generation needs position.

Appendix A.10 measures this. Over 1,000 test samples of subject 1 with the full 40-session model, the average Euclidean distance to the true CLIP image latent was 4.83 for the backbone output, 3.83 for the retrieval submodule and 0.41 for the diffusion prior. The prior removes nearly all the gap.

Nudge it onto the page

Blue dots are true CLIP image latents. Purple dots are predicted latents. Each line joins a prediction to the image it should match. Switch the source of the latents.

The three average distances (4.83, 3.83, 0.41) are the paper’s Appendix A.10, measured in the real 425,984-number space. The 2D points and the direction of the shift are illustrative: offsets were scaled so the average line length equals the paper’s number.

How a diffusion prior works

Diffusion models learn to undo noise. Take a true embedding z and mix in random noise ε to get a noisy version. The model sees the noisy list, a time step, and a condition, and it guesses the clean list. Repeat the guess a few times, each time with less noise, and it lands on a clean embedding.

zt = √(ᾱt) z + √(1 − ᾱt) ε    loss = ‖ ẑ − z ‖2

Here ᾱt says how much of the clean signal is left at step t. It runs from near 1 (clean) to near 0 (pure noise). ẑ is the guess. This is the loss of DALL-E 2’s prior (Ramesh et al.), and MindEye2 reuses that code. The condition is the backbone’s output.

Illustrative: z = (1.0, 0.0), ᾱ = 0.64, ε = (0.5, −1.0) → zt = 0.8 z + 0.6 ε = (1.10, −0.60); if the guess is (0.9, 0.1) the loss is 0.01 + 0.01 = 0.02

Shapes: the prior takes noisy (256, 1664) and the backbone output (256, 1664), and returns a clean (256, 1664). The paper trains it from scratch and keeps OpenCLIP bigG frozen, as in locked-image tuning. Only the brain side learns.

The low-level submodule

CLIP embeddings carry meaning well and exact colours poorly. MindEye1 trained a separate model for the blurry, low-level version of the picture. MindEye2 folds this into the main network as a second branch.

A small MLP projector feeds a CNN upsampler. The output has shape (64, 64, 4), the size of a Stable Diffusion VAE latent. The loss is the L1 distance (the average absolute difference) to the true VAE latent. A second MLP also predicts the embedding of a teacher network, VICRegL ConvNext-XXL, with a SoftCLIP loss.

Llowlevel = (1/N) Σi |VAEi − VAÊi| + LSoftCLIP(VIC, VIĈ)

One loss for three outputs

The three branches share the backbone. Their losses add up, with small weights on the two extra ones.

L = Lprior + 0.033 · LBiMixCo|SoftCLIP + 0.016 · Llowlevel

The weights α1 = 0.033 and α2 = 0.016 are from the paper. They keep the two helper losses from drowning the prior. Chapter 8 shows that the helpers also help the prior: removing both made reconstruction metrics worst.

A worked look at the conflict, and what the helpers add

Why can one embedding not serve both losses? Imagine two brain latents whose true embeddings point in nearly the same direction but sit at different distances from the origin. The contrastive loss only cares about direction, so it is happy to leave them close. The mean squared error cares about the exact numbers, so it wants them apart. One output cannot please both. Two outputs can.

The helpers also teach the backbone. Table 5 shows reconstruction with the prior alone: PixCorr 0.155 and SSIM 0.309. Add the low-level branch and PixCorr jumps to 0.281. Add retrieval instead and Alex(2) reaches 90.6%. All three together give PixCorr 0.267 and the best retrieval, 98.0%. The authors read this as multiple objectives being “mutually beneficial”.

Finally, note what is trained from scratch: the prior. Only the OpenCLIP bigG target network is frozen, in the style of locked-image text tuning (LiT). The prior is trained from scratch, with code adapted from the DALLE2-pytorch repository.

The backbone output ranks images correctly but is 4.83 away from the true CLIP latent. What fixes the distance?

Chapter 7

From Embedding to Pixels

Turn the predicted CLIP embedding into a picture with a retuned SDXL, then clean the picture up with a predicted caption

A sketch artist gets a witness’s description. She draws a first version fast. It has the right idea but one eye sits wrong and the nose is odd. Then a second artist, who knows what faces look like, repaints the sketch with a one-line note: “a man in a hat”. The result looks like a person.

MindEye2 works in these two steps. A model named SDXL unCLIP makes the first picture from the embedding. Base Stable Diffusion XL (SDXL) repaints it with a caption. Both are image generators trained by others. Only the first is retuned.

Step 1: SDXL unCLIP

Normal SDXL is steered by text. An unCLIP model is steered by a CLIP image embedding instead. Give it the embedding of a photo and it returns a variation of that photo. Earlier unCLIP models kept the meaning but lost the layout. MindEye2 needs the opposite: the same image back, at the pixel level.

So the authors fine-tuned SDXL. They replaced the text conditioning in its cross-attention layers with all 256 patch tokens of the bigG image embedding. Cross-attention lets each image region look at the conditioning list and pull in what it needs. They also dropped the pooled text embedding.

They report that adding any text conditioning made the reconstructions worse. They trained 110,000 steps at 256 × 256 pixels, batch size 8, with offset noise 0.04, on an internal image set. Best outputs came at 768 × 768. The model still starts from pure noise, like the base model, and not from a reference image.

Appendix A.6 checks this stage alone. Fed the true bigG embedding, SDXL unCLIP returns an image with PixCorr 0.676 and CLIP identification 0.999. Versatile Diffusion, fed CLIP-L, scores 0.266 and 0.997. The paper calls the results nearly identical to the originals. This tells us any later distortion comes from the brain prediction, not the generator.

Step 2: refine with a caption

Brain-predicted embeddings are imperfect. The unCLIP picture can look distorted: right content, warped shapes. The paper calls this the “unrefined” reconstruction. To improve realism the authors feed it to base SDXL in image-to-image mode.

Image-to-image does not start from pure noise. It adds noise to the unrefined picture and denoises from there. MindEye2 skips the first 50% of the denoising time steps. That keeps the coarse layout and lets the generator fix local detail. The guide text is a caption predicted from the brain.

Pick the output stage

The top row is the reconstruction path. Choose which output to score. The bars are the paper’s Table 1 scores for it, all from 0 to 1, higher is better.

Scores are Table 1 of the paper (full 40 sessions, average of subjects 1, 2, 5 and 7). PixCorr and SSIM are on a 0 to 1 scale; the other four are two-way identification accuracies shown as fractions of 1.

Look at the bars. The unrefined output scores higher than the refined on most of the high-level tests, for example CLIP 94.5% against 93.0%. The refined output wins on Alex(2), 96.1% against 95.2%. Yet people prefer the refined picture. In the paper’s online test, 71.94% of judgments chose the refined one as closer to the truth. The authors take this as a warning that the usual metrics may not match human views.

The caption path

The caption comes from the same prior output. A small linear model converts bigG embeddings into CLIP ViT-L/14 embeddings. This is needed because the pretrained captioner, GIT (GenerativeImage2Text), accepts only CLIP-L inputs. The authors trained it with ground-truth COCO images. GIT then writes text such as “a cat sitting on a table”.

The conversion is two linear layers, one acting over the 256 tokens and one over the 1,664 numbers, in a few lines of PyTorch. Appendix A.12 tests the benefit. With the predicted caption, Alex(2) is 88.02% against 87.46% for an empty prompt. CLIP identification is 80.75% against 81.21%, so the empty prompt wins there. The authors call the gain modest.

Blending in the low-level image

The last step averages the refined picture with the low-level branch output, pixel by pixel, at a ratio of 4 parts refined to 1 part low-level. This raises low-level scores such as PixCorr. The paper says it is not critical and can be dropped without a visible loss.

At inference the frozen models are SDXL unCLIP, base SDXL and GIT, plus the small bigG to CLIP-L map. The trained brain network is the only part that depends on the person, and within it only the first layer is private.

When the picture goes wrong

The most common failure is the confident wrong picture. The brain prediction points at the wrong object, and the refinement step then makes the wrong object look real. The symptom is a clean, natural image of the wrong thing. The paper saw this in its human test: raters sometimes preferred a distorted Brain Diffuser image that contained subtle correct features over a clean MindEye2 image that was confidently wrong.

The authors do not pick the best of many samples. They take the first sample from each stochastic model, with no second-order selection. This matters when you read the pictures: they are not cherry-picked by a score. A different seed would give a slightly different picture of the same scene.

Why does MindEye2 fine-tune SDXL to take image embeddings instead of using an existing unCLIP model?

Chapter 8

What the Tables Show, and What They Do Not

Read the main results, the ablations and the limits, and learn which scores to trust

A student shows you a test score of 92. Before you cheer, you ask: out of what, on which test, against whom, and does the score match how the answers look? This chapter asks those four questions of every MindEye2 table.

The test and the scores

All results use the 1,000 shared NSD images as the test set, averaged over the 4 subjects who finished all 40 sessions (subjects 1, 2, 5 and 7). Training photos never appear in the test.

The scores come in three groups. Low-level scores ask if pixels match: PixCorr is the pixel-by-pixel correlation and SSIM measures local structure. High-level scores ask if the meaning matches. They use two-way identification: given the true image and a random one, is the reconstruction closer to the true one, judged by features of AlexNet, Inception or CLIP? Chance is 50%. EfficientNet and SwAV report a correlation distance, where lower is better. Retrieval is the 300-candidate test of Chapter 5.

Table 1: the full-data comparison

With all 40 sessions, MindEye2 leads on nearly every metric. PixCorr is 0.322 against 0.319 for MindEye1, SSIM 0.431 against 0.360, and image retrieval 98.8% against 90.0%. Brain Diffuser retrieves the right image only 18.8% of the time. MindEye1 is slightly ahead on CLIP two-way identification: 93.3% against 93.0%.

The one-hour model trades quality for time. Its PixCorr is 0.195 and its image retrieval is 79.0%. Against the 40-hour method of Takagi and Nishimoto it wins on Alex(2) (84.2% against 78.9%) and Alex(5) (90.6% against 85.6%), and it retrieves far better than Brain Diffuser’s 18.8%. It loses to both 40-hour methods on PixCorr. Use the device to see these rows.

Read the tables

Choose a table, then a metric. Bars run from 0 to 1. The green bar is the best value in that table. Gaps show “n/a” where the paper reports no value.

All values are typed from the paper. Table 1 is the full 40-session setting except the last row (1 hour). Tables 4 and 5 are small models trained from scratch on 10 sessions of subject 1, without refinement. Table 10 is subject 1, 1 hour, with different pretraining subjects. Image and brain retrieval are 300-way.

The data curve and a failure mode

Figure 5 plots quality against training time for pretrained and non-pretrained models. Both improve with data, and the two curves grow more alike as data are added. The gap is largest when data are scarce. For non-pretrained models trained on 10 or 30 minutes, the paper reports instability, perhaps “mode collapse”, where the output is the same whatever the input.

That is the symptom. The measurement is odd: those collapsed outputs scored well on SSIM. So SSIM alone cannot find the failure. The fix is pretraining on other subjects, which keeps the model stable at 10 and 30 minutes.

Brain correlation, captions, and human raters

The paper adds a test with no ground-truth pixels. Feed the reconstruction to an encoding model, which predicts brain activity from an image, and compare with the real scan. In visual cortex, MindEye2 scores 0.373, the unrefined version 0.384, the one-hour model 0.348, Brain Diffuser 0.381 and Takagi and Nishimoto 0.247 (Table 3). Unrefined wins again.

For captions (Table 2), MindEye2 beats Ferrante et al. on GIT captions: METEOR 0.344 against 0.305 and sentence similarity 52.3% against 44.7%. Against UniBrain on COCO captions it wins every metric UniBrain reports except CLIP-L, where UniBrain scores 86.1% and MindEye2 63.8%.

The human tests used 58 raters on Prolific. They picked the true reconstruction over a random one 97.82% of the time. They chose refined over unrefined 71.94% of the time. For the one-hour setting, MindEye2 beat Brain Diffuser 53.01% of the time (p = 0.044). The win is real but small. Raters sometimes preferred a distorted Brain Diffuser image over a “confidently wrong” naturalistic MindEye2 image.

Ablations: where the gains come from

Table 6 shows MindEye2 beats MindEye1 even with no pretraining, both trained on all 40 sessions of subject 1. Retrieval jumps to 100% against 95.0% forward and 99.7% against 89.4% backward. MindEye1 stays ahead on PixCorr (0.388 against 0.376) and CLIP (93.7% against 92.6%).

Table 4 isolates two changes: the linear first layer and the bigG target. Table 5 asks which loss terms matter. Without the retrieval and low-level branches reconstruction is worst: PixCorr 0.155 against 0.267 with all three. The helpers are not baggage. They teach the backbone things the prior alone does not.

Limits the authors state

fMRI is sensitive to movement. A small head turn or thinking about something else resists decoding. The model has been shown only on natural scenes like COCO. Metrics sometimes disagree with human taste. The authors also call for care: brain data must be protected and companies must say how they use it.

How to read a score you did not run

Three habits help. First, ask what the baseline is. Chance for the two-way tests is 50%, so 79% means something very different from 99%. Second, look at the variation between subjects: Tables 7 and 8 list each subject, and image retrieval for the one-hour model ranges from 93.96% for subject 1 down to 64.44% for subject 7. Third, ask which direction the metric runs, since EfficientNet and SwAV are better when lower.

Non-pretrained models on 10 minutes of data scored well on SSIM but produced near-identical outputs for any input. What does this teach?

Chapter 9

Field Guide

Keep the numbers, the terms, the checklist and the core code, and find where to read next

MindEye2 gives each person a private linear layer from voxels to a shared 4,096-number space. One shared network, pretrained on seven people and fine-tuned on one hour of an eighth, predicts a CLIP embedding. A diffusion prior cleans it. SDXL unCLIP draws it. A caption-guided refinement polishes it.

The numbers

QuantityValueWhere
Voxels per subject12,682 to 17,907Figure 2
Trials per session750 images, 3 s eachSection 3
Full training set40 sessions, 30,000 trials; 1,000 testSection 3
One hourfirst session, 2.5% of the dataSections 1 and 3
Shared latent4,096 numbersSection 2.1
Target embedding256 × 1664 (OpenCLIP ViT-bigG/14)Section 2.2
Pretraining batch63 = 9 samples × 7 subjectsSection 2
Loss weightsα1 = 0.033, α2 = 0.016Equation 1
Distance to true latent4.83 backbone, 3.83 retrieval, 0.41 priorFigure 10
Refinementskip 50% of steps; blend 4 : 1Section 2.5
Image retrieval98.8% (40 h), 79.0% (1 h), chance 0.3%Table 1
Human raters97.82% true match; 71.94% refined; 53.01% vs Brain DiffuserAppendix A.15

The terms

The checklist

The core as code

This is a sketch of the data flow, written for this lesson. It is not the authors’ code, which they released on GitHub (see the paper).

# one training step; batch holds 9 trials from each of 7 subjects
def train_step(batch, model):
    lat = []
    for s, (vox, img_emb, vae) in batch.items():          # vox: (9, V_s)
        lat.append(model.align[s](vox))                 # (9, 4096), private linear layer
    z = torch.cat(lat)                                  # (63, 4096), common language
    h = model.backbone(z)                               # 4 residual blocks
    clip = model.to_clip(h).view(-1, 256, 1664)       # bigG-shaped target
    l_prior = model.prior.loss(clip, cond=h, target=img_emb)       # MSE on denoised guess
    l_ret   = bimixco_or_softclip(model.retrieval(h), img_emb)
    l_low   = (model.low(h) - vae).abs().mean() + softclip(model.vic(h), vic_emb)
    return l_prior + 0.033 * l_ret + 0.016 * l_low

# inference for a new scan
def reconstruct(vox, s):
    h = model.backbone(model.align[s](vox))
    emb = model.prior.sample(cond=h)                    # (256, 1664)
    rough = sdxl_unclip(emb)                            # unrefined image
    cap = git(bigG_to_L(emb))                           # predicted caption
    fine = sdxl_img2img(rough, cap, skip=0.5)
    return 0.8 * fine + 0.2 * model.low_image(h)       # 4 : 1 blend

Where it sits, and where to go next

MindEye2 is a lecture reading for LLMs and the Language Brain. The linear decoder idea is the same one in Linear Decoders. The shared-space idea echoes the latent models of PCA and ICA. Contrastive embeddings are in Contrastive Learning and CLIP, and generators are in Diffusion and VAE and VQ-VAE. For neural decoders that read speech and movement, see the speech neuroprosthesis and NDT2 and NDT3.

The authors say the method may reach clinics and brain-computer interfaces if adapted to real-time analysis or to other imaging than fMRI. That is their hope, not a result.

The takeaway. A new person does not need their own 40-hour model. A private linear layer lets a shared network read their brain, and a frozen generator draws what the network predicts.

Read the source: MindEye2 on arXiv (Scotti, Tripathy, Torrico Villanueva, Kneeland, Chen, Narang, Santhirasegaran, Xu, Naselaris, Norman, Abraham; ICML 2024, PMLR 235). Press Teach to explain it back on a whiteboard, or go back to the hero and run the 300 lookups again.

MindEye2: Shared-Subject Models Enable fMRI-To-Image With 1 Hour of Data
Read the paper · The lecture it belongs to · Back to Gleams