MAGE: MAsked Generative Encoder to Unify Representation Learning and Image Synthesis

Tianhong Li, Huiwen Chang, Shlok Kumar Mishra, Han Zhang, Dina Katabi, Dilip Krishnan

TL;DR

MAGE (MAsked Generative Encoder) is the first framework to successfully unify state-of-the-art self-supervised representation learning and high-fidelity image generation within a single Vision Transformer. By training on discrete semantic tokens with a variable masking ratio (from 50% to 100%), MAGE eliminates the need for separate recognition and synthesis models, achieving top-tier performance on both benchmarks simultaneously.

What Problem Does This Paper Address?

Computer vision has traditionally treated image generation (synthesis) and representation learning (recognition) as separate problems requiring distinct architectures and training paradigms. Generative models typically map low-dimensional inputs (like noise or class labels) to high-dimensional images, while representation learning compresses high-dimensional images into low-dimensional embeddings.

Prior attempts to use Masked Image Modeling (MIM)—such as Masked Autoencoders (MAE)—for both tasks fell short. Because these models operate directly on raw pixels and rely on pixel-level reconstruction losses, their generated images are often blurry and lack fine-grained textures. MAGE addresses this gap by demonstrating that generation and representation learning can mutually benefit each other when unified under a single token-based framework.

Methods

The core innovation of MAGE rests on two pillars: quantized tokenization and a variable masking ratio.

  1. Tokenization: Instead of processing raw pixel patches, MAGE uses a pre-trained VQGAN to convert input images into a grid of discrete semantic tokens. This forces the model to operate in a high-level semantic space while retaining structural details.
  2. Variable Masking Ratio: During pre-training, MAGE randomly masks out a variable percentage of tokens, sampled from a truncated Gaussian distribution ranging from 50% to 100%. A 100% mask corresponds to pure image generation (synthesis from scratch), while lower masking ratios force the network to learn robust representations for recognition.
  3. Encoder-Decoder Architecture: A Vision Transformer (ViT) encoder processes only the unmasked tokens. Crucially, instead of using a generic, shared mask token to pad the encoder output before decoding, MAGE uses an image-specific class token [C] learned by the encoder to summarize global features.
  4. Contrastive Co-training (MAGE-C): To further boost representation quality, the authors introduce an optional contrastive loss (InfoNCE) on the encoder's output. This loss is selectively applied only when the masking ratio is low ($m_r < 0.6$) to avoid training on pairs of views with zero overlapping information.
Figure 3. MAGE Framework: we first use a VQGAN tokenizer to tokenize the input image into a sequence of semantic tokens. We then sample a masking ratio (see text for details on the sampling strategy) and randomly mask out tokens according to this sampled ratio. A ViT encoder-decoder structure processes the unmasked tokens. A reconstructive cross-entropy loss encourages the model to reconstruct masked tokens. We can also add an optional contrastive loss at the output of the encoder to further improve the linear separability of the learned latent feature space.

Datasets

  • ImageNet-1K: Used for both self-supervised pre-training and primary evaluations (including linear probing, fine-tuning, and class-unconditional image generation).
  • Downstream Transfer Learning Datasets: To test representation robustness under few-shot settings, the authors evaluated MAGE on 8 distinct datasets: Birds, DTD, Caltech, Cars, CIFAR100, Col-Hist, Pets, and UC-Merced.

Key Insights and Ideas

  • Generation is just 100% masking: By framing image synthesis as the extreme case of masked image modeling (where 100% of the tokens are missing), representation learning and generation become two sides of the same coin.
  • Pixels cause blur, tokens bring clarity: Operating in token space rather than pixel space allows the model to learn a probability distribution over discrete semantic categories rather than averaging pixel values. This prevents the blurry outputs typical of pixel-based MIM models like MAE.
  • Dynamic masking requires dynamic padding: Replacing a uniform [MASK] token with an image-specific, encoder-learned class token [C] provides the decoder with global contextual guidance, significantly improving both reconstruction and generation quality.
Figure 2. Reconstruction results using MAE and MAGE with 75% masking ratio. MAE reconstructs blurry images with low quality, while MAGE can reconstruct high-quality images with detail, and further improves quality through iterative decoding (see subsection 3.2 for details). With the same mask, MAGE generates diverse reconstruction results with different random seeds. Note that the mask for MAGE is on semantic tokens whereas that of MAE is on patches in the input image.

Key Results

MAGE achieves state-of-the-art results simultaneously in both generation and representation learning benchmarks on ImageNet-1K:

  • Image Generation: For class-unconditional generation, MAGE (ViT-L) achieves a Fréchet Inception Distance (FID) of 9.10 (and 7.04 with weak data augmentation), drastically outperforming the previous state-of-the-art MaskGIT (20.68 FID).
  • Representation Learning: In linear probing on ImageNet-1K, MAGE (ViT-L) achieves 78.9% top-1 accuracy. When enhanced with the contrastive loss (MAGE-C), it reaches 80.9%, outperforming pure contrastive methods like MoCo v3 and other MIM approaches.
Figure 1. Linear probing and class unconditional generation per- formance of different methods trained and evaluated on ImageNet- 1K. MAGE achieves SOTA performance in linear probing and es- tablishes a new SOTA in class unconditional generation.

Limitations and Future Work

  • Fine-tuning from scratch: The authors note that training from scratch or fine-tuning on quantized tokens yields slightly subpar performance compared to pixel-based alternatives, suggesting that quantization might introduce a bottleneck for certain dense downstream tasks.
  • Contrastive loss conflict: Applying contrastive learning at very high masking ratios degrades performance because heavily masked views share almost no mutual information. MAGE bypasses this by thresholding the loss ($m_r < 0.6$), but a more elegant, unified loss formulation remains an open area of research.
  • Scaling: A natural future extension is to pre-train MAGE on larger unlabelled datasets, such as JFT-300M, to see if the synergy between generation and representation scales up.

Summary updated

BibTeX
@misc{li2022mage,
  author = {Tianhong Li and Huiwen Chang and Shlok Kumar Mishra and Han Zhang and Dina Katabi and Dilip Krishnan},
  title = {{MAGE: MAsked Generative Encoder to Unify Representation Learning and Image Synthesis}},
  year = {2022},
  eprint = {2211.09117},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2211.09117},
}
Figure