Skip to content
King Jin

1 September 2026

Masked Autoencoders (MAE)

Recently, I went through the MAE paper (Masked Autoencoders Are Scalable Vision Learners) line by line, with the help of a Chinese paper-reading video. The idea sounds very simple: hide most of an image and ask the model to paint it back. But there are a few design choices behind it that I kept getting wrong, so today I want to write them down properly.

What problem MAE solves

Supervised vision training needs labels: a class name like dog, a bounding box, or a segmentation mask. Labels are expensive, but raw images are everywhere. Self-supervised learning makes the target from the input itself:

partial image⟶predict the missing content\text{partial image}\longrightarrow\text{predict the missing content}

The first idea is to copy BERT: hide a few patches and predict them. The problem is that images and text are very different. A missing word carries a lot of meaning, while a missing image patch can often be guessed from the colours and textures next to it. If we only hide a little, the model can solve the task locally and never learns about objects or scenes.

MAE fixes this with two decisions:

  1. High random masking: remove about 75% of the patches, so copying nearby pixels is not enough.
  2. Asymmetric encoder and decoder: the big encoder only sees the visible patches, and a small decoder handles the full sequence.

So the high mask ratio does two jobs at once. It makes the task harder, and it makes pretraining cheaper.

How it works

The whole method is a corrupt, encode, reconstruct pipeline:

  1. Split a 224 × 224 × 3 image into 196 patches of 16 × 16 × 3.
  2. Randomly remove 75% of them, so 49 patches stay visible and 147 are masked.
  3. Run the ViT encoder on the 49 visible patches only.
  4. Put the encoded tokens back in their original order and fill every missing position with a learned mask token.
  5. Run a small Transformer decoder over all 196 positions.
  6. Predict the missing pixels and compute the loss on the masked patches only.
  7. After pretraining, keep the encoder and throw the decoder away.

1. Turn the image into patches

This part comes from Vision Transformer. For an image of height HH, width WW, CC channels and patch size PP:

N=HWP2=224×224162=196N=\frac{HW}{P^2}=\frac{224\times224}{16^2}=196

Each flattened patch has P2C=16×16×3=768P^2C=16\times16\times3=768 values. A shared linear layer maps every patch into the encoder's hidden size, and a positional embedding tells the model where the patch came from.

2. Remove most of the patches

The masked patches are removed before the encoder. They are not replaced with black pixels, and no [MASK] token goes into the encoder. This saves the encoder's compute, and it also avoids a mismatch: at downstream time the encoder never sees mask tokens, so it should not see them during pretraining either.

Random masking works better than hiding one big block, because the visible patches stay spread across the whole image. The encoder gets small pieces of evidence from many places and has to connect them.

3. Encode only the visible patches

hV=Eθ(xV+pV)h_{\mathcal V}=E_\theta(x_{\mathcal V}+p_{\mathcal V})

V\mathcal V is the set of visible patches, xVx_{\mathcal V} are their embeddings, pVp_{\mathcal V} are their positions. Seeing 25% of the tokens does not make everything exactly 4× cheaper, because the decoder and other overhead are still there. In the paper the full design was still at least 3× faster than running the encoder on every token.

4. Add mask tokens and decode

The decoder needs a token at every position, so MAE inserts the same learned mask vector at every missing spot and adds positional embeddings. The decoder is narrower and shallower than the encoder:

PartSeesJobKept after pretraining?
Large ViT encoderVisible patches onlyLearn useful visual featuresYes
Small decoderVisible tokens plus mask tokensRebuild the pixelsNo

Because the decoder does the low-level painting, the encoder does not have to remember every pixel detail.

5. Loss only on the hidden patches

For each patch, the last layer predicts 768 values (not 256, because RGB has 3 channels). With M\mathcal M as the masked set:

LMAE=1∣M∣∑i∈M∥x^i−norm⁡(xi)∥22\mathcal L_{MAE}=\frac{1}{|\mathcal M|}\sum_{i\in\mathcal M}\left\|\hat{x}_i-\operatorname{norm}(x_i)\right\|_2^2

The target can be raw pixels or pixels normalised inside each patch. The normalised version gave better features in the paper. The visible patches are not scored, because copying what the model already sees teaches it nothing.

Why 75% works

With a low mask ratio, the neighbours of a missing patch show almost the same edges and colours, so the model can just interpolate. With 75% hidden, many neighbours are gone too, and the model needs bigger clues: object shape, how parts fit together, the layout of the scene.

The paper found roughly 40% to 80% works well for fine-tuning, with 75% as the default.

Pretraining vs using it

MAE is a pretraining recipe. When you actually use the model, you:

  1. Throw away the decoder.
  2. Feed the full, unmasked image into the encoder.
  3. Add a task head and fine-tune for classification, detection or segmentation.

Nothing is masked at normal inference time. The reconstruction task is just scaffolding to shape the encoder.

MAE vs BERT

BERTMAE
Input unitText tokenImage patch
Mask ratioAbout 15%About 75%
WhyWords are dense with meaningImages are very redundant
Encoder inputSequence with mask tokensVisible patches only
TargetToken idPixel values

What the experiments showed

  • On ImageNet-1K, MAE-pretrained ViT-B/L/H reached 83.6%, 85.9% and 86.9% top-1 after fine-tuning, and ViT-H reached 87.8% at 448 × 448, using only ImageNet-1K data.
  • Bigger models gained more from MAE than from supervised training from scratch.
  • It transferred better than supervised pretraining to COCO detection and ADE20K segmentation.
  • A small decoder was enough. Putting mask tokens through the big encoder was slower and slightly worse.

Things I got confused about

  • Mask tokens only appear after the encoder, at the decoder input.
  • MAE does not use labels during pretraining. Labels only come in for fine-tuning.
  • A nice reconstruction is not the goal. The useful output is the encoder.
  • A 16 × 16 RGB patch has 768 values, not 256.

My mental model

I think of MAE as giving a student a few scattered puzzle pieces and asking what the scene is, while a cheap assistant fills in the rest of the picture. If I show too many pieces, the student just copies the colours next to the gaps. If I hide 75%, the student has to understand the whole scene. After practice the assistant goes home, and what stays is the student's better eye.

The key idea is to put the pressure to understand on the encoder, and push the boring pixel work into a decoder you throw away.

References

OlderVision Transformer →