Abstract
Deep neural networks often rely on deep supervision—auxiliary classifiers at intermediate layers—to mitigate gradient vanishing and accelerate convergence. However, traditional deep supervision imposes task-specific labels on shallow layers, potentially disrupting the natural hierarchy where early layers should focus on general, task-irrelevant features. We present Contrastive Deep Supervision (CDS), a framework that replaces intermediate task losses with contrastive learning. By supervising shallow layers to learn augmentation-invariant representations, CDS preserves the feature hierarchy and enhances generalization. Our experiments demonstrate significant improvements in image classification, object detection, and knowledge distillation, with a ResNet18 achieving a +3.64% top-1 accuracy gain on ImageNet.
Introduction
Training very deep neural networks is notoriously difficult due to issues like gradient vanishing. A popular solution is Deep Supervision, where auxiliary classifiers are attached to intermediate layers to provide direct gradient signals. However, there is a fundamental conflict in traditional Deep Supervision: it applies the final task loss (e.g., "is this a dog?") to shallow layers. Visualization studies suggest that shallow layers should be learning low-level features like edges, textures, and colors—features that are generally "task-irrelevant." Forcing these early layers to learn high-level semantic labels (task-bias) can disrupt the natural feature hierarchy and degrade the final model's accuracy.
The CDS Framework
To address this, we propose Contrastive Deep Supervision (CDS). Instead of using a standard classifier (Fully Connected layer + Cross-Entropy) for intermediate layers, CDS utilizes Contrastive Learning to supervise the backbone at various depths.
As illustrated in the figure above, CDS differs from traditional deep supervision by allowing intermediate layers to remain "task-irrelevant." The method follows three core steps:
- Intermediate Supervision: Several "projection heads" are attached to the backbone at different depths.
- The Contrastive Loss: For a given image, two different augmentations (e.g., color jittering or cropping) are created. Intermediate layers are trained to minimize the distance between representations of these two versions (positive pairs) while maximizing the distance from other images in the batch (negative pairs).
- The Final Layer: The very last layer still uses the standard supervised task loss to ensure the model achieves its primary objective.
Crucially, these projection heads are discarded after training. The resulting model maintains the exact same architecture and computational cost during inference as a standard network.
Experimental Evaluation
The authors evaluated CDS across a massive range of benchmarks, including ImageNet, COCO, and various fine-grained classification datasets.
Key Results
- ImageNet Classification: A ResNet18 trained with CDS achieved 72.85% top-1 accuracy, a massive +3.64% improvement over the standard baseline, significantly outperforming other deep supervision methods like DSN.
- Object Detection: Backbones pre-trained with CDS provided a +0.9 AP boost for Faster R-CNN and +0.8 AP for RetinaNet on the MS COCO2017 dataset compared to standard pre-training.
- Knowledge Distillation: By combining CDS with feature distillation, a ResNet18 student reached 73.23% on ImageNet, outperforming the second-best distillation method by 2.16%.
- Fine-Grained Tasks: On the CUB200 dataset, CDS improved ResNet50 accuracy by 4.0% when training from scratch.
Discussion and Insights
The primary "aha moment" of CDS is that for a shallow layer, learning that "an image is the same even if it's grayscale" is more useful than trying to learn "this is a Golden Retriever." This general knowledge transfers better to the final layers and prevents the model from over-fitting training labels too early. While the training loss may stay slightly higher than the baseline, the validation accuracy is much higher, indicating superior generalization.
Furthermore, models trained with CDS show lower Expected Calibrated Error (ECE). This improved calibration means the model's confidence scores are more meaningful—if it predicts a class with 90% confidence, it is statistically more likely to be correct compared to a baseline model.
Conclusion
Contrastive Deep Supervision offers a powerful yet simple refinement to the training of deep neural networks. By aligning auxiliary supervision with the natural feature hierarchy of the model—supervising for invariance in shallow layers and task-specific labels in deep layers—CDS achieves state-of-the-art performance across a variety of vision tasks. While it introduces some training-time overhead due to multiple augmentations and projection heads, the lack of inference-time cost makes it a highly practical framework for deploying high-performance models.
Summary updated