Enriching Knowledge Distillation with Intra-Class Contrastive Learning

Hua Yuan, Ning Xu, Xin Geng, Yong Rui · DOI

Introduction: The "Perfect" Teacher Paradox

Knowledge Distillation (KD) relies on "dark knowledge"—the subtle information hidden in the soft probability distributions produced by a large teacher model. Ideally, these soft labels convey not just the primary class (e.g., "dog"), but also the relative similarities to other classes (e.g., "cat" or "car").

However, modern high-capacity teacher models often become too proficient at fitting training data. They tend to collapse all samples of the same class into a single point in the feature space. When this happens, the soft labels become nearly identical to "hard" ground-truth labels, destroying the intra-class variance—the "multi-view" structure—that helps student models generalize. This paper introduces a method to prevent this "mode collapse" and provide a richer signal for the student.

Methodology: Margin-Based Intra-Class Contrastive Distillation

The proposed approach introduces a margin-based intra-class contrastive loss during teacher training to maintain feature diversity while ensuring clear separation between categories.

Comparison between standard feature collapse (left) and the proposed intra-class diversification with a margin (right).

The method consists of three main components:

  1. Intra-Class Contrastive Loss ($L_{Intra}$): Unlike standard contrastive learning, which pushes different classes apart, this loss targets samples within the same class. It encourages the teacher to learn a more spread-out, diverse representation for each category.
  2. Margin-Based Filtering: To prevent training instability, the authors introduce a confidence margin ($\delta$). The intra-class loss is only applied to "anchor" samples that the teacher is already confident about, ensuring that diversification does not interfere with basic classification accuracy.
  3. Pipeline-Based Caching: To provide enough negative samples without exceeding GPU memory limits, the authors implemented a sliding-window queue that caches features asynchronously.
The training algorithm for Margin-Based Intra-Class Contrastive Distillation.

Experimental Results and Insights

The researchers evaluated their method on standard benchmarks including CIFAR-100 and ImageNet, testing both homogeneous (e.g., ResNet50 to ResNet34) and heterogeneous (e.g., ResNet50 to MobileNet-V2) distillation.

  • Performance Gains: On CIFAR-100, the method achieved 79.10% accuracy (ResNet50 $\to$ ResNet34), compared to 78.38% for standard KD. On ImageNet, it reached 67.81% Top-1 accuracy, outperforming SOTA baselines like ReviewKD.
  • Tunability: Theoretical analysis confirms that intra-class spread increases monotonically with the weight of the contrastive term ($\lambda$), providing a mathematical "dial" to control label diversity.
  • Complementarity: The method is highly compatible with other relational KD techniques. Combining it with RKD (Relational Knowledge Distillation) yielded the highest overall performance of 79.39% on CIFAR-100.
  • Efficiency: Despite the extra steps, the pipeline-caching mechanism kept computational overhead low, adding only about 10-15% to training time per batch.

Conclusion

By forcing the teacher model to maintain diversity within classes, Margin-Based Intra-Class Contrastive Distillation preserves the "nuance" required for effective knowledge transfer. This method effectively addresses the limitations of high-capacity teachers in KD pipelines, leading to significant performance improvements in student models across various architectures and datasets.

Summary updated

BibTeX
@misc{yuan2025enriching,
  author = {Hua Yuan and Ning Xu and Xin Geng and Yong Rui},
  title = {{Enriching Knowledge Distillation with Intra-Class Contrastive Learning}},
  year = {2025},
  eprint = {2509.22053},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2509.22053},
}
Figure