ArcFace: Additive Angular Margin Loss for Deep Face Recognition
- Publication
- IEEE Transactions on Pattern Analysis and Machine Intelligence 2022Journal
- First submitted to arXiv
- arXiv:1801.07698
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{facerecognitionarcface2018,
title = {{ArcFace: Additive Angular Margin Loss for Deep Face Recognition}},
author = {Jiankang Deng and Jia Guo and Jing Yang and Niannan Xue and Irene Kotsia and Stefanos Zafeiriou},
year = {2018},
eprint = {1801.07698},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1801.07698}
}
This was an eventful year for face recognition.
Metric learning predates this period, but margin-based face-recognition losses developed quickly then: from A-Softmax to CosFace, and now ArcFace. This series of losses aims to address the margin problem in face recognition.
Problem Definition
Let’s dive straight into the explanation, beginning with Softmax:
Here, contains class logits; is the input feature vector, is the class of the -th image, is the number of classes, and is the batch size.
Typically, is the output score of a fully connected layer, which can be represented as , where is the weight of the fully connected layer, and is the bias term.
When we set , we get , which can be written as the dot product:
Here, is the angle between and .
So far, we haven’t changed anything—we’re just describing the computation process of the Softmax loss function.
Revisiting CosFace
Next, we apply L2 normalization to and , fixing them at 1. This simplifies to .
CosFace changes only the target-class score to , leaves the other classes unchanged, and scales all scores by .
Subtracting a constant introduces a "margin" in the decision boundary, forcing the model to be more confident when classifying. This effectively increases inter-class margins and enhances the model’s ability to differentiate between different classes. In other words, the model requires higher confidence (greater cosine similarity) to correctly classify a sample, which helps reduce class overlap.
But if our goal is to increase inter-class margins, why apply to ?
Why Not Apply it Directly to ?
This is precisely the problem the authors aim to address in this paper:
If our goal is to increase inter-class margins, why not apply it directly to ?
Solution
Model Architecture
The diagram above shows ArcFace with sub-centers: each class has centers, the largest cosine similarity for that class is selected, and an angular margin is applied to the target class. Basic ArcFace corresponds to . This is a diagram of the loss, not the feature-extraction backbone.
But you probably don't like that image, so let's look at the implementation details:
# Implementation from ArcFace by InsightFace
class ArcFace(torch.nn.Module):
def __init__(self, s=64.0, margin=0.5):
super(ArcFace, self).__init__()
self.s = s
self.margin = margin
self.cos_m = math.cos(margin)
self.sin_m = math.sin(margin)
self.theta = math.cos(math.pi - margin)
self.sinmm = math.sin(math.pi - margin) * margin
self.easy_margin = False
def forward(self, logits: torch.Tensor, labels: torch.Tensor):
index = torch.where(labels != -1)[0]
target_logit = logits[index, labels[index].view(-1)]
with torch.no_grad():
target_logit.arccos_()
logits.arccos_()
final_target_logit = target_logit + self.margin
logits[index, labels[index].view(-1)] = final_target_logit
logits.cos_()
logits = logits * self.s
return logits
Take a close look at this segment:
with torch.no_grad():
target_logit.arccos_()
logits.arccos_()
final_target_logit = target_logit + self.margin
logits[index, labels[index].view(-1)] = final_target_logit
logits.cos_()
The input logits are cosine similarities between normalized features and class weights. The code converts them to angles, adds the margin only for the target class, converts back to cosine, and multiplies by the scale . The default margin is 0.5 radians, or about 28.6 degrees. If the original target-class angle is 60 degrees, adding the margin makes it about 88.6 degrees. The model must therefore reduce the target-class angle to classify the sample correctly.
Because these in-place operations run inside torch.no_grad(), their forward values change while backward propagation uses a straight-through (identity) gradient through the modified logits tensor, rather than the exact derivative of . Gradients still reach the preceding layers.
What's the Difference?
The authors compare the impact of different margins on classification:
In the diagram, the horizontal and vertical axes are the angles and between a feature and the two class centers. The leftmost panel shows normalized Softmax: the decision boundary is , with each side assigned to one class and no extra angular margin.
The second panel shows SphereFace's multiplicative angular margin, for the target class. Its angular margin varies with the angle rather than having a constant width. The classes still share the same normalized hypersphere; they are not placed on separate hyperspheres.
CosFace applies the margin to the target-class cosine value, yielding curved boundaries when projected back into angle space. ArcFace adds directly to the target-class angle, so the two boundaries in the figure are parallel straight lines with a constant gap.
Unifying the Formula
Given the concepts of "additive cosine margin" in CosFace, "additive angular margin" in ArcFace, and "multiplicative angular margin" in SphereFace, we can unify these margins into a more general formula:
Thus, the loss function can be written as:
Based on this formula, let's revisit the different loss functions:
- In CosFace, , , ;
- In ArcFace, , , ;
- In the paper’s multiplicative angular-margin comparison, , , .
Training and Validation Datasets
-
Training Datasets:
-
CASIA
-
VGG2
-
MS1MV0
- This dataset is a loosely cropped version.
- The estimated noise ratio in the original data is around 47.1% ∼ 54.4%.
- It was cleaned semi-automatically to create MS1MV3.
-
Celeb500K
- Collected similarly to MS1MV0.
- Celebrity identities were searched on Google to download top-ranked face images.
- The paper's prose says 25 million images from 500,000 identities were downloaded, while Table 1 above lists Celeb500K at 50 million images. The two figures conflict in the original paper.
- Faces larger than 50×50 pixels were detected using RetinaFace.
-
IBUG-500K Dataset
-
After removing overlapping identities (about 50K) through ID string matching, the cleaned MS1MV0 and Celeb500K were combined.
-
The final dataset, named IBUG-500K, consists of 11.96 million images from 493K identities.
-
The gender, race, pose, age, and image count distributions are shown below.
-
-
-
Validation Datasets:
-
LFW & CFP-FP & AgeDB
- These are used to quickly check the model's convergence.
-
CPLFW & CALFW
- Newer datasets with more significant pose and age variations.
-
MegaFace & IJB-B & IJB-C
- Large-scale image datasets.
-
LFR2019
- A dataset with 10,000 identities collected from various shows, movies, and TV series, comprising a total of 200,000 video clips. Each clip ranges from 1 second to 30 seconds in length.
-
Training Configuration
-
Face Standardization and Cropping:
- Standardized face crops are generated using five facial points predicted by RetinaFace, with dimensions of 112×112.
-
Network Architecture:
- ResNet50 and ResNet100 CNN architectures are used as the embedding networks, without bottleneck structures.
- The final 512-D embedding features are obtained using a BN-Dropout-FC-BN structure after the last convolutional layer.
-
Training Settings:
- The feature scale
sis set to 64, and the angular marginmin ArcFace is set to 0.5. - All recognition experiments are implemented using MXNet.
- The batch size is set to 512, and models are trained on 8 NVIDIA Tesla P40 (24GB) GPUs.
- Momentum is set to 0.9, and weight decay is set to 5e−4.
- The feature scale
Discussion
Comparison of Different Losses
-
Angular Margin Setting:
- On CASIA with ResNet50, among margins 0.4, 0.45, 0.5, and 0.55, the 0.5 setting is best on CFP-FP and AgeDB. On LFW it ties with 0.4 at 99.53%.
- The best margins for SphereFace and CosFace are 1.35 and 0.35, respectively.
-
Model Performance:
- The authors' SphereFace implementation at converges without the original annealing strategy. ArcFace at leads on CFP-FP and AgeDB in this table, while it ties with ArcFace at on LFW.
-
Combined Margin Framework:
- CM1 (1, 0.3, 0.2) and CM2 (0.9, 0.4, 0.15) are the two combined-margin settings in the table. Both trail ArcFace at on CFP-FP and AgeDB, so the table does not show combined margins working best here.
-
Norm-Softmax and Triplet Loss:
- Combining Norm-Softmax with intra-class loss improves performance on CFP-FP and AgeDB.
- Combining Norm-Softmax with inter-class loss results in only a slight improvement in accuracy.
- Triplet (0.35) reaches 91.90% on CFP-FP and 89.98% on AgeDB, below ArcFace at with 95.56% and 95.15%. These are results under this training setup.
Adding Intra-loss, Inter-loss, or Triplet-loss to ArcFace does not give a clear improvement in this table. Therefore, the authors conclude that ArcFace already strengthens intra-class compactness, inter-class separation, and the classification margin.
Performance on Validation Datasets
With ResNet100, the ArcFace models trained on MS1MV3 and IBUG-500K both score 99.83% on LFW and 98.02% and 98.01% on YTF, respectively. The listed CosFace result is 99.73% and 97.6%. Training image counts differ between methods, so this table alone cannot isolate the effect of the angular margin.
Several models in the table are near 99.8% on LFW and 98.0% on YTF, leaving small differences. ArcFace is close to the highest listed scores, though it leads neither column.
Beyond LFW and YTF, ArcFace also reports performance on CFP-FP, CPLFW, AgeDB, and CALFW. The IBUG-500K/ResNet100 row scores 98.87%, 93.43%, 98.38%, and 96.10%, respectively. It leads the first three columns and ties MV-Softmax at 96.10% on CALFW.
The ArcFace model trained on IBUG-500K with ResNet100 reaches 96.02% and 97.27% TPR at FPR in 1:1 verification on IJB-B and IJB-C, respectively. The lower softmax baselines in the table use different training data or backbones, so the full gap cannot be assigned to the ArcFace loss alone.
Conclusion
The core idea of ArcFace is to enhance intra-class compactness and inter-class differences by introducing angular margins in the feature space, achieving superior performance on multiple face recognition benchmarks.