In Defense of Feature Mimicking for Knowledge Distillation

Guo-Hua Wang, Yifan Ge, Jianxin WuarXiv 2020 · DOI · OpenReview

TL;DR

This paper proposes a novel knowledge distillation method that focuses on mimicking the "penultimate layer" features of a teacher network, rather than just its output logits. They introduce a new loss function based on Locality-Sensitive Hashing (LSH) that encourages the student network to learn the direction of the teacher's features while allowing more freedom in their magnitude, leading to state-of-the-art performance across various vision tasks.

What Problem Does This Paper Address?

Knowledge distillation (KD) is a powerful technique for training smaller, more efficient "student" neural networks by leveraging the knowledge of larger, pre-trained "teacher" networks. Traditional KD methods primarily use the teacher's output probabilities (logits) as supervision. However, these logits are often very close to the ground truth labels and might not fully capture the rich information learned by the teacher in its intermediate layers. Furthermore, these methods struggle with teachers trained without a softmax output or when teacher and student networks have different architectures. This paper addresses these limitations by proposing a feature-mimicking approach that directly learns from the teacher's internal representations, specifically from the penultimate layer, which is argued to contain more discriminative information.

Methods

The core of the proposed method is feature mimicking, where the student network is trained to replicate the feature representations of the teacher network in its penultimate layer. To facilitate this, they introduce:

  • Linear Embedding Layer: A simple linear layer is added to the student's network to match the dimensionality of the teacher's features. This layer can be merged into the classifier post-training, adding no inference overhead. This also helps align feature spaces, especially when the student is pretrained.
  • Locality-Sensitive Hashing (LSH) Loss: The authors argue that feature direction is more crucial for classification than feature magnitude. They decompose features into these two components and propose an LSH-based loss function. This loss encourages the student's feature direction to align with the teacher's while allowing its magnitude to vary more freely. This is a key departure from standard L2 loss, which penalizes both direction and magnitude equally.
  • Two-Stage Training (for some tasks): For tasks like multi-label classification, a two-stage training strategy is employed. The first stage focuses on aligning feature spaces using the mimicking loss, and the second stage incorporates the standard classification loss.

Datasets

The proposed method was evaluated on several standard computer vision datasets:

  • CIFAR-100: Used for single-label image classification.
  • ImageNet: Used for single-label image classification.
  • VOC2007 & MS-COCO: Used for multi-label classification.
  • Pascal VOC: Used for object detection.

Key Insights and Ideas

  • Penultimate Layer is Key: The paper strongly advocates for mimicking features from the penultimate layer, arguing it contains more discriminative information than output logits and is more flexible for cross-architecture distillation.
  • Direction Over Magnitude: A crucial insight is that the direction of a feature vector is more important for classification than its magnitude. This led to the development of the LSH loss.
  • LSH for Direction Mimicry: Locality-Sensitive Hashing naturally groups similar feature directions, making it an effective tool for encouraging the student to learn the teacher's feature orientation.
  • Flexibility of Feature Mimicking: The approach is shown to be effective across different teacher-student architectures and applicable to tasks where traditional KD struggles (e.g., multi-label classification).

Key Results

  • State-of-the-Art Performance: The proposed LSH-based feature mimicking method achieved state-of-the-art results on CIFAR-100 and ImageNet for single-label classification.
  • Significant Improvements: On CIFAR-100, the method achieved relative improvements of up to 113% compared to the baseline student model.
  • Effective for Cross-Architecture Distillation: The method showed strong performance even when teacher and student networks had significantly different architectures, outperforming existing methods like CRD.
  • Object Detection Success: The approach was successfully extended to object detection (Faster R-CNN and RetinaNet), demonstrating significant improvements over baseline methods and even achieving comparable performance to the teacher in some cases.
  • LSH Loss Advantage: The LSH loss consistently outperformed the standard L2 loss for feature mimicking, especially in cross-architecture scenarios, highlighting the importance of focusing on feature direction.

Limitations and Future Work

  • Hyperparameter Tuning: The LSH module has hyperparameters (N, stdhash, β) that may require tuning on a validation set for optimal performance.
  • Randomness in LSH: While the paper shows LSH is effective, there's inherent randomness in the hashing process, which they mitigate by averaging over multiple epochs. Reducing this randomness is a potential area for future work.
  • Feature Space Alignment: While the linear embedding layer helps, explicit feature space alignment techniques could be further explored.
  • Data-Free Distillation: The authors mention exploring data-free settings as a future direction.
  • Mimicking Proposals in Detection: For object detection, they focused on mimicking penultimate layer features and suggest mimicking proposal features as future work.

Summary updated

Abstract

Knowledge distillation (KD) is a popular method to train efficient networks ("student") with the help of high-capacity networks ("teacher"). Traditional methods use the teacher's soft logits as extra supervision to train the student network. In this paper, we argue that it is more advantageous to make the student mimic the teacher's features in the penultimate layer. Not only the student can directly learn more effective information from the teacher feature, feature mimicking can also be applied for teachers trained without a softmax layer. Experiments show that it can achieve higher accuracy than traditional KD. To further facilitate feature mimicking, we decompose a feature vector into the magnitude and the direction. We argue that the teacher should give more freedom to the student feature's magnitude, and let the student pay more attention on mimicking the feature direction. To meet this requirement, we propose a loss term based on locality-sensitive hashing (LSH). With the help of this new loss, our method indeed mimics feature directions more accurately, relaxes constraints on feature magnitudes, and achieves state-of-the-art distillation accuracy. We provide theoretical analyses of how LSH facilitates feature direction mimicking, and further extend feature mimicking to multi-label recognition and object detection.
BibTeX
@misc{wang2020defense,
  author = {Guo-Hua Wang and Yifan Ge and Jianxin Wu},
  title = {{In Defense of Feature Mimicking for Knowledge Distillation}},
  year = {2020},
  eprint = {2011.01424},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2011.01424},
}
Figure