Back to paper library
arXiv 2021CVPR 2022Vision TransformersPaper notes

MAE

A Quarter of the Clue

Original paper

Masked Autoencoders Are Scalable Vision Learners

Paper authors

Kaiming He · Xinlei Chen · Saining Xie · Yanghao Li · Piotr Dollár · Ross Girshick

Publication
CVPR 2022Conference
First submitted to arXiv
arXiv:2111.06377
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{visiontransformersmae2021,
  title = {{Masked Autoencoders Are Scalable Vision Learners}},
  author = {Kaiming He and Xinlei Chen and Saining Xie and Yanghao Li and Piotr Dollár and Ross Girshick},
  year = {2021},
  eprint = {2111.06377},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2111.06377}
}
On this page

In NLP, masked language modeling has become one of the best-known pretraining tasks: hide about 15% of the text tokens and ask the model to fill them in. This classic recipe gave us models such as BERT, RoBERTa, and ALBERT.

What about images?

Why has vision not had a similarly successful pretraining method?

Define the problem

ViT had already tried something similar. In that paper, the authors masked part of an image and tried predicting the missing content, including pixel and region-level targets; see our ViT note.

The verdict in those experiments: neither approach worked as well as supervised pretraining.


The MAE authors point to a central difference: language and vision have different information densities. Language is made by people and carries explicit semantic units. Images have plenty of spatial redundancy, so a model can restore a few missing patches from nearby ones without working hard to understand parts, objects, or scenes.

It can just interpolate from its neighbors. No wonder the result might disappoint.

Solve the problem

To get around that difference, the authors simply hide most of the patches. How many? Oh, just 75%!

Give the encoder only visible patches

Figure 1 shows the data flow. As in ViT, the image is first split into patches. The patches to hide are sampled at random to avoid a center bias. Masked patches are removed before the encoder, leaving it only the visible quarter. The decoder later inserts mask tokens and reconstructs the image at the original patch positions.

Source: paper Figure 1. This lets a large encoder process a much smaller token sequence during pretraining. For downstream inference, remove the masks and discard the decoder, leaving the encoder to process a complete image. The smaller encoder input saves compute; it does not reduce the size of the training dataset. Masked patches skip the encoder input, but the encoder still receives gradients through the decoder's reconstruction loss.

In implementation, patches become tokens with positional information. The tokens are shuffled, and only the visible quarter goes into the encoder. The decoder gets encoded visible tokens, shared learned mask tokens that contain none of the missing pixels, and positional embeddings, then restores their original order. No special sparse operator is needed.

Reconstruction target and loss

MAE reconstructs the input by predicting the pixel values of each masked patch. For an RGB patch of side length PP, the decoder's final projection outputs P2×3P^2\times3 pixel values. The default objective is pixel mean squared error (MSE), computed only at masked positions, rather than over the whole image. The decoder also emits values for visible positions, but this loss does not constrain them. A blurry visible region in the reconstruction is therefore a different issue from a wrong masked region.

The authors even give us plenty of pictures to make this easier to follow. In paper Figure 2, each triplet shows the masked input on the left, the decoder's reconstruction in the middle, and the original image on the right. These qualitative examples use 80% masking, rather than the 75% default in the ablations below.

Source: paper Figure 2. Downstream evaluation is stronger evidence.

Experimental results and discussion

Most ablations below use ViT-L/16, ImageNet-1K, and 800 pretraining epochs. In the tables, ft means end-to-end encoder fine-tuning, while lin freezes the encoder and trains a linear classifier. Keep the two protocols separate.

Establish the baseline first

The original ViT recipe trained ViT-L/16 from scratch to 76.5% top-1 accuracy. The MAE authors' improved supervised training recipe reached 82.5%. MAE pretraining followed by fine-tuning reached 84.9%. Those first two numbers matter: a strong supervised baseline makes the pretraining gain easier to see.

Source: paper Section 4, Baseline: ViT-Large. MAE still adds 2.4 percentage points over the authors' strong supervised baseline—almost absurdly good. The entire 76.5-to-84.9 gap, however, is not attributable to masking.

Why 75% masking?

The top panel of paper Figure 5 shows full fine-tuning and the bottom panel shows linear probing. Fine-tuning remains fairly stable at about 40–80% masking. Linear probing improves up to 73.5% at 75% masking, then falls. The 75% default balances representation quality and compute in these tests; it is not a rule that more masking always helps.

Source: paper Figure 5. Both vertical axes report ImageNet-1K validation accuracy, but the levels and trends differ between protocols.

Paper Table 1(c) compares an encoder that receives mask tokens. Its linear-probe accuracy falls from 73.5% to 59.6%, a 13.9-point difference; full fine-tuning moves from 84.9% to 84.2%, only 0.7 point. The authors propose a pretraining-to-downstream input mismatch as one explanation, since downstream images have no mask tokens. The compute saving from fewer encoder tokens is more direct.

The decoder need not match the encoder's weight

Paper Table 1(a)(b) tests decoder depth and width. An eight-block decoder has the best linear-probe result, 73.5%, but depths two, four, and eight all reach 84.9% after full fine-tuning. Width 512 is the default and half the ViT-L encoder's 1024 dimensions. It works well here; a half-width decoder is not a universal rule.

Source: paper Table 1(a)(b). Linear-probe and fine-tuned results require separate comparison.

Pixels or tokens as targets?

Paper Table 1(d) gives fine-tuning/linear-probe accuracy for four targets: raw pixels 84.9/73.5, per-patch normalized pixels 85.4/73.9, PCA 84.6/72.3, and dVAE tokens 85.3/71.6. dVAE beats raw pixels after full fine-tuning but trails normalized pixels and needs an extra pretrained tokenizer. Thus, “every alternative is worse than raw pixels” misreads the table.

Source: paper Table 1(d). The default ablation uses raw pixels; the later 1600-epoch ImageNet comparison uses normalized pixels. Check which setting a number belongs to.

The retained augmentations

In paper Table 1(e), random resized cropping with horizontal flipping scores 84.9/73.5; fixed-size crop with flip 84.7/73.1; center crop without random augmentation 84.0/65.7; adding color jitter 84.3/71.9. There is no random-rotation ablation. MAE depends less on augmentation than some alternatives, but its default still crops and flips images.

Source: paper Table 1(e). The authors compare augmentation dependence with SimCLR and BYOL. BYOL has no explicit negative pairs, so it should not be described as a conventional contrastive loss.

Mask shape changes the task

In paper Table 1(f), random 75% masking reaches 84.9/73.5; block masking at 50% reaches 83.9/72.3, and at 75% drops to 82.8/63.9; grid masking at 75% gives 84.0/66.0. Block masks are harder to reconstruct, while grid masks are easier. A sharper reconstruction does not necessarily yield better recognition features.

Source: paper Table 1(f). Paper Figure 6 then shows random 75%, block 50%, and grid 75% examples. Their different ratios matter to the visual comparison.
Source: paper Figure 6. Random masking combined high masking and stronger downstream accuracy among these tested settings.

Read accuracy with training time

Paper Table 3 uses 1600 epochs and normalized pixels. MAE reaches 83.6% with ViT-B, 85.9% with ViT-L, and 86.9% with ViT-H at 224-pixel input. The 87.8% ViT-H result follows fine-tuning at 448 pixels, not merely enlarging a test image. At publication time, the authors report this above a previous 87.1% result among methods using only ImageNet-1K; that comparison has both a date and a data condition.

Source: paper Table 3. BEiT's pretraining-data column says IN1K+DALLE because its dVAE tokenizer used an additional 250 million images. In this table MAE is more accurate than BEiT without that tokenizer pretraining; the paper also reports about 3.5× faster pretraining per epoch for MAE. Top-1 accuracy alone does not capture the whole cost comparison.

Paper Table 2 also states the hardware. With 128 TPU-v3 cores, TensorFlow, 800 epochs, and 75% masking, ViT-L with encoder mask tokens takes 42.4 hours; MAE with an eight-block decoder takes 15.4 hours, a 2.8× speedup. For ViT-H, 119.6 hours is estimated, versus 34.5 hours, about 3.5×. On the same hardware, the paper separately reports 31 hours for 1600-epoch ViT-L MAE and 36 hours for 300-epoch MoCo v3. These support efficiency for the reported implementation.

Conclusion

In image processing, recorded light does not have the clear semantic pieces that words do. Yet MAE can make detailed reconstructions, suggesting that it has learned many important visual concepts.

This is reminiscent of what happened in NLP: vision seems to be following a similar path, though in its own way.

Many later studies borrowed this idea and added MAE-style training to improve their models. We'll share more when we come across them.