A Unified Framework for Contrastive Learning from a Perspective of Affinity Matrix

Wenbin Li, Meihao Kong, Xuesong Yang, Lei Wang, Jing Huo, Yang Gao, Jiebo Luo

TL;DR

This paper introduces UniCLR, a unified framework that demonstrates how four major, seemingly distinct paradigms of self-supervised learning (SSL)—contrastive, non-contrastive, whitening, and consistency regularization—can be unified under a single perspective: optimizing a basic affinity matrix. By viewing SSL through this lens, the authors derive three novel, high-performing variants and a simple symmetric loss that significantly accelerates model convergence.

What Problem Does This Paper Address?

Self-supervised learning (SSL) has revolutionized visual representation learning by allowing models to learn from unlabeled data. However, the field has fragmented into different methodologies:

  1. Standard Contrastive Learning (e.g., SimCLR, MoCo), which requires contrasting positive pairs against massive amounts of negative pairs.
  2. Non-Contrastive Learning (e.g., BYOL, SimSiam), which discards negative pairs but relies on complex architectural tricks (like stop-gradients and asymmetric predictors) to avoid representation collapse.
  3. Whitening Regularization (e.g., Barlow Twins, VICReg), which uses feature decorrelation to prevent collapse.
  4. Consistency Regularization (e.g., CO2), which enforces similarity consistency across different data augmentations.

Because these methods rely on different motivations and mathematical formulations, understanding their underlying connections has been difficult. Additionally, contrastive methods suffer from the false negative problem (treating two different images of the same semantic class as a negative pair), while non-contrastive methods constantly battle the risk of trivial, collapsed solutions.

Methods

The core insight of UniCLR is that the relationships between two augmented views of a mini-batch can be entirely captured by an affinity matrix ($Z^T Z'$), where $Z$ and $Z'$ are the normalized feature representations of the two views.

Figure 1. Overall architecture of the proposed UniCLR framework. Given a mini-batch of raw images x, two sets of views X and X′ are obtained via data augmentation and then encoded into representations Z and Z′ through the weights-shared Siamese networks fθ or one of which fθema is updated with the exponential moving average (EMA) of fθ with a stop-gradient (i.e., sg) operation. The affinity matrix between Z and Z′ is finally calculated, forming the basis of the variants of UniCLR, i.e., SimAffinity, SimWhitening and SimTrace.

By manipulating this affinity matrix, the authors introduce three distinct baselines within the UniCLR framework:

  • SimAffinity: A streamlined contrastive baseline that applies cross-entropy loss directly to the affinity matrix. Unlike SimCLR, it only considers $N-1$ negative pairs instead of $2N-2$, making it computationally more efficient.
  • SimWhitening: Integrates feature whitening directly into the contrastive loss by incorporating the inverse of the feature covariance matrix ($\text{\Sigma}^{-1}$) into the affinity calculation ($Z^T \text{\Sigma}^{-1} Z'$).
  • SimTrace: A non-contrastive method that maximizes the mathematical trace of the whitened affinity matrix. Remarkably, SimTrace inherently prevents representation collapse without needing stop-gradients or asymmetric networks.

The Symmetric Consistency Loss

To tackle the false negative problem, the authors introduce a simple regularization term that enforces symmetry on the affinity matrix: $$\Gamma_{\text{Symmetry}} = \|Z^T Z' - Z'^T Z\|_F$$ This forces the cross-view positive-negative similarities to be consistent, preserving the relative similarities of semantically related images and preventing the model from receiving saturated gradients.

Datasets

The framework and its variants were validated on four standard benchmarks:

  • ImageNet-1K: The primary large-scale benchmark (1.2 million training images).
  • ImageNet-100: A 100-class subset of ImageNet used for rapid prototyping.
  • CIFAR-10 & CIFAR-100: Small-scale datasets used to evaluate performance and convergence behavior.

Key Insights and Ideas

  • The Affinity Matrix is the Universal Language of SSL: Seemingly disparate techniques are actually just applying different operations (like cross-entropy, whitening, or trace operations) to the exact same core matrix.
  • Whitening is a Double-Edged Sword: The authors discovered that whitening actually harms standard contrastive learning because decorrelation exacerbates the false negative problem. However, for non-contrastive learning (SimTrace), it is the exact mechanism that prevents representation collapse.
  • Symmetry Drives Fast Convergence: Forcing the affinity matrix to be symmetric acts as an incredibly effective consistency regularizer. It maintains stable relationships between a sample and its false negatives, which dramatically speeds up training.

Key Results

ImageNet-1K Performance

Under the standard linear evaluation protocol on ImageNet-1K (trained for 200 epochs), the UniCLR variants achieved state-of-the-art results:

  • SimAffinity achieved 73.8% top-1 accuracy, outperforming SimSiam (70.0%) and BYOL (70.6%). It even beat methods like Barlow Twins and VICReg that were trained for 1000 epochs.
  • SimTrace achieved 69.1% accuracy without any asymmetric designs (no stop-gradients, no extra predictors), proving that trace optimization over a whitened affinity matrix is sufficient to prevent collapse. Adding an asymmetric predictor pushed its performance to 71.7%.

Convergence Speedup

Ablation studies on CIFAR datasets demonstrated that the proposed symmetric loss significantly accelerates training. Models utilizing the symmetric loss converged much faster and achieved higher overall accuracy compared to baselines without it.

Figure 2. k-NN evaluation on CIFAR-10 and CIFAR-100. (a) Experimental results on CIFAR-10. (b) Experimental results on CIFAR- 100. SimAffinity w/o T, w/o S, and w/o T&S indicate SimAffinity without temperature, without symmetric loss, and without both parts, respectively. All models are trained for 200 epochs, and different colors denote different methods.

Limitations and Future Work

While UniCLR successfully unifies contrastive, non-contrastive, whitening, and consistency-based SSL, the authors note that it does not yet cover clustering-based SSL methods (such as SwAV or DeepCluster). The authors state that exploring how to elegantly integrate clustering mechanisms into this affinity matrix framework is the primary direction for their future research.

Summary updated

BibTeX
@misc{li2022unified,
  author = {Wenbin Li and Meihao Kong and Xuesong Yang and Lei Wang and Jing Huo and Yang Gao and Jiebo Luo},
  title = {{A Unified Framework for Contrastive Learning from a Perspective of Affinity Matrix}},
  year = {2022},
  eprint = {2211.14516},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2211.14516},
}
Figure