Supervised Masked Knowledge Distillation for Few-Shot Transformers

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

TL;DR

SMKD (Supervised Masked Knowledge Distillation) is a novel framework that helps Vision Transformers (ViTs) overcome their "data-hungry" nature in few-shot learning scenarios. By extending masked self-distillation to a supervised setting—aligning features across different images of the same class—it achieves new state-of-the-art results on several few-shot classification benchmarks.

What Problem Does This Paper Address?

Vision Transformers (ViTs) have revolutionized computer vision by capturing long-range dependencies through self-attention. However, they lack the "inductive biases" (like translation invariance) inherent in Convolutional Neural Networks (CNNs). This makes them notoriously data-hungry.

In Few-Shot Learning (FSL), where a model must learn to recognize new categories from just one or five examples, ViTs tend to overfit severely. While previous researchers tried to fix this using auxiliary self-supervised tasks or complex label-based regularization, a gap remained: how to effectively integrate label information directly into the powerful masked knowledge distillation frameworks that have worked so well for self-supervised learning.

Figure 1. Comparison of the proposed idea and other exist- ing methods for few-shot Transformers. Our model mitigates the overfitting issue of few-shot Transformers, by extending the masked knowledge distillation framework into the supervised set- ting, and enforcing the alignment of [cls] and corresponding [patch] tokens for intra-class images.

Methods

The authors propose Supervised Masked Knowledge Distillation (SMKD). The core idea is to move beyond comparing two views of the same image (self-distillation) to comparing views of different images from the same class (supervised distillation).

Key components include:

  • Student-Teacher Architecture: A standard setup where a "student" network learns from a "teacher" network (which is an exponentially moving average of the student).
  • Intra-class [cls] Token Distillation: The model minimizes the cross-entropy between the projected class ([cls]) tokens of two different images belonging to the same category.
  • Intra-class Masked [patch] Token Distillation: This is the most novel part. For a patch in the teacher's image, the model finds the most similar patch in the student's image (which might be masked) using cosine similarity. The student is then tasked with reconstructing these "matched" patch features across images.
  • Two-Stage Training:
    1. Self-supervised Pre-training: Using the iBOT framework to give the model a strong initial feature representation.
  • Supervised Training: Fine-tuning with the proposed SMKD losses.
Figure 3. Overview of our SMKD framework. Two views are generated from a pair of images sampled (with replacement) from the same class. The first view, applied with random blockwise masking, is passed to the student network, while the second unmasked view is passed to the teacher network. Both networks consist of a ViT backbone and a projection head. The parameters of the teacher network are Exponentially Moving Averaged (EMA) updated by the student network. SMKD distills knowledge between intra-class cross-views on both class and patch levels. L[cls] distills knowledge from [cls] tokens, while L[patch] distills knowledge from [patch] tokens by finding dense correspondence of matched token pairs (connected by red dashed lines) with highest similarities.

Datasets

The model was evaluated on four standard few-shot classification benchmarks:

  • mini-ImageNet: 100 classes, 600 images per class.
  • tiered-ImageNet: A larger subset of ImageNet with 609 classes.
  • CIFAR-FS: 100 classes from CIFAR-100, adapted for few-shot learning.
  • FC100: Another CIFAR-100 derivative with a more challenging "super-class" split to minimize overlap between training and testing categories.

Key Insights and Ideas

  • Semantic Patch Correspondence: The authors hypothesized that even if two images of the same class look different, they should share patches with similar semantic meanings (e.g., two different dogs both have "ear" patches). SMKD successfully learns to find these correspondences.
  • Masking as a Challenge: By masking patches in the student's view and asking it to reconstruct them based on a different image's patches, the task becomes significantly harder. This forces the model to learn robust, high-level semantic features rather than relying on low-level pixel matching.
  • Simplicity Wins: Unlike competing methods that use complex "spectral tokens" or multiple cascaded transformers, SMKD introduces no additional learnable parameters to the backbone, making it highly efficient and easy to integrate with other techniques.
Figure 5. Visualization of dense correspondence. We use the patches with the highest self-attention of the [cls] token on each attention head (6 in total) of the last layer of ViT-S as queries. Best matched patches with highest similarities are connected with lines.

Key Results

SMKD achieved impressive performance, particularly on smaller-resolution datasets:

  • New State-of-the-Art (SOTA): On CIFAR-FS, it reached 80.08% (1-shot) and 90.63% (5-shot). On FC100, it hit 50.38% (1-shot) and 68.37% (5-shot), outperforming previous methods by over 2%.
  • Competitive on ImageNet variants: It ranked second among Transformer-based methods on mini-ImageNet and tiered-ImageNet, and achieved a new SOTA when combined with specific pooling strategies from other papers (reaching 75.32% 1-shot on mini-ImageNet).
  • Efficiency: SMKD is significantly faster to train than its top competitors (e.g., ~16 hours vs ~22 hours for HCTransformers) while using a third of the parameters.

Limitations and Future Work

  • Reliance on Pre-training: The ablation studies show that the model struggles to converge if trained from scratch with SMKD losses alone. A self-supervised pre-training stage is currently essential.
  • Curriculum Learning: The authors view their two-stage process as a form of curriculum learning (easy SSL tasks to hard supervised tasks). They suggest that future work could unify these into a single, more elegant training objective.
  • Patch Matching Complexity: While effective, the current patch-matching strategy relies on simple cosine similarity. More sophisticated matching algorithms could potentially further boost performance.

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