---
title: Class-Center Similarity Explained
url: https://www.emergentmind.com/topics/class-center-similarity-ccs
type: topic
---

# Class-Center Similarity Explained

Searching arXiv for the cited papers and closely related work on class-center similarity.
Class-Center Similarity (CCS) denotes a family of formulations in which prediction, supervision, or regularization is expressed through the relation between a feature representation and one or more class centers. A class center may be realized as a classifier weight vector, a learnable prototype, a running-average feature prototype, or a batch-estimated binary prototype, depending on the task and optimization regime. The term is not fully standardized across the literature: in semantic segmentation, CCS appears explicitly as a Class Center Similarity layer that reframes pixel-wise prediction as pixel-to-center similarity [2301.04870]; in contrastive-center learning, CCS can be defined through distances or contrastive ratios tied to class centers [1707.07391]; in fine-grained visual classification, the same underlying idea is implemented through sample-center and center-center cosine similarity without being formalized as a standalone term [2407.04243]; and in deep hashing, an analogous mechanism is presented as centers similarity learning rather than CCS [2103.09442].

## 1. Conceptual scope and formalization

At a high level, CCS replaces or augments direct class-logit reasoning with similarity to class representatives in embedding space. The general structure is consistent across tasks: a feature $x$ is compared against class centers $\{c_k\}$, and the training objective encourages high similarity to the target center together with low similarity to non-target centers. What changes across instantiations is the definition of the center, the similarity metric, and the update rule.

| Setting | Class center representation | Similarity mechanism |
|---|---|---|
| Semantic segmentation | Global classifier weights $w_j$ or scene-conditioned adaptive centers $c_k$ | Inner product for pixel-to-center, cosine for center-to-center |
| Contrastive-center learning | Learnable center $c_k$ per class | Squared Euclidean distance, contrastive ratio |
| Fine-grained visual classification | Running-average class-center feature $F_j$ | Cosine similarity for sample-center and center-center |
| Deep hashing | Learnable center $\mu_j$ and batch-wise binary prototype $u_j$ | Inner product or cosine via $\theta_{ij}$ and sigmoid likelihood |

In the segmentation formulation, the conventional $1\times 1$ convolution head already contains an implicit center structure: each weight vector of the segmentation head represents its corresponding semantic class in the whole dataset and can be regarded as the embedding of the class center. Pixel-wise classification then amounts to computing similarity between a pixel embedding and the class centers. This interpretation turns the classifier into a prototype matcher and motivates scene-conditioned center generation [2301.04870].

In contrastive-center learning, the center is a learnable parameter updated together with the network. The relevant quantity is not merely closeness to the target center, but a contrastive relation between the target-center distance and the aggregate distance to non-target centers. This yields CCS definitions such as
$$
S_{\mathrm{loss}}(x_i) = - \frac{\|x_i-c_{y_i}\|_2^2}{\left(\sum_{j\neq y_i}\|x_i-c_j\|_2^2\right)+\delta}
$$
and
$$
S_{\mathrm{ctr}}(x_i)=\frac{\left(\sum_{j\neq y_i}\|x_i-c_j\|_2^2\right)+\delta}{\|x_i-c_{y_i}\|_2^2+\delta},
$$
which encode intra-class compactness and inter-class separability in a single ratio [1707.07391].

Fine-grained visual classification adopts a different center semantics. There, a class center is a feature prototype $F_j\in\mathbb{R}^D$ representing the whole class, maintained by a running average of sample embeddings rather than gradient descent. CCS is instantiated as cosine similarity between a sample and its class center, and between class centers themselves. The most similar non-target class is selected by an $\arg\max$ over the center-center similarity matrix, which makes CCS a mechanism for identifying and penalizing the hardest confusions [2407.04243].

In deep supervised hashing, the center concept splits into two objects: learnable class centers $\mu_j$ and batch-wise estimated binary prototypes $u_j$. Here CCS is a logistic likelihood over center similarity scores
$$
\theta_{ij}=0.5\,u_i^\top \mu_j,
$$
or, in a continuous relaxation, via cosine. This couples classwise sample-to-center attraction with prototype-to-prototype concentration and repulsion [2103.09442].

A common misconception is to treat CCS as a single loss or a single metric. The literature instead shows a broader design pattern: CCS may be an inference layer, an auxiliary loss, a prototype update rule, or a center-to-center regularizer, and it may use inner product, cosine similarity, or squared Euclidean distance depending on the geometry of the task.

## 2. Pixel-to-center similarity in semantic segmentation

The segmentation formulation begins from two stated difficulties: large intra-class feature variation in different scenes and small inter-class feature distinction in the same scene. The central observation is that standard semantic segmentation already computes a form of CCS. Let the backbone output a feature map $F\in\mathbb{R}^{D\times N}$, where the feature of pixel $i$ is $f_i\in\mathbb{R}^D$. If the conventional segmentation head has $K$ class weights $W^c\in\mathbb{R}^{K\times D}$, with $j$-th row $w_j$, then the per-pixel, per-class score is
$$
s_{i,j}=w_j^\top f_i.
$$
Under the class-center view, each $w_j$ is a global class center learned across the dataset, and the classifier is a pixel-to-center similarity calculator [2301.04870].

The Class Center Similarity layer replaces the final $1\times 1$ convolution head with a three-stage pipeline. First, the Adaptive Class Center Module (ACCM) generates scene-conditioned adaptive centers $C\in\mathbb{R}^{K\times D}$. Second, the Similarity Calculation Module computes pixel-to-center and center-to-center similarities. Third, Class Distance losses increase inter-class separation and intra-class compactness at the scene level. ACCM aggregates scene features into coarse centers using a learned spatial weight map $M\in\mathbb{R}^{K\times N}$:
$$
C=\mathcal{A}(M\otimes F^\top),
$$
where $M\otimes F^\top$ yields $K\times D$ coarse centers by weighted spatial pooling per class channel, and $\mathcal{A}(\cdot)$ is implemented as a $1\times 1$ convolution that refines them into adaptive centers. The mask $M$ is predicted from $F$ and supervised by a Dice loss.

Prediction uses inner-product pixel-to-center similarity:
$$
s_{i,k}=f_i^\top c_k,
$$
followed by
$$
P(y_i=k\mid f_i)=\mathrm{softmax}_k(s_{i,k})=\frac{\exp(s_{i,k})}{\sum_{j=1}^K \exp(s_{i,j})}.
$$
For center-to-center similarity, the formulation uses cosine similarity with an absolute value in the numerator:
$$
\mathrm{sim}_{\cos}(c_p,c_q)=\frac{|c_p^\top c_q|}{\|c_p\|_2\|c_q\|_2}.
$$
The absolute value is introduced to encourage linear independence and remove norm influence.

The loss is built from a relative similarity
$$
RSimi(f_i,c_q)=\frac{\exp(Simi(f_i,c_q))}{\sum_{j=1}^K\exp(Simi(f_i,c_j))},
\quad Simi(f_i,c_q)=f_i^\top c_q,
$$
and a distance
$$
D(f_i,c_q)=-\log(RSimi(f_i,c_q)).
$$
The scene-level intra-class loss is
$$
\mathcal{L}^{scene}_{intra}
=
\sum_{q=1}^{K}\sum_{i=1}^{N}\mathbbm{1}[y_i=q]\left[-\log RSimi(f_i,c_q)\right].
$$
With inner-product similarity and softmax normalization, this recovers the standard cross-entropy form; cross-entropy is therefore a special case of the proposed intra-class distance loss. The scene-level inter-class loss penalizes high similarity between different adaptive centers:
$$
\mathcal{L}^{scene}_{inter}
=
\sum_{p=1}^{K}\sum_{q=1}^{K}\mathbbm{1}[p\neq q]\,
\exp\big(-\mathrm{sim}_{\cos}(c_p,c_q)\big).
$$
The complete objective is
$$
\mathcal{L}
=
\mathcal{L}^{scene}_{intra}
+
\alpha\,\mathcal{L}^{scene}_{inter}
+
\beta\,\mathcal{L}_{Dice},
$$
with
$$
\mathcal{L}_{Dice}
=
1-\frac{2\sum_{i=1}^{N}m_i^\top y_i}{\sum_{i=1}^{N}\|m_i\|_2^2+\sum_{i=1}^{N}\|y_i\|_2^2+\epsilon},
\quad \epsilon=1e^{-3}.
$$

This construction makes CCS both an inference mechanism and a structured regularizer. ACCM adapts class centers to scene content, the intra term contracts per-class pixel clouds toward scene-specific centers, and the inter term pushes centers apart inside the current image. The geometric interpretation given in the source is that pixels and class centers lie in an embedding space, adaptive centers align to local scene distributions, and clearer class-separation hyperplanes emerge as intra-class contraction and inter-class expansion proceed jointly [2301.04870].

## 3. Contrastive-center formulations in discriminative representation learning

In contrastive-center learning, CCS is grounded in a class-center objective rather than a prediction head. Let $x_i\in\mathbb{R}^d$ be the deep feature of sample $i$, $y_i\in\{1,\dots,K\}$ its label, and $c_k\in\mathbb{R}^d$ the learnable center for class $k$. Using squared Euclidean distance, define
$$
A_i=\|x_i-c_{y_i}\|_2^2,
\qquad
B_i=\sum_{j=1,j\neq y_i}^{K}\|x_i-c_j\|_2^2,
\qquad
D_i=B_i+\delta,
$$
with $\delta=1$ by default to prevent division by zero. The contrastive-center loss is
$$
L_{ct-c}
=
\frac{1}{2}\sum_{i=1}^{m}\frac{A_i}{D_i}
=
\frac{1}{2}\sum_{i=1}^{m}
\frac{\|x_i-c_{y_i}\|_2^2}
{\left(\sum_{j=1,j\neq y_i}^{K}\|x_i-c_j\|_2^2\right)+\delta}.
$$
Training uses the joint supervision
$$
L=L_s+\lambda L_{ct-c},
$$
where $L_s$ is the softmax cross-entropy [1707.07391].

Within this formulation, CCS can be defined in several ways. A pure target-center similarity is
$$
S_{dist}(x_i,y_i)=-\|x_i-c_{y_i}\|_2^2,
\qquad
S_{exp}(x_i,y_i)=\exp(-\|x_i-c_{y_i}\|_2^2).
$$
A contrastive CCS that explicitly includes non-target centers is
$$
S_{ctr}(x_i)
=
\frac{B_i+\delta}{A_i+\delta},
$$
and a loss-aligned CCS is
$$
S_{loss}(x_i)
=
-\frac{A_i}{B_i+\delta}.
$$
The source identifies $S_{loss}$ as the CCS most directly tied to the optimization objective and $S_{ctr}$ as a larger-is-better separation-focused metric.

The gradient structure makes the intended geometry explicit. For the per-sample contribution $f_i=\frac{1}{2}A_i/D_i$, the gradient with respect to the feature is
$$
\frac{\partial L_{ct-c}}{\partial x_i}
=
\frac{x_i-c_{y_i}}{D_i}
-
\frac{A_i\sum_{j\neq y_i}(x_i-c_j)}{D_i^2}.
$$
When $y_i=n$, center $c_n$ is attracted toward $x_i$; when $y_i\neq n$, $c_n$ is repelled from $x_i$ proportionally to $A_i/D_i^2$. The center update is
$$
c_n\leftarrow c_n-\alpha\frac{\partial L_{ct-c}}{\partial c_n},
$$
with a smaller dedicated learning rate $\alpha$ recommended for stability.

The relation to prior losses is sharply defined. Softmax cross-entropy optimizes classification boundaries but does not explicitly penalize distances to centers or enforce center separation. Center loss
$$
L_c=\frac{1}{2}\sum_{i=1}^{m}\|x_i-c_{y_i}\|_2^2
$$
improves intra-class compactness but ignores inter-class separability. Contrastive and triplet losses operate on pairs and triplets and require selection or mining. By contrast, contrastive-center loss uses class centers rather than pairs or triplets and explicitly balances intra-class compactness against inter-class separation with per-batch $O(mK)$ cost [1707.07391].

This framing suggests a broad interpretation of CCS: it need not be a similarity function in the narrow sense of a bounded score; it can also be a contrastive ratio or negative loss term that is monotone with desirable center geometry.

## 4. Fine-grained visual classification and exploration of class centers

Fine-grained visual classification uses class centers to address two stated problems: evident intra-class variances and subtle inter-class differences, together with overfitting from fewer training samples. The formulation defines a class center as a feature prototype $F_j\in\mathbb{R}^D$ representing class $j$. Unlike center-loss-based methods, these centers are not learnable parameters updated by gradient descent. Instead, each center is maintained by a running average with a per-class counter:
$$
F_{y_i}=\frac{X_i+C_{y_i}^{cur}F_{y_i}^{cur}}{C_{y_i}^{cur}+1},
\qquad
C_{y_i}=C_{y_i}^{cur}+1.
$$
Centers are randomly initialized before training and then deterministically updated per incoming sample [2407.04243].

Cosine similarity is used both for sample-center and center-center relations:
$$
\cos(a,b)=\frac{a^\top b}{\|a\|_2\|b\|_2},
\qquad
D_{cos}(a,b)=1-\cos(a,b).
$$
With $N$ classes, the center-center similarity matrix is $S\in\mathbb{R}^{N\times N}$ with entries
$$
s_{h,w}=\cos(F_h,F_w).
$$
For sample $X_i$ of class $y_i$, the most similar non-target class is selected as
$$
sim_{y_i}=\arg\max_{w\neq y_i}s_{y_i,w},
$$
and $s_{y_i,sim_{y_i}}$ serves both as a hardest-negative selector and as an adaptive weight.

The feature-side component is the multiple class-center constraint:
$$
L_{MCC}
=
\sum_{k=1}^{M}
\left[
D_{cos}(X_k,F_{y_k})
+
s_{y_k,sim_{y_k}}\cdot \cos(X_k,F_{sim_{y_k}})
\right].
$$
Equivalently,
$$
L_{MCC}
=
\sum_{k=1}^{M}
\left[
1-\cos(X_k,F_{y_k})
+
s_{y_k,sim_{y_k}}\cdot \cos(X_k,F_{sim_{y_k}})
\right].
$$
Minimizing this pulls each sample toward its target center while pushing it away from the most similar non-target center. The non-target term is stronger when the target class center is itself highly similar to another center, so repulsion is focused where inter-class confusion is greatest.

The label-side component is class-center label generation. For each class, the method maintains a running average of the final linear-layer logits:
$$
L_{y_i}
=
\frac{f(X_i)+C_{y_i}^{cur}L_{y_i}^{cur}}{C_{y_i}^{cur}+1}.
$$
Then
$$
P_{X_i}=\mathrm{softmax}(f(X_i)),
\qquad
Q_{y_i}=\mathrm{softmax}(L_{y_i}),
$$
and the regularization term is
$$
L_{CLG}
=
\sum_{k=1}^{M} KL(P_{X_k}\,\|\,Q_{y_k})
=
\sum_{k=1}^{M}\sum_{n=1}^{N}
p_{k,n}\log\frac{p_{k,n}}{q_{y_k,n}}.
$$
The total objective augments standard cross-entropy:
$$
L_{final}=L_{CE}+\lambda_1 L_{MCC}+\lambda_2 L_{CLG}.
$$

Two aspects distinguish this CCS formulation from earlier center-based losses. First, the centers are stabilized by averaging rather than by gradient updates, which the source associates with smooth, stable center evolution compared to large oscillations seen with center loss and its variants. Second, CCS operates simultaneously at the feature level and the label level: the multiple class-center constraint reduces intra-class variance and enlarges inter-class differences, while class-center label generation produces soft labels that reflect class-center distributions rather than uniform label smoothing [2407.04243].

The source explicitly notes that the paper does not formally name “Class-Center Similarity” as a standalone construct, but also states that a precise CCS formulation consistent with the method is intrinsic to the loss. In that sense, CCS here is less a named module than a unifying geometric principle.

## 5. Centers similarity learning for deep supervised hashing

In deep supervised hashing, CCS appears as centers similarity learning. The setting includes a feature embedding $h_i=f_\theta(x_i)\in\mathbb{R}^{L\times 1}$, a binary hash code $b_i=\mathrm{sign}(h_i)\in\{-1,1\}^L$, learnable class centers $\mu_j\in\mathbb{R}^{L\times 1}$, and batch-wise estimated binary prototypes $u_j\in\{-1,1\}^L$. The classwise objective uses a Gaussian-softmax form:
$$
L_{\mathrm{classwise}}(\Theta,M)
=
-\sum_{i=1}^{N}\sum_{j=1}^{C}
y_{ji}
\log
\frac{
\exp\left\{-\frac{\|h_i-\mu_j\|^2}{2\sigma^2}\right\}
}{
\sum_{k=1}^{C}
\exp\left\{-\frac{\|h_i-\mu_k\|^2}{2\sigma^2}\right\}
}.
$$
This term pulls samples toward their class centers in Euclidean space [2103.09442].

CCS proper is defined through a similarity likelihood between batch-wise binary prototypes and learnable centers. Let
$$
\theta_{ij}=0.5\,u_i^\top \mu_j,
$$
with an alternative interpretation through cosine,
$$
u_i^\top \mu_j
=
L\cdot \cos(u_i,\mu_j)
=
L\cdot \left(\frac{u_i^\top}{\|u_i\|}\right)\left(\frac{\mu_j}{\|\mu_j\|}\right).
$$
Define $s_{ij}\in\{0,1\}$ to indicate whether $u_i$ and $\mu_j$ correspond to the same class, and let $\rho(t)=1/(1+e^{-t})$. The likelihood is
$$
p(s_{ij}\mid u_i;\mu_j)
=
\begin{cases}
\rho(\theta_{ij}), & s_{ij}=1,\\
1-\rho(\theta_{ij}), & s_{ij}=0.
\end{cases}
$$
The resulting CCS loss is the negative log-likelihood
$$
L_{\mathrm{CCS}}(M)
=
\sum_{i=1}^{Z}\sum_{j=1}^{C}
\left[
\log(1+e^{\theta_{ij}})-s_{ij}\theta_{ij}
\right].
$$
A quantization penalty enforces proximity to the discrete codes:
$$
L_{\mathrm{quant}}(\Theta)=\sum_{i=1}^{N}\|b_i-h_i\|_2^2.
$$
The full objective is
$$
L_{\mathrm{total}}(\Theta,M)
=
L_{\mathrm{classwise}}(\Theta,M)
+
\gamma L_{\mathrm{CCS}}(M)
+
\beta L_{\mathrm{quant}}(\Theta).
$$

The method uses a two-step strategy. In the first step, a batch-wise binary center is estimated for each class appearing in the mini-batch by solving
$$
\min_{u_j\in\{-1,1\}^L}\sum_{k=1}^{n_j}\|u_j-b_{jk}\|_2^2,
$$
which is equivalent to bitwise voting with the closed-form solution
$$
u_{j,v}=\mathrm{sgn}\left(\sum_{k=1}^{n_j}b_{jk,v}\right).
$$
Running sums are maintained across iterations. In the second step, the learnable centers are concentrated toward their own batch-estimated prototypes and repelled from prototypes of other classes through $L_{\mathrm{CCS}}$.

The gradient of the CCS term with respect to a learnable center is
$$
\frac{\partial L_{\mathrm{CCS}}}{\partial \mu_j}
=
\frac{1}{2}\sum_{i=1}^{Z}u_i\left[\rho(\theta_{ij})-s_{ij}\right].
$$
This logistic form is described as providing stable gradients: for mismatched pairs, the gradient magnitude is controlled by $\rho(\theta_{ij})-s_{ij}$, which helps prevent degenerate collapse. The overall complexity is $O(b\cdot C+Z\cdot C)$ per batch, compared with $O(b^2)$ or $O(b^3)$ behavior in pairwise or triplet hashing [2103.09442].

CCS in this setting is therefore not a direct sample-to-class similarity for prediction. It is a prototype-to-prototype regularizer that reshapes the class-center geometry underlying the classwise hash loss.

## 6. Empirical behavior, limitations, and open directions

The empirical record attached to CCS is task-specific but internally consistent. In semantic segmentation, the CCS layer improves all tested heads on ADE20K with a ResNet-50 backbone: baseline FCN/PSP/DeepLabV3+ obtain $37.94/41.94/43.57$ mIoU, while adding CCS yields $43.57/44.07/44.25$ mIoU. On ADE20K validation with ResNet-101, DeepLabV3+ reaches $46.35$ mIoU and CCSNet reaches $47.76$ mIoU, a gain of $+1.41$; on Pascal Context with 59 classes, OCRNet reaches $54.8$ mIoU and CCSNet reaches $54.9$ mIoU. Ablations further show that Dice loss is the best supervision for the mask $M$, that the best reported configuration on ResNet-50 FCN is $\alpha=0.5,\beta=1.0$, and that a ground-truth mask upper bound produces $47.21$ mIoU and $84.12$ Acc, indicating substantial headroom when adaptive centers are perfectly localized. Qualitative evidence includes t-SNE visualizations showing compressed per-class clusters and enlarged margins between confusing classes such as “tree” and “plant,” as well as pixel-to-center distance histograms showing smaller intra-class distances and larger inter-class distances with adaptive centers than with global mean centers [2301.04870].

In contrastive-center learning, the reported results are likewise aligned with the intended geometry. On MNIST with $\lambda=0.1$, contrastive-center loss improves accuracy to $99.17\%$ versus softmax at $98.8\%$ and center loss at $98.94\%$; the visualization shows class centers are much more separated, with average $L_2$ distance to the “center of centers” of approximately $50$, about $3.3$–$5\times$ larger than with center loss. On CIFAR10, ResNet-20 with contrastive-center loss achieves $92.45\%$, above softmax at $91.25\%$ and center loss at $92.1\%$. On LFW, FRN trained with contrastive-center loss achieves $98.68\%$, compared with $97.47\%$ for softmax-only and $98.55\%$ for a retrained center-loss model [1707.07391].

In fine-grained visual classification, the exploration-of-class-center loss yields consistent improvements across datasets and backbones. With a ResNet50 backbone, the baseline versus ECC results are AIR $91.1\rightarrow 93.0$, CUB $84.7\rightarrow 87.3$, CAR $93.1\rightarrow 94.7$, and NAB $83.4\rightarrow 85.5$. The method also augments existing fine-grained pipelines: for example, CAL with ResNet101 improves from AIR $94.2$ to $95.2$ and CUB $90.6$ to $91.0$, while Swin Transformer improves from CUB $91.0$ to $92.3$. Ablations show that both the multiple class-center constraint and class-center label generation contribute, with the combined ECC objective performing best. The source also identifies failure modes: early unreliability of centers and distributions, the need to keep $\lambda_2$ smaller than $\lambda_1$ early in training, and the $O(N^2)$ cost of the center-center similarity matrix, which can be mitigated by periodic recomputation [2407.04243].

In deep hashing, IDCWH consistently surpasses DCWH across multiple datasets. On CIFAR-10 under the “mini” protocol, IDCWH achieves mAP values of $0.828/0.865/0.868/0.859$ at $12/24/32/48$ bits; under the “full” protocol, it reaches $0.964/0.969/0.967/0.968$; on CIFAR-100, it achieves $0.764/0.813/0.824/0.835$; and on MS-COCO, $0.732/0.760/0.764/0.770$ at $16/32/48/64$ bits. Removing CCS degrades mAP across all datasets and code lengths, with gains more pronounced at shorter code lengths. The source highlights practical limitations involving noisy prototype estimates under class imbalance, the growth of $O(b\cdot C)$ softmax cost when the number of classes becomes large, and sensitivity to noisy labels [2103.09442].

Taken together, these results support a common interpretation: CCS is a center-aware structuring principle for representation space. It may act through adaptive centers, contrastive ratios, cosine hardest-negative selection, or prototype-to-prototype logistic regularization, but in each case the central objective is the same: reduce intra-class variation while enlarging inter-class differences. A plausible implication is that CCS is best understood not as a single algorithm but as a reusable geometric template spanning dense prediction, classification, metric learning, and retrieval. Open directions explicitly proposed in the segmentation literature include transformer or hybrid backbones, dynamic center update strategies such as EMA of centers across scenes or memory banks, contrastive pretraining on pixel-center pairs and center-center negatives, and adaptive temperature scaling in the softmax for relative similarity [2301.04870].

Source: https://www.emergentmind.com/topics/class-center-similarity-ccs