---
title: Dual Sigmoid Loss for Face Recognition
url: https://www.emergentmind.com/topics/dual-sigmoid-loss
type: topic
---

# Dual Sigmoid Loss for Face Recognition

Dual Sigmoid Loss, as introduced in the SFace (“Sigmoid-Constrained Hypersphere Loss”) framework, is a loss formulation for deep face recognition that decouples the intra-class “pull” and inter-class “push” forces by modulating their gradient contributions with two independent, parameterized sigmoid functions. This construction allows for explicit control over where and how strongly each sample is encouraged to cluster with its class center or to separate from other classes on the unit hypersphere. By tuning these dual sigmoids, SFace mitigates overfitting, especially in the presence of noisy or low-quality training data, and achieves robust, discriminative face embeddings [2205.12010].

## 1. Mathematical Formulation and Notation

The embedding $x_i \in \mathbb{R}^d$ of input $X_i$ is produced by the network and both $x_i$ and each class center $W_j$ (the columns of the last-layer weight matrix $W \in \mathbb{R}^{d \times C}$) are $\ell_2$-normalized: $\|x_i\| = \|W_j\| = 1$. The angular similarity between $x_i$ and $W_j$ is given by $\cos \theta_j = W_j^\top x_i$ and $\theta_j = \arccos(W_j^\top x_i)$.

The SFace loss for $x_i$ is:
$$
L_{SFace}(x_i) = L_{intra}(\theta_{y_i}) + \sum_{j \ne y_i} L_{inter}(\theta_j)
$$
where
$$
L_{intra}(\theta) = -[r_{intra}(\theta)]_b \cdot \cos \theta
$$
$$
L_{inter}(\theta) = +[r_{inter}(\theta)]_b \cdot \cos \theta
$$
The $[\cdot]_b$ operator is the block-gradient, meaning the value is used in the forward pass but not differentiated through during backpropagation.

## 2. Dual Sigmoid Re-Scale Functions

SFace employs two independent sigmoid functions to modulate the intra-class and inter-class gradient scales as a function of angle $d = \theta$:

- **Intra-class (pull) re-scale:**
  $$
  r_{intra}(d) = s \cdot \sigma_{intra}(d)
  $$
  $$
  \sigma_{intra}(d) = \frac{1}{1+\exp[-a_{intra}(d-b_{intra})]}
  $$
  - $a_{intra}$ controls sharpness; $b_{intra}$ is the inflection (“onset”) angle; $s$ is a global scale (commonly 64).
  - For $d \ll b_{intra}$, intra-class pull is suppressed; above $b_{intra}$, it ramps up.
- **Inter-class (push) re-scale:**
  $$
  r_{inter}(d) = s \cdot [1 - \sigma_{inter}(d)]
  $$
  $$
  \sigma_{inter}(d) = \frac{1}{1+\exp[-a_{inter}(d-b_{inter})]}
  $$
  - $a_{inter}$, $b_{inter}$ parameterize slope and margin.
  - For $d \ll b_{inter}$, inter-class push is strong; for $d \gg b_{inter}$, push is negligible.

These dual sigmoids allow fine-grained, decoupled control: one can enforce tight clustering for clean data (low $b_{intra}$), but increase $b_{intra}$ to halt “pull” early in noisy scenarios and avoid overfitting.

## 3. Gradient Modulation and Optimization Behavior

Only the cosine terms receive backpropagated gradients; the sigmoid re-scales act as fixed coefficients during each update. Specifically,
$$
\frac{\partial L_{intra}}{\partial \cos \theta} = -r_{intra}(\theta)
$$
$$
\frac{\partial L_{inter}}{\partial \cos \theta} = r_{inter}(\theta)
$$
Since $\frac{\partial \cos \theta}{\partial \theta} = -\sin \theta$, the gradient magnitudes with respect to $\theta$ are
$$
v_{intra}(\theta) = r_{intra}(\theta) \sin \theta \, , \quad v_{inter}(\theta) = r_{inter}(\theta) \sin \theta
$$
Thus, SFace directly determines the effective angular “pull” or “push” based on how far samples are from the decision margins, defined by the chosen $b_{intra}$ and $b_{inter}$.

## 4. Parameter Tuning and Loss Behavior Under Noise

Parameter selection critically shapes the embedding geometry:

- **$b_{intra}$**: Sets the “target” intra-class angle. Higher $b_{intra}$ increases noise tolerance by ceasing intra-class pull earlier, making embeddings looser; lower values enforce tighter clusters.
- **$a_{intra}$**: Controls gradient sharpness at the intra-class boundary.
- **$b_{inter}$**: Sets the angular margin for inter-class separation; typical values are $1.2$–$1.3$ radians ($\approx 69^\circ–75^\circ$).
- **$a_{inter}$**: Slopes chosen so the transition region is narrow but not a step (e.g., $a_{·}=80$).

In practice, higher $b_{intra}$ values help SFace prevent overfitting when label noise increases, as noisy samples are not forcefully incorporated into incorrect clusters. On clean datasets, lower $b_{intra}$ supports compact representations.

| Scenario                  | $b_{intra}$ (example) | $b_{inter}$ (example) | Impact                                     |
|---------------------------|----------------------|----------------------|---------------------------------------------|
| Clean (little noise)      | 0.80                 | 1.20                 | Tight clusters, clear separation            |
| Noisy (label noise grows) | 0.84                 | 1.20                 | Early pull-off, less overfitting to noise   |

## 5. Comparison to Other Hypersphere Margin Losses

Traditional angular-margin losses (SphereFace, CosFace, ArcFace) impose margin constraints via additive or multiplicative angular shifts:
- SphereFace: $f(\theta) = \cos(m\theta)$,
- ArcFace: $f(\theta) = \cos(\theta + m)$,
- CosFace: logit margin-shifting by $m$.

Gradients in those schemes involve implicit, coupled re-scale factors $r^{softmax}_{intra}$ and $r^{softmax}_{inter}$ that depend on all logits simultaneously and cannot be independently tuned. SFace’s design offers explicit, independent re-scaling for intra- and inter-class terms, and operates solely on single angles (not mixtures thereof), thus simplifying tuning and offering robust performance under non-ideal data conditions.

## 6. Implementation Details

A standard SFace pipeline consists of:

- Network (e.g., ResNet50) generating a $d$-dimensional feature vector per sample, followed by $\ell_2$ normalization.
- Last-layer weights $W \in \mathbb{R}^{d \times C}$, columns $\ell_2$-normalized per forward pass.
- For each sample, compute $\cos \theta_j = W_j^\top x_i$ and $\theta_j$ via $\arccos$.
- Compute $r_{intra}$ and $r_{inter}$ via the parameterized sigmoid functions, with gradients blocked.
- Loss assembly: $L = -r_{intra}(\theta_{y_i}) \cos \theta_{y_i} + \sum_{j\ne y_i} r_{inter}(\theta_j) \cos \theta_j$
- SGD updates are applied to both $W$ and network parameters.

## 7. Empirical Results and Significance

SFace demonstrates competitive or superior accuracy and robustness across diverse benchmarks:

- On MS1MV2 with ResNet100 and $(a_{intra}=80, b_{intra}=0.90, a_{inter}=80, b_{inter}=1.20, s=64)$:
  - LFW: 99.82% (ArcFace 99.83%)
  - YTF: 98.06% (ArcFace 98.02%)
  - MegaFace: Top-1 = 98.50% (ArcFace 98.35%), TAR@FAR = 98.61% (ArcFace 98.48%)
  - IJB-C: 1:1 TAR@FAR=1e-5–1e-1 improved over ArcFace by 0.5–1%
- Under increasing label-noise (WebFace, 0–20%), SFace’s accuracy degrades more gracefully than ArcFace or CosFace, as $b_{intra}$ is increased to limit the effect of noisy samples.
- On IJB-A and IJB-C, SFace consistently outperforms ArcFace by 0.2–0.5% at low FAR and in Rank-1/TPIR metrics.

This suggests that the decoupled, sigmoidal gradient modulation offers a robust means to balance discriminative training against overfitting, particularly with imperfect data [2205.12010].

Source: https://www.emergentmind.com/topics/dual-sigmoid-loss