The Problem: Learning a Good Face Space
A face recognition network turns a face into an embedding, a list of numbers (512 in Ollie's case). The goal is a space where photos of the same person land close together and different people land far apart. The loss function is how training measures progress toward that goal.
Before 2017, two approaches dominated:
- Contrastive loss looked at pairs of photos: pull same-person pairs together, push different-person pairs apart beyond a margin. See contrastive loss explained.
- Triplet loss, made famous by Google's FaceNet in 2015, looked at three photos at a time: an anchor, a positive of the same person and a negative of someone else.
Both work, but both need careful selection of hard pairs or triplets, and the number of possible combinations explodes with dataset size. Training was slow and finicky.
The Classifier Trick
The alternative was to train the network as a classifier: give it photos of 85,000 people and ask it to say which person each photo shows, using an ordinary softmax layer. After training, throw away the classifier and keep the embedding layer.
Plain softmax has a weakness. It only needs each photo to score highest for the right person. It doesn't care whether the margin is huge or razor-thin. The resulting embeddings separate the training identities, but not with enough room to spare for new faces.
The fix was to normalise everything and think in angles. If both the embedding and each person's classifier weight vector are scaled to length 1, the classifier score is just the cosine of the angle between them. Each person's weight vector acts like a centre for that identity on the surface of a sphere. Now you can demand a margin.
Read more: What Is Facial Embedding? The Technology Behind Celebrity Matching
Three Ways to Add a Margin
Three closely related papers added a margin in slightly different ways. With θ as the angle between a face's embedding and its true identity's centre:
| Method | Year | Margin applied as | Typical setting |
|---|---|---|---|
| SphereFace (A-Softmax) | 2017 | Multiply the angle: cos(m·θ) | m = 4 |
| CosFace (Large Margin Cosine Loss) | 2018 | Subtract from the cosine: cos(θ) − m | m = 0.35, scale s = 64 |
| ArcFace (Additive Angular Margin) | 2019 | Add to the angle: cos(θ + m) | m = 0.5, scale s = 64 |
In each case, the right answer is made artificially harder during training. The network can only win by pulling each face much closer to its identity's centre than strictly necessary, which leaves clear gaps between people.
ArcFace's version has a neat geometric meaning: the margin is a fixed distance along the surface of the sphere (an arc, hence the name). That makes the gap between identities the same everywhere, and in practice ArcFace trained a little more stably and scored slightly better than the others.
The Results
Jiankang Deng, Jia Guo, Niannan Xue and Stefanos Zafeiriou published ArcFace at CVPR 2019. Trained on MS1MV2 with a ResNet-100 backbone, it reached 99.83% on LFW, around 98% on the cross-age AgeDB-30 and the front-to-profile CFP-FP, and strong results on the much harder IJB-B and IJB-C benchmarks. The team released code and models through the InsightFace project, which helped ArcFace become the default choice for years.
The loss is also cheap. There's no pair or triplet mining. Each photo is processed once per step like any classification problem, which makes training on millions of images straightforward.
Get new guides by email
Why Ollie Uses CosFace
Ollie's 20-layer network was trained with CosFace (s = 64, m = 0.40) rather than ArcFace. The two give very similar embeddings, and CosFace has a practical advantage: because it simply subtracts a constant from the cosine, it's simpler and very stable, with no special handling needed when angles get large. For a model trained from scratch on a single consumer GPU, that stability was worth more than the small difference in benchmark scores.
The result scores 99.5% on LFW, with LFW identities removed from training first. For more on the full model, see how Ollie works.
Limits and Later Work
Margin losses assume clean labels. Web-scraped datasets contain mistakes, and a hard margin can force the network to cram mislabelled photos into the wrong cluster. Later methods such as Sub-center ArcFace (2020) give each identity several centres so noisy photos can sit apart, and AdaFace (2022) adjusts the margin based on image quality so blurry photos aren't punished as hard.
The core idea has held up: normalise, think in angles and demand a margin. Most face models in use today are trained with ArcFace, CosFace or one of their descendants.
