Conventional soft-max learns features that separate classes by probability, but not necessarily by angular distance—the metric most verification protocols use (cosine similarity). Previous margin-based ideas (SphereFace: multiplicative angular margin, CosFace: additive cosine margin) helped, yet:
CosFace imposed the margin in the cosine space, not directly on the angle.
ArcFace introduces a geometrically exact and implementation-friendly margin in the angular space and shows it can be dropped into any classification network to obtain state-of-the-art face recognition.
2. Core idea in one equation
For a feature x (L2-normalized) and a class weight Wᵧ (also normalized), the ordinary soft-max logit is
cos θᵧ = Wᵧ · x
ArcFace replaces it by adding an additive angular margin m to the target angle:
logitᵧ = s · cos(θᵧ + m)
logit_k = s · cos(θ_k) for k ≠ y
where
• s is a fixed scaling factor (≈ 64) stabilizing gradients.
• m is a small angle (≈ 0.5 rad, i.e., 30°) that forces extra separation.
This directly enforces that, during training, the decision boundary between classes is an arc of a circle lying m radians away from the ground-truth center, hence the name Arc-Face.
3. How does it differ from earlier margins?
Method
Margin type
Formula fragment (target logit)
Intuition
Soft-max
none
s·cos θ
probability separation
SphereFace
multiplicative angular
s·cos(m·θ)
angle amplified but hard to optimize
CosFace
additive cosine
s·(cos θ − m)
pushes in cosine space
ArcFace
additive angular (ours)
s·cos(θ + m)
exact geodesic margin on hypersphere
ArcFace keeps training stable (no annealing schedule), needs only a single hyper-parameter m, and aligns perfectly with the evaluation metric (cosine).
Backbones evaluated
• ResNet-50, ResNet-100, SE-ResNet-50, MobileFaceNet, etc.
Hyper-params (typical)
code
m = 0.5
s = 64
batch = 512
optimizer = SGD, lr 0.1 → 0.0001 (step decay)
Total training time: 8–14 h on 8× Tesla P40 for ResNet-100.
5. Results (headline numbers)
Benchmark (verification, 1:1)
Accuracy / TAR
Relative gain
LFW
99.83 %
+0.2 % vs prior SOTA
MegaFace (1 M distractors)
98.35 % (Rank-1)
+3.5 %
IJB-B (FPIR 1e-4)
94.2 %
+2.5 %
IJB-C (FPIR 1e-4)
95.6 %
+2.3 %
ArcFace became the first method to surpass 99.8 % on LFW using a single model.
6. Why does it work so well?
Angular margin exactly matches the test metric (cosine/angle), giving loss-metric consistency.
Feature and weight normalisation fixes the radius of the hypersphere, so only direction matters.
The additive margin shifts decision boundaries uniformly, making inter-class angles larger while keeping intra-class compact.
7. Practical adoption
• Implemented in nearly every open-source face toolkit (InsightFace, FaceNet, DeepFace, dlib, etc.).
• Works for speaker recognition, person-reID, product visual search—any embedding learned with cosine similarity.
• Often combined with tricks like Partial FC, AdaFace, SubCenter ArcFace for huge-scale training.
8. Quick PyTorch snippet
python
class ArcFace(nn.Module):
def __init__(self, in_features, n_classes, s=64.0, m=0.50):
super().__init__()
self.W = nn.Parameter(torch.randn(n_classes, in_features))
nn.init.xavier_uniform_(self.W)
self.s, self.m = s, m
self.cos_m = math.cos(m)
self.sin_m = math.sin(m)
self.th = math.cos(math.pi - m)
self.mm = math.sin(math.pi - m) * m
def forward(self, x, labels):
# L2 normalise
x = F.normalize(x)
W = F.normalize(self.W)
cosine = F.linear(x, W) # [B, C]
sine = torch.sqrt(1.0 - cosine**2)
phi = cosine * self.cos_m - sine * self.sin_m # cos(θ + m)
# where θ + m > π -> use cosine - mm for numerical stability
phi = torch.where(cosine > self.th, phi, cosine - self.mm)
one_hot = torch.zeros_like(cosine)
one_hot.scatter_(1, labels.view(-1,1), 1.0)
logits = self.s * (one_hot * phi + (1.0 - one_hot) * cosine)
return logits
Plug the logits into nn.CrossEntropyLoss() and train as usual.
9. Limitations & open questions
• Still needs large, clean, diverse data to generalise.
• Margin m is fixed across classes & instances—recent work explores adaptive or sample-aware margins.
• Ignores feature magnitude, which can encode confidence; AdaFace re-introduces it.
10. TL;DR
ArcFace injects a simple constant angular margin into soft-max, perfectly matching the cosine metric used in face recognition. This tiny tweak yields substantially more discriminative embeddings, is easy to implement, stable to train, and has become the default loss for modern face recognition systems.
Happy to dive deeper (e.g., training tricks, theoretical analysis, comparisons with newer losses) if you need more details! 😊