Layer Grafted Pre-training: Bridging Contrastive Learning And Masked Image Modeling For Label-Efficient Representations

Ziyu Jiang, Yinpeng Chen, Mengchen Liu, Dongdong Chen, Xiyang Dai, Lu Yuan, Zicheng Liu, Zhangyang Wang

Introduction

Researchers have developed "Layer Grafted Pre-training," a simple yet highly effective way to combine the two most popular self-supervised learning methods: Masked Image Modeling (MIM) and Contrastive Learning (CL). By training lower network layers with MIM and higher layers with CL, the model achieves a massive 14.4% accuracy boost over standard MIM on ImageNet-1k using only 1% of labels.

The Problem: Gradient Conflict

In the world of computer vision, there are two dominant ways to teach a model without human-labeled data:

  1. Contrastive Learning (CL): Teaches the model that two different "views" of the same image (e.g., cropped or color-distorted) should have similar representations. This is great for learning high-level concepts but can ignore local details.
  2. Masked Image Modeling (MIM): Hides parts of an image and asks the model to reconstruct them. This is excellent at learning local structures and textures but often lacks the "big picture" semantic understanding needed for few-shot learning.

Naturally, researchers tried to combine them using Multi-Task Learning (MTL)—simply adding the two loss functions together. However, this usually fails. The authors discovered why: the two methods have conflicting goals. MIM requires the model to be sensitive to pixel-level changes (like brightness and position) to reconstruct them, while CL requires the model to be invariant to those same changes.

Gradient Conflict Across Layers

As shown in the gradient analysis above, the cosine similarity between MIM and CL gradients becomes increasingly negative in deeper layers. They are literally pulling the model weights in opposite directions, creating a "gradient conflict" that worsens as you go deeper into the neural network.

Methodology: Layer Grafted Pre-training

The authors propose a "sequential cascade" approach called Layer Grafted Pre-training. Instead of forcing the whole network to do both tasks at once, they assign tasks based on what different layers are naturally good at.

Layer Grafted Pre-training Strategies
  • The Grafting Strategy: They first train the lower layers of a Vision Transformer (ViT) using an MIM loss (specifically the MAE framework). Then, they "graft" higher layers onto this base and train them using a CL loss (specifically MoCo v3).
  • "Smooth" Grafting: Rather than completely freezing the lower layers during the second stage, they use a very small learning rate for the lower (MIM-trained) layers and a larger learning rate for the higher (CL-trained) layers. This allows the transition between the two feature spaces to "smooth out" without destroying the local features learned by MIM.
  • Layer-wise Preference: The authors empirically found that lower layers prefer MIM (capturing local spatial details), while higher layers prefer CL (learning semantic grouping).

Key Insights

  • Order Matters: The authors tried the reverse (CL first, then MIM) and found it performed significantly worse. This confirms that low-level "pixel" knowledge is a necessary foundation for high-level "semantic" knowledge, not the other way around.
  • Attention Distance: Analysis showed that CL-trained models have a much larger "average attention distance" in early layers compared to MIM. By using MIM for early layers, the model maintains a smaller, more localized focus early on, which mimics the hierarchical structure of the human visual system.

Key Results

The primary training and evaluation were conducted on ImageNet-1k (for classification) and ADE20K (for semantic segmentation). The results on ImageNet-1k with a ViT-B/16 backbone are striking, particularly in label-scarce scenarios:

  • 1% Few-Shot Learning: Layer Grafted Pre-training achieved 65.5% Top-1 accuracy, outperforming the MIM baseline (51.1%) by 14.4% and the CL baseline (63.4%) by 2.1%.
  • Linear Evaluation: It reached 77.7%, beating both MIM (68.0%) and CL (76.7%).
  • State-of-the-Art Hybrid: It outperformed other complex hybrid methods like iBoT and SIM, despite being conceptually simpler.
  • Scalability: The benefits held true when scaling up to the larger ViT-L/16 model, reaching 81.0% on linear evaluation.

Limitations and Future Work

  • Two-Stage Training: While effective, the method requires a sequential two-stage training process, which is more complex to manage than a single-stage joint optimization.
  • Fine-tuning Gap: While the method dominates in few-shot and linear evaluation, its advantage in full fine-tuning (where you have all the labels) is much smaller (0.3% - 0.7% improvement).
  • Future Directions: The authors suggest exploring how this layer-wise grafting might work on real-world, unlabeled, and imbalanced datasets, or extending the idea to other modalities like video or audio.

Summary updated

BibTeX
@inproceedings{jiang2023layer,
  author = {Ziyu Jiang and Yinpeng Chen and Mengchen Liu and Dongdong Chen and Xiyang Dai and Lu Yuan and Zicheng Liu and Zhangyang Wang},
  title = {{Layer Grafted Pre-training: Bridging Contrastive Learning And Masked Image Modeling For Label-Efficient Representations}},
  booktitle = {International Conference on Learning Representations},
  year = {2023},
  url = {https://openreview.net/forum?id=jwdqNwyREyh},
}
Figure