TL;DR
Supervised Contrastive Learning (SupCon) adapts the high-performing contrastive loss used in self-supervised learning to the fully supervised setting. By leveraging labels to pull all samples of the same class together in embedding space, it consistently outperforms standard cross-entropy, achieving a new state-of-the-art 81.4% top-1 accuracy on ImageNet for ResNet-200 while offering significantly better robustness to image corruptions.
What Problem Does This Paper Address?
For years, the cross-entropy loss has been the undisputed king of supervised deep learning. However, it isn't perfect: it can be sensitive to noisy labels, lacks robustness to natural corruptions (like blur or noise), and often results in poor margins between classes.
Meanwhile, contrastive learning has revolutionized self-supervised representation learning (e.g., SimCLR). These methods learn by pulling two augmented "views" of the same image together and pushing them away from other images in the batch. However, until this paper, these techniques hadn't been effectively adapted to supervised learning in a way that consistently beat cross-entropy on large-scale datasets like ImageNet. The authors aim to bridge this gap by using class labels to define "positives" more broadly.
Methods
The authors propose SupCon, which modifies the self-supervised contrastive framework in several key ways to leverage label information:
- Multiviewed Batches: For every image in a batch, two random augmentations (views) are created.
- Many Positives per Anchor: Unlike self-supervised methods that only have one "positive" (the other view of the same image), SupCon treats all augmented samples in the batch that share the same class label as positives.
- The Loss Function: They analyze two ways to sum these multiple positives. They find that summing the log-probabilities ($\mathcal{L}_{out}^{sup}$) performs significantly better than taking the log of the summed probabilities ($\mathcal{L}_{in}^{sup}$). This is because the "out" version reduces bias and provides a more stable gradient.
- Two-Stage Training:
- Stage 1: Train an encoder and a "projection head" (a small MLP) using the SupCon loss.
- Stage 2: Freeze the encoder, discard the projection head, and train a simple linear classifier on top using cross-entropy.
Datasets
The researchers evaluated SupCon on standard image classification benchmarks:
- CIFAR-10 and CIFAR-100: Small-scale benchmarks for initial validation.
- ImageNet: The gold standard for large-scale visual recognition.
- ImageNet-C: A variant of ImageNet used to test robustness against 15 different types of natural corruptions (noise, blur, weather, etc.).
Key Insights and Ideas
- Implicit Hard Mining: One of the most powerful "aha" moments is the realization that the SupCon loss naturally performs "hard positive/negative mining." The gradient math shows that the model automatically focuses more on samples that are difficult to distinguish, without needing complex manual mining algorithms.
- Normalization is Crucial: Mapping embeddings to a unit hypersphere (normalization) and using a temperature parameter in the loss are vital for the model to learn well-separated clusters.
- Stability over Accuracy: While the accuracy gains are impressive, the hyperparameter stability is a major win. SupCon is much less sensitive to the choice of optimizer (LARS vs. SGD) or the specific type of data augmentation used compared to cross-entropy.
- The Power of Negatives: Like its self-supervised cousins, SupCon benefits greatly from large batch sizes (up to 6144 in this paper), as more negatives help the model learn finer distinctions between classes.
Key Results
- Top-1 Accuracy: On ImageNet, SupCon achieved 81.4% on ResNet-200, a 0.8% improvement over the best-reported cross-entropy results for that architecture. On ResNet-50, it reached 78.7%.
- Robustness: SupCon models showed significantly lower Mean Corruption Error (mCE) on ImageNet-C. For ResNet-50, the mCE dropped from 68.6 (cross-entropy) to 67.2, indicating the embeddings are more resilient to real-world image distortions.
- Transfer Learning: Representations learned via SupCon transferred as well as, or better than, cross-entropy models when fine-tuned on 12 different downstream datasets (like Pets, Flowers, and Aircraft).
Limitations and Future Work
- Computational Cost: The reliance on large batch sizes and two views per image makes SupCon more computationally expensive than standard cross-entropy training.
- Two-Stage Process: The requirement to train the encoder first and then a linear classifier adds an extra step to the pipeline, though the authors note the linear head can sometimes be trained jointly with some gradient blocking.
- Future Directions: The authors suggest exploring how to better integrate advanced augmentations like CutMix into the contrastive framework and investigating optimal architectures for the projection head, which is currently discarded after the first stage.
Summary updated