Papers
Topics
Authors
Recent
Search
2000 character limit reached

Contrastive-center Loss for Classification

Updated 23 March 2026
  • Contrastive-center Loss is an auxiliary supervision objective that promotes intra-class compactness and inter-class separability by using a ratio of distances in feature space.
  • It augments standard softmax loss by penalizing the ratio between the distance to the correct class center and aggregated distances to other centers, streamlining training without sample mining.
  • Empirical results on datasets like MNIST, CIFAR-10, and LFW indicate measurable gains over traditional losses, enhancing both classification accuracy and feature discrimination.

Contrastive-center loss is an auxiliary supervision objective designed for deep neural networks, most notably in image classification and face recognition tasks. It introduces “class centers” in feature space and enforces desirable intra-class compactness and inter-class separability by directly penalizing the ratio between the distance of a feature to its correct class center and the sum of its distances to all other class centers. This approach augments the standard softmax loss and enhances the discriminative quality of learned features, operating in a manner distinct from both classical center loss and contrastive loss approaches (Qi et al., 2017).

1. Formal Definition and Mathematical Structure

Let mm denote the mini-batch size, kk the number of classes, and dd the feature dimension. For each input sample xiRdx_i \in \mathbb{R}^d with label yi{1,,k}y_i \in \{1,\dots,k\} and class centers cjRdc_j \in \mathbb{R}^d, the loss terms are defined as follows:

  • Ai=xicyi2A_i = \Vert x_i - c_{y_i} \Vert^2 (squared distance to its corresponding true class center)
  • Bi=jyixicj2+δB_i = \sum_{j \neq y_i} \Vert x_i - c_j \Vert^2 + \delta (sum of squared distances to all other class centers, stabilized by constant δ>0\delta > 0)

The contrastive-center loss is defined as:

Lctc=12i=1mAiBiL_{ctc} = \frac{1}{2} \sum_{i=1}^m \frac{A_i}{B_i}

In practice, a joint loss is deployed:

kk0

where kk1 is the standard cross-entropy and kk2 scales the contribution of the auxiliary loss.

2. Mechanism: Intra-Class Compactness and Inter-Class Separability

The ratio kk3 couples the goals of intra-class compactness and inter-class separability in a single term:

  • Intra-class compactness: The numerator, kk4, increases if an embedding kk5 deviates from its true class center kk6. Minimization directly contracts class clusters in feature space.
  • Inter-class separability: The denominator, kk7, aggregates the squared distances to all non-corresponding class centers. If kk8 approaches an incorrect center, kk9 diminishes, inflating the loss and imposing a repulsive penalty that enhances class separation.
  • Joint effect: Minimizing this ratio for all samples simultaneously tightens clusters and maximizes inter-cluster gaps. The geometric interpretation is that each loss term is the sample’s intra-center distance "normalized" by its inter-cluster distance, providing scale-invariant enforcement.

3. Optimization Dynamics: Gradients and Center Updates

Given the composite structure, gradients with respect to both network parameters (via dd0) and the learned centers dd1 are essential for training:

  • Sample gradients:

dd2

The update pulls dd3 towards its center and pushes away from incorrect centers proportionally to dd4.

  • Center gradients:

dd5

Each center is adjusted by a batch-accumulated term and updated after each batch via a distinct learning rate dd6:

dd7

This optimization scheme decouples center motion from main network learning rates, stabilizing training.

4. Hyperparameterization and Training Practices

Three principal hyperparameters govern practical application:

  • dd8 (denominator shift): Prevents division by zero; default dd9 is robust across settings.
  • xiRdx_i \in \mathbb{R}^d0 (contrastive-center loss weight): Adjusts the relative influence of xiRdx_i \in \mathbb{R}^d1; typical values are xiRdx_i \in \mathbb{R}^d2 for generic classification (MNIST, CIFAR-10) and xiRdx_i \in \mathbb{R}^d3 for verification (LFW, CASIA-WebFace). Higher xiRdx_i \in \mathbb{R}^d4 can cause over-separation, hurting primary classification metrics.
  • xiRdx_i \in \mathbb{R}^d5 (center learning rate): Typically in the range xiRdx_i \in \mathbb{R}^d6, chosen to be smaller than main network learning rate to avoid center instability.

Tuning proceeds by setting xiRdx_i \in \mathbb{R}^d7, initializing a moderate xiRdx_i \in \mathbb{R}^d8, and adaptively adjusting xiRdx_i \in \mathbb{R}^d9 and yi{1,,k}y_i \in \{1,\dots,k\}0 based on validation performance and observed convergence behavior.

5. Training Algorithm: Stepwise Pseudocode and Workflow

The contrastive-center loss augments a standard deep learning training loop without necessitating sample mining. The typical training iteration per mini-batch is:

yi{1,,k}y_i \in \{1,\dots,k\}7

Centers are initialized to zero or randomly, and update rules are carried out per expressions in section 3.

6. Empirical Performance and Quantitative Evidence

Across a series of benchmarks, contrastive-center loss demonstrates consistent improvements over both vanilla softmax classification and the original center loss:

Dataset/Task Softmax Center Loss Contrastive-center Loss
MNIST (LeNets++) 98.80% 98.94% 99.17%
CIFAR-10 (ResNet) 91.25% 92.10% 92.45%
LFW (CASIA-WebFace) 97.47% 98.55% 98.68%

Visualization on low-dimensional MNIST features shows an order-of-magnitude increase in average inter-center distance (yi{1,,k}y_i \in \{1,\dots,k\}1 for contrastive-center vs. yi{1,,k}y_i \in \{1,\dots,k\}2–yi{1,,k}y_i \in \{1,\dots,k\}3 for center loss), confirming enhanced cluster separation (Qi et al., 2017).

7. Practical Considerations and Applicability

  • Computational cost: Calculating yi{1,,k}y_i \in \{1,\dots,k\}4 is yi{1,,k}y_i \in \{1,\dots,k\}5 per sample, which may be prohibitive for extremely large yi{1,,k}y_i \in \{1,\dots,k\}6. In such settings, negative center sub-sampling is feasible.
  • Robustness: The method requires no sample mining, unlike traditional contrastive or triplet loss, streamlining training implementation.
  • Stability: Slow center updates are crucial; overly fast updates cause oscillation in center positions.
  • Synergy: Contrastive-center loss can be combined seamlessly with any backbone architecture and head, including CNN, ResNet, or any classifier based on softmax or margin variants.
  • Interpretation: The numerator-denominator form provides a clear geometric mechanism for enforcing compactness and separability without explicit reliance on sampling strategies.

The contrastive-center loss presents a straightforward yet effective auxiliary objective, yielding superior discriminative features and measurable gains in both image classification and face verification contexts, as substantiated by comprehensive comparative experiments (Qi et al., 2017).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Contrastive-center Loss.