Back to paper library
arXiv 2018IEEE TPAMI 2022Face recognitionPaper notes

ArcFace

Additive Angular Margin Loss

Original paper

ArcFace: Additive Angular Margin Loss for Deep Face Recognition

Paper authors

Jiankang Deng · Jia Guo · Jing Yang · Niannan Xue · Irene Kotsia · Stefanos Zafeiriou

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}
}
On this page

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:

LSoftmax=1N∑i=1N−log⁡(efyi∑j=1Cefj)L_{\text{Softmax}} = \frac{1}{N}\sum_{i=1}^{N}-\log\left(\frac{e^{f_{y_i}}}{\sum_{j=1}^{C}e^{f_j}}\right)

Here, ff contains class logits; xx is the input feature vector, yiy_i is the class of the ii-th image, CC is the number of classes, and NN is the batch size.

Typically, fjf_j is the output score of a fully connected layer, which can be represented as fj=WjTx+Bjf_j = W_j^Tx + B_j, where WjW_j is the weight of the fully connected layer, and BjB_j is the bias term.

When we set Bj=0B_j = 0, we get fj=WjTxf_j = W_j^Tx, which can be written as the dot product:

fj=∥Wj∥∥x∥cos⁡θjf_j = \|W_j\|\|x\|\cos\theta_j

Here, θj\theta_j is the angle between WjW_j and xx.

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 ∥Wj∥\|W_j\| and ∥x∥\|x\|, fixing them at 1. This simplifies fjf_j to fj=cos⁡θjf_j = \cos\theta_j.

CosFace changes only the target-class score to fyi=cos⁡θyi−mf_{y_i}=\cos\theta_{y_i}-m, leaves the other classes unchanged, and scales all scores by ss.

Subtracting a constant mm 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 mm to cos⁡θ\cos\theta?

Why Not Apply it Directly to θ\theta?

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 θ\theta?

Solution

Model Architecture

The diagram above shows ArcFace with sub-centers: each class has KK centers, the largest cosine similarity for that class is selected, and an angular margin is applied to the target class. Basic ArcFace corresponds to K=1K=1. 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:

python
# 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:

python
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 ss. 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 cos⁡(arccos⁡(x)+m)\cos(\arccos(x)+m). 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 θ1\theta_1 and θ2\theta_2 between a feature and the two class centers. The leftmost panel shows normalized Softmax: the decision boundary is θ1=θ2\theta_1=\theta_2, with each side assigned to one class and no extra angular margin.

The second panel shows SphereFace's multiplicative angular margin, cos⁡(mθyi)\cos(m\theta_{y_i}) 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 mm 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:

fj={cos⁡(m1θyi+m2)−m3if j=yi,cos⁡θjif j≠yi.f_j = \begin{cases} \cos(m_1\theta_{y_i} + m_2) - m_3 & \text{if } j = y_i, \\ \cos\theta_j & \text{if } j \neq y_i. \end{cases}

Thus, the loss function can be written as:

LArcFace=−1N∑i=1Nlog⁡(es(fyi)es(fyi)+∑j≠yies(fj))L_{\text{ArcFace}} = -\frac{1}{N}\sum_{i=1}^{N}\log\left(\frac{e^{s(f_{y_i})}}{e^{s(f_{y_i})} + \sum_{j\neq y_i}e^{s(f_j)}}\right)

Based on this formula, let's revisit the different loss functions:

  • In CosFace, m1=1m_1 = 1, m2=0m_2 = 0, m3=0.35m_3 = 0.35;
  • In ArcFace, m1=1m_1 = 1, m2=0.5m_2 = 0.5, m3=0m_3 = 0;
  • In the paper’s multiplicative angular-margin comparison, m1=1.35m_1 = 1.35, m2=0m_2 = 0, m3=0m_3 = 0.

Training and Validation Datasets

  1. 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.

  2. 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

  1. Face Standardization and Cropping:

    • Standardized face crops are generated using five facial points predicted by RetinaFace, with dimensions of 112×112.
  2. 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.
  3. Training Settings:

    • The feature scale s is set to 64, and the angular margin m in 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.

Discussion

Comparison of Different Losses

  1. 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.
  2. Model Performance:

    • The authors' SphereFace implementation at m=1.35m=1.35 converges without the original annealing strategy. ArcFace at m=0.5m=0.5 leads on CFP-FP and AgeDB in this table, while it ties with ArcFace at m=0.4m=0.4 on LFW.
  3. 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 m=0.5m=0.5 on CFP-FP and AgeDB, so the table does not show combined margins working best here.
  4. 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 m=0.5m=0.5 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 10−410^{-4} 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.