Supervised Masked Knowledge Distillation for Few-Shot Transformers

Han Lin, Guangxing Han, Jiawei Ma, Shiyuan Huang, Xudong Lin, Shih-Fu Chang · DOI

Abstract

Vision Transformers (ViTs) achieve impressive performance on data-abundant computer vision tasks by capturing long-range dependencies. However, in few-shot learning (FSL) settings, ViTs often overfit due to a lack of CNN-like inductive biases. We propose Supervised Masked Knowledge Distillation (SMKD), a novel framework that incorporates label information into self-distillation. By enabling intra-class knowledge distillation on both class and patch tokens and introducing cross-image masked patch reconstruction, SMKD outperforms previous methods across four major benchmarks, achieving a new state-of-the-art.

Introduction: The Challenge of Few-Shot ViTs

Vision Transformers have revolutionized computer vision but remain notoriously "data-hungry." Unlike Convolutional Neural Networks (CNNs), which possess an inherent inductive bias (the assumption that neighboring pixels are related), ViTs must learn these spatial relationships from scratch.

In Few-Shot Learning (FSL), where models must generalize from just one or five examples, this lack of bias leads to aggressive overfitting. ViTs tend to "memorize" specific training samples rather than learning robust, generalizable features. While researchers have explored self-supervised auxiliary tasks, a gap remains in effectively leveraging label information within the powerful "masked modeling" paradigms used for large-scale Transformer training.

Methods: Supervised Masked Knowledge Distillation

SMKD addresses these challenges through a two-stage training framework designed to make ViTs "few-shot friendly."

1. Self-Supervised Pre-training

The process begins with a standard masked image modeling (MIM) phase (utilizing the iBOT framework) to establish a baseline understanding of visual structures.

2. Supervised Masked Knowledge Distillation

The core innovation lies in the second stage, which employs a "Teacher-Student" architecture. The Teacher is an Exponentially Moving Average (EMA) version of the Student.

  • Intra-class Distillation: Unlike traditional methods that compare two views of the same image, SMKD samples two different images (Image A and Image B) from the same class.
  • Global and Local Alignment: The model forces the [cls] (global) tokens of both images to align. For local features, since patches between different images do not align spatially, SMKD uses cosine similarity to find the "best-matched" patch in the teacher's unmasked image for every patch in the student's masked image.
  • Cross-Image Reconstruction: The student must reconstruct the features of a masked patch in Image A by attending to the most semantically similar patch in Image B. This forces the model to ignore image-specific noise and focus on category-defining semantic features.
The SMKD framework architecture, illustrating the student-teacher setup and the dual global/local distillation losses.

Key Insights: Learning Dense Correspondences

A primary strength of SMKD is its ability to learn dense semantic correspondences across different instances of a class. By matching patches across images, the model develops a fine-grained understanding of object parts. Visualizations demonstrate that the model naturally learns to connect similar components—such as the wheels of different buses or the facial features of different animals—without explicit part-level supervision. This dense correspondence is key to the model's superior generalization in low-data regimes.

Visualization of cross-image patch correspondences. The model successfully identifies and matches semantically similar parts (e.g., eyes, wheels, armor details) across different images of the same class.

Experimental Results

SMKD was evaluated on four standard few-shot classification benchmarks: mini-ImageNet, tiered-ImageNet, CIFAR-FS, and FC100.

  • New State-of-the-Art: SMKD achieved top performance across all benchmarks. Notably, on CIFAR-FS, it reached 80.08% (1-shot), and on the challenging FC100 dataset, it reached 50.38% (1-shot).
  • Efficiency: SMKD is significantly more efficient than competing methods. It trains in approximately one hour (supervised stage) compared to over 21 hours for HCTransformers, while using 3x fewer parameters (21M vs 63M).
  • Ablation Studies: Combining global ([cls]) and local ([patch]) distillation provided a massive 13.35% improvement over the baseline for 1-shot tasks on mini-ImageNet, confirming the value of the dual-alignment strategy.

Conclusion

By bridging the gap between self-supervised masked modeling and supervised learning, SMKD allows ViTs to excel even with limited data. The transition from simple self-supervised tasks to complex cross-image supervised distillation provides a powerful curriculum for training Transformers on specialized, small-scale datasets. Future work may explore one-stage training approaches or more advanced patch-matching algorithms like Optimal Transport.

Code for this paper is available at: https://github.com/HL-hanlin/SMKD

Summary updated

BibTeX
@misc{lin2023supervised,
  author = {Han Lin and Guangxing Han and Jiawei Ma and Shiyuan Huang and Xudong Lin and Shih-Fu Chang},
  title = {{Supervised Masked Knowledge Distillation for Few-Shot Transformers}},
  year = {2023},
  eprint = {2303.15466},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2303.15466},
}
Figure