Distilling efficient Vision Transformers from CNNs for semantic segmentation

Xu Zheng, Yunhao Luo, Pengyuan Zhou, Lin Wang

TL;DR

This paper introduces C2VKD, a novel knowledge distillation framework that enables compact Vision Transformers (ViTs) to learn efficiently from powerful but cumbersome CNN models for semantic segmentation. By addressing the inherent differences between CNN and ViT architectures and the capacity gap between them, C2VKD achieves significant performance improvements, setting a new state-of-the-art.

What Problem Does This Paper Address?

Semantic segmentation, a crucial task in computer vision, aims to classify every pixel in an image. While Convolutional Neural Networks (CNNs) have been dominant, Vision Transformers (ViTs) have emerged as superior performers, especially on large datasets, due to their scalability and learning capacity. However, ViTs are computationally expensive and require vast amounts of training data, making them impractical for many real-world applications. This paper tackles the challenge of transferring the knowledge from well-established, high-performance CNN models to create efficient ViT-based models for semantic segmentation, without sacrificing performance. This is a non-trivial problem due to the fundamental differences in how CNNs and ViTs process information (e.g., receptive fields, inductive biases) and the significant capacity gap between them, which hinders direct knowledge transfer.

Methods

The core of the proposed solution is the C2VKD (CNN-to-ViT Knowledge Distillation) framework, which comprises two novel modules:

  • Visual-Linguistic Feature Distillation (VLFD): This module addresses the heterogeneous feature representations between CNNs and ViTs. It leverages the observation that ViT features, due to their patch-based processing similar to NLP tokens, possess "linguistic-compatible" characteristics. VLFD aligns these linguistic features from the CNN teacher with the ViT student. It also incorporates both global-wise and patch-wise feature distillation to capture fine-grained correspondences that might be missed by global alignment alone.
  • Pixel-wise Decoupled Distillation (PDD): This module tackles the capacity gap and potential prediction errors from the teacher model. Instead of simply using the teacher's output logits, PDD decouples the distillation process for target and non-target classes. It combines ground truth labels with the teacher's predictions, allowing the ViT student to learn more reliably and effectively, mitigating the negative impact of teacher errors.

The overall framework combines these distillation losses with the standard cross-entropy loss for training the ViT student.

Datasets

The proposed C2VKD framework is evaluated on three standard semantic segmentation benchmarks:

  • PASCAL VOC 2012: A dataset with 21 classes, commonly used for evaluating segmentation models.
  • Cityscapes: A more complex dataset featuring urban street scenes with high-quality pixel-wise annotations across 50 cities.
  • ADE20K: A large-scale dataset with 150 fine-grained semantic concepts.

Key Insights and Ideas

  • ViT features have "linguistic-compatible" characteristics: This is a key insight that enables aligning CNN and ViT representations by treating ViT's patch embeddings analogously to word embeddings in NLP.
  • Direct alignment of CNN and ViT features is challenging: The differing inductive biases (e.g., CNNs' local receptive fields vs. ViTs' global self-attention) make simple feature map alignment ineffective.
  • Decoupling target and non-target class distillation is crucial: This strategy helps the student model learn more robustly by mitigating the impact of potential errors in the teacher's predictions, especially when there's a significant capacity gap.
  • Combining global and patch-wise feature distillation is beneficial: This approach captures both broad contextual information and fine-grained local details, leading to better feature transfer.

Key Results

The C2VKD framework consistently outperforms existing state-of-the-art knowledge distillation methods across all tested ViT backbones (SegFormer, PVT, PVTv2) and datasets.

  • PASCAL VOC 2012: Achieved significant improvements in mIoU, with gains of up to +2.01% over baselines.
  • Cityscapes: Demonstrated robust performance, with gains of up to +2.31% mIoU, particularly excelling at segmenting small objects.
  • ADE20K: Showed substantial improvements, with gains of up to +3.87% mIoU, highlighting its effectiveness on larger and more complex datasets.
  • Qualitative results (visualizations) show that C2VKD effectively mitigates common issues in KD, such as underperformance and incorrect segmentation regions, often surpassing even the teacher model in specific aspects.

Limitations and Future Work

  • Computational Cost: While C2VKD achieves better performance and efficiency, it does introduce some additional computational cost during training compared to simpler KD methods.
  • Future Directions: The authors plan to explore improving the efficiency of feature transformations between CNN and ViT. They also propose investigating the reverse problem: distilling a compact CNN student from a powerful ViT teacher.

Summary updated

BibTeX
@article{zheng2023distilling,
  author = {Xu Zheng and Yunhao Luo and Pengyuan Zhou and Lin Wang},
  title = {{Distilling efficient Vision Transformers from CNNs for semantic segmentation}},
  journal = {Pattern Recognition},
  year = {2023},
}
Figure