Paper commentary
SphereFace: Deep Hypersphere Embedding for Face Recognition
Angular softmax loss learns hypersphere features that make faces easier to match
- Problem Softmax-trained face features do not reliably meet the open-set criterion that same-person distances stay below different-person distances. Earlier fixes added Euclidean margin losses that need pair mining or only pull classes toward centers.
- Method SphereFace uses an angular softmax loss that adds an integer margin m on angles, not Euclidean distances. Each class must satisfy a stricter angle condition on a hypersphere, and m=4 is the default.
- Results A single model trained on CASIA-WebFace reaches 99.42% on LFW and 95.0% on YTF. Softmax reaches 97.88% and 93.1% under the same 64-layer setup.
Why open-set face recognition needs angular structure
Face recognition here is tested under an open-set protocol, where the test identities are disjoint from the training identities. A classifier trained on known identities cannot be applied to them directly, so the network has to produce a feature space in which distance decides identity.
The target criterion is that the largest distance between two images of one person should be smaller than the smallest distance between images of different people. Meeting this criterion makes nearest neighbor matching exact in principle, but it is hard to learn because faces vary widely within one identity and resemble each other across identities.
Softmax features are separable but often not discriminative enough, so earlier systems added Euclidean margin losses such as contrastive, triplet or center loss on top of softmax. Contrastive and triplet losses rely on pair or triplet mining, and center loss only pulls each class toward its center.
The authors observe that softmax-trained features already have an angular distribution, which makes a Euclidean margin an awkward fit. They therefore propose to place the margin on angles instead of on Euclidean distances.
What the softmax decision depends on
In the binary case the class posteriors are built from exponentials of \(W_i^Tx+b_i\), so the label is decided by comparing the two linear scores. The decision boundary is \((W_1-W_2)x+b_1-b_2=0\), where \(x\) is the learned feature and \(W_i\), \(b_i\) belong to the last fully connected layer.
Writing each score as \(\|W_i\|\|x\|\cos\theta_i+b_i\) turns it into a norm-weighted cosine of the angle between \(W_i\) and \(x\). Fixing \(\|W_i\|=1\) and \(b_i=0\) leaves only the two angles, so the boundary becomes \(\cos\theta_1-\cos\theta_2=0\), the bisector of the two weight vectors.
With the same normalization in the multi-class case, the modified softmax loss is \[L_{modified}=\frac{1}{N}\sum_i -\log\frac{e^{\|x_i\|\cos\theta_{y_i,i}}}{\sum_j e^{\|x_i\|\cos\theta_{j,i}}}\] where \(N\) is the number of training samples. The weights are renormalized in every iteration, and the biases are zeroed.
This loss yields angularly distributed features, but those features are not necessarily discriminative. That gap is why the authors add a margin on the angles rather than changing the normalization further.
How the angular margin enters the loss
For class 1 the rule \(\cos\theta_1>\cos\theta_2\) is replaced by \(\cos(m\theta_1)>\cos\theta_2\), with an integer \(m\ge 2\), and class 2 uses \(\cos(m\theta_2)>\cos\theta_1\). A sample must now lie closer to its own weight than before, so the decision is stricter. This stricter comparison is valid on the first interval \([0,\pi/m]\), so the method needs an extension beyond it.
With all training samples classified correctly, the boundaries leave an angular margin of \(\frac{m-1}{m+1}\theta_{12}\), where \(\theta_{12}\) is the angle between \(W_1\) and \(W_2\). The margin grows with \(m\) and is zero when \(m=1\), which recovers the modified softmax loss.
On the first interval \(\psi\) equals \(\cos(m\theta)\), so the extension keeps the margin where it was defined.
The full A-Softmax loss is \[L_{ang}=\frac{1}{N}\sum_i -\log\frac{e^{\|x_i\|\psi(\theta_{y_i,i})}}{e^{\|x_i\|\psi(\theta_{y_i,i})}+\sum_{j\ne y_i}e^{\|x_i\|\cos\theta_{j,i}}}\]. Replacing the angles by expressions in \(W\) and \(x\) through the multi-angle formula lets the gradients be taken with respect to \(x\) and \(W\), as for ordinary softmax, and this is why \(m\) must be an integer.
Reading the margin as a constraint on a hypersphere
With \(\|W_1\|=\|W_2\|=1\), the angles \(\theta_1\) and \(\theta_2\) equal the arc lengths \(\omega_1\) and \(\omega_2\) on the unit hypersphere. The class 1 boundary becomes \(m\omega_1=\omega_2\), and the region that classifies a sample as class 1 is \(m\omega_1<\omega_2\).
In 2D this is an arc-length constraint on a unit circle, and in 3D it is a circle-like region on a unit sphere. A larger \(m\) shrinks each class region, so the constraint sits on the manifold itself rather than in Euclidean space, where the Euclidean margin losses act.
The authors use this geometry to connect the learned features with the assumption that face images lie on a manifold, and they state that the features then behave under geodesic distance on the hypersphere. This connection is the authors' argument; the experiments test whether the angular constraint improves recognition.
How large m must be
The authors define m_min as the smallest value such that, for every m above it, the maximal intra-class angular distance is smaller than the minimal inter-class angular distance. The bounds are derived by requiring this inequality for each class.
In the binary case the maximal intra-class angle of class 1 is \(\frac{\theta_{12}}{m-1}+\frac{\theta_{12}}{m+1}\), and the minimal inter-class angle is \(\frac{(m-1)\theta_{12}}{m+1}\). Two inequalities, split at \(\theta_{12}\le\frac{m-1}{m}\pi\), are solved to give \(m_{\min}\ge 2+\sqrt{3}\).
For more than two classes, the bound assumes the class weights are uniformly spaced in Euclidean space, so the angle between neighbouring weights is \(2\pi/k\) for \(k\) classes with \(k\ge 3\). Solving the resulting inequality gives \(m_{\min}\ge 3\).
The authors use \(m=4\) to approximate the desired feature distribution, since it lies above both bounds. They also report that larger \(m\) tended to work better and that \(m=4\) usually suffices, and \(m=4\) is the default in their experiments.
Training data, preprocessing and matching
Face landmarks are detected with MTCNN, faces are cropped by a similarity transformation, and each RGB pixel in [0, 255] is normalized by subtracting 127.5 and dividing by 128.
The CNNs are trained on CASIA-WebFace after excluding identities that appear in the test sets, which leaves 494,414 face images of 10,575 individuals. The authors note that this is 0.49M images, small compared with DeepFace at 4M, VGGFace at 2M and FaceNet at 200M. Horizontally flipped copies of the training faces are used for augmentation.
Models are implemented in Caffe, use residual units, and are built with 4, 10, 20, 36 or 64 convolution layers. Training uses batches of 128 on four GPUs, with a learning rate starting at 0.1 that is divided by 10 at 16K and 24K iterations and training that finishes at 28K iterations.
At test time the output of the FC1 layer is the face feature, and the representation of a face is the concatenation of its feature with that of its flipped copy. Features are compared by cosine distance, with nearest neighbor for identification and a threshold for verification.
Effect of the margin size m
A toy experiment trains A-Softmax on six individuals with the most samples in CASIA-WebFace, with a three-dimensional FC1 output. The angular margin in the figure is -1.41 at m=1, -0.12 at m=2, 0.53 at m=3 and 0.66 at m=4.
On LFW and YTF with the 64-layer CNN, the accuracy rises with m: 97.88 for original softmax, then 97.90, 98.40, 99.25 and 99.42 for m=1 to 4 on LFW. On YTF the same settings give 93.1, 93.2, 93.8, 94.4 and 95.0.
Most of the rise on LFW therefore appears as m grows beyond 1, and the authors read this as larger angular margin giving stronger discrimination.
Effect of network depth
A-Softmax with m=4 and original softmax are trained on CNNs with 4, 10, 20, 36 and 64 convolution layers, using the architectures in Table 2.
On YTF, A-Softmax scores 93.4, 93.7, 94.1, 94.3 and 95.0, against 91.1, 92.0, 92.6, 92.9 and 93.1 for softmax.
A-Softmax exceeds the softmax models by 1.54% to 1.91% across the five depths. The authors attribute the larger gain for deeper networks to A-Softmax making fuller use of the learning capacity of deeper architectures, while the deeper standard CNNs improve less and saturate.
Comparison with other losses and published systems
Under the same 64-layer CNN trained on CASIA-WebFace, SphereFace reaches 99.42% on LFW and 95.0% on YTF. The other losses in that setting are softmax at 97.88 and 93.1, softmax with contrastive loss at 98.78 and 93.5, triplet loss at 98.70 and 93.4, L-Softmax at 99.10 and 94.0, and softmax with center loss at 99.05 and 94.4.
Among published systems trained on WebFace, the table lists Yi et al. at 97.73 and 92.2, Ding et al. at 98.43 on LFW, and Liu et al. at 98.71 on LFW. The authors describe the SphereFace result as the best reported for a model trained on WebFace.
Systems trained on private data use very different scales, such as DeepFace with 4M images and FaceNet with 200M. The authors note that their single model is only below Google FaceNet, which uses more than 200 million images, so these rows come from other training regimes and are not a controlled comparison.
MegaFace identification and verification
MegaFace has a gallery of more than 1 million images from 690K individuals, and its probe set comes from FaceScrub and FGNet.
The 3-patch ensemble concatenates three patch features without PCA and reaches 75.766 rank-1 and 89.142 verification. The single model reaches 72.729 rank-1 and 85.561 verification. The ensemble beats the second-best result by 4.8% in rank-1 identification and 6.3% in verification.
Against models trained on large datasets, the authors report margins of 0.64% for identification and 1.4% for verification. Under the same CNN and training set, softmax reaches 54.855 rank-1 and 65.925 verification, softmax with contrastive loss 65.219 and 78.865, triplet loss 64.797 and 78.322, and L-Softmax 67.128 and 80.423.
Limitations
The lower bounds on m_min are not claimed to be tight, and a tighter lower bound and an upper bound are left to future work.
The multi-class bound depends on the assumption that class weights are uniformly spaced in Euclidean space, and the paper does not check this assumption for weights learned in training.
The training data is CASIA-WebFace, which the authors describe as relatively small and having noisy labels. Comparisons with systems trained on private datasets therefore differ in training data as well as method.
The MegaFace headline numbers use the 3-patch ensemble, while the LFW and YTF results are for a single model.
Paper info
- Authors
- Weiyang Liu, Yandong Wen, Zhiding Yu, Ming Li, Bhiksha Raj, Le Song
- Venue
- arXiv · Preprint
- First published
- 2017-4-26
- Added
- 2026-11-12
- Updated
- 2018-1-29
- Version
- v4
- arXiv
- 1704.08063
- Category
- cs.CV
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Weiyang Liu, Yandong Wen, Zhiding Yu, Ming Li, Bhiksha Raj, Le Song (2017). SphereFace: Deep Hypersphere Embedding for Face Recognition. arXiv:1704.08063v4. https://arxiv.org/abs/1704.08063v4
BibTeX
@misc{liu2017sphereface,
title = {{SphereFace: Deep Hypersphere Embedding for Face Recognition}},
author = {Weiyang Liu and Yandong Wen and Zhiding Yu and Ming Li and Bhiksha Raj and Le Song},
year = {2017},
eprint = {1704.08063},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1704.08063v4}
}