# Additive Margin Softmax for Face Verification

###### Abstract

In this paper, we propose a conceptually simple and geometrically interpretable objective function, i.e. additive margin Softmax (AM-Softmax), for deep face verification. In general, the face verification task can be viewed as a metric learning problem, so learning large-margin face features whose intra-class variation is small and inter-class difference is large is of great importance in order to achieve good performance. Recently, Large-margin Softmax [10] and Angular Softmax [9] have been proposed to incorporate the angular margin in a multiplicative manner. In this work, we introduce a novel additive angular margin for the Softmax loss, which is intuitively appealing and more interpretable than the existing works. We also emphasize and discuss the importance of feature normalization in the paper. Most importantly, our experiments on LFW and MegaFace show that our additive margin softmax loss consistently performs better than the current state-of-the-art methods using the same network architecture and training dataset. Our code has also been made available^{1}^{1}1https://github.com/happynear/AMSoftmax.

## 1 Introduction

Face verification is widely used for identity authentication in enormous areas such as finance, military, public security and so on. Nowadays, most face verification models are built upon Deep Convolutional Neural Networks and supervised by classification loss functions [18, 20, 19, 9], metric learning loss functions [16] or both [17, 13]. Metric learning loss functions such as contrastive loss [17] or triplet loss [16] usually require carefully designed sample mining strategies and the final performance is very sensitive to these strategies, so increasingly more researchers shift their attentions to building deep face verification models based on improved classification loss functions [20, 19, 9].

Current prevailing classification loss functions for deep face recognition are mostly based on the widely-used softmax loss. The softmax loss is typically good at optimizing the inter-class difference (i.e., separating different classes), but not good at reducing the intra-class variation (i.e., making features of the same class compact). To address this, lots of new loss functions are proposed to minimize the intra-class variation. [20] proposed to add a regularization term to penalize the feature-to-center distances. In [19, 12, 15], researchers proposed to use a scale parameter to control the ”temperature” [2] of the softmax loss, producing higher gradients to the well-separated samples to further shrink the intra-class variance. In [9, 10], the authors introduced an conceptually appealing angular margin to push the classification boundary closer to the weight vector of each class. [9] also provided a theoretical guidance of training a deep model for metric learning tasks using the classification loss functions. [6, 12, 15] also improved the softmax loss by incorporating differnet kinds of margins.

In this work, we propose a novel and more interpretable way to import the angular margin into the softmax loss. We formulate an additive margin via , which is simpler than [9] and yields better performance. From Equation (3), we can see that is multiplied to the target angle in [9], so this type of margin is incorporated in a multiplicative manner. Since our margin is a scalar subtracted from , we call our loss function Additive Margin Softmax (AM-Softmax).

## 2 Preliminaries

To better understand the proposed AM-Softmax loss, we will first give a brief review of the original softmax and the A-softmax loss [9]. The formulation of the original softmax loss is given by

(1) | ||||

where is the input of the last fully connected layer ( denotes the the -th sample), is the -th column of the last fully connected layer. The is also called as the target logit [14] of the -th sample.

In the A-softmax loss, the authors proposed to normalize the weight vectors (making to be ) and generalize the target logit from to ,

(2) |

where the is usually a piece-wise function defined as

(3) |

where is usually an integer larger than and is a hyper-parameter to control how hard the classification boundary should be pushed. During training, the is annealing from to a small value to make the angular space of each class become more and more compact. In their experiments, they set the minimum value of to be 5 and , which is approximately equivalent to (Figure 2).

## 3 Additive Margin Softmax

In this section, we will first describe the definition of the proposed loss function. Then we will discuss about the intuition and interpretation of the loss function.

### 3.1 Definition

[10] defines a general function to introduce the large margin property. Motivated by that, we further propose a specific that introduces an additive margin to the softmax loss function. The formulation is given by

(4) |

Compared to the defined in L-Softmax [10] and A-softmax [9] (Equation (3)), our definition is more simple and intuitive. During implementation, the input after normalizing both the feature and the weight is actually , so in the forward propagation we only need to compute

(5) |

In this margin scheme, we don’t need to calculate the gradient for back-propagation because . It is much easier to implement compared with SphereFace [9].

Since we use cosine as the similarity to compare two face features, we follow [19, 11, 12] to apply both feature normalization and weight normalization to the inner product layer in order to build a cosine layer. Then we scale the cosine values using a hyper-parameter as suggested in [19, 11, 12]. Finally, the loss function becomes

(6) | ||||

In this paper, we assume that the norm of both and are normalized to 1 if not specified. In [19], the authors propose to let the scaling factor to be learned through back-propagation. However, after the margin is introduced into the loss function, we find that the will not increase and the network converges very slowly if we let to be learned. Thus, we fix to be a large enough value, e.g. , to accelerate and stablize the optimization.

As described in Section 2, [10, 9] propose to use an annealing strategy to set the hyper-parameter to avoid network divergence. However, to set the annealing curve of , lots of extra parameters are introduced, which are more or less confusing for starters. Although properly tuning those hyper-parameters for could lead to impressive results, the hyper-parameters are still quite difficult to tune. With our margin scheme, we find that we no longer need the help of the annealing strategy. The network can converge flexibly even if we fix the hyper-parameter from scratch. Compared to SphereFace [9], our additive margin scheme is more friendly to those who are not familiar with the effects of the hyper-parameters. Another recently proposed additive margin is also described in [6]. Our AM-Softmax is different than [6] in the sense that our feature and weight are normalized to a predefined constant . The normalization is the key to the angular margin property. Without the normalization, the margin does not necessarily lead to large angular margin.

### 3.2 Discussion

#### 3.2.1 Geometric Interpretation

Our additive margin scheme has a clear geometric interpretation on the hypersphere manifold. In Figure 3, we draw a schematic diagram to show the decision boundary of both conventional softmax loss and our AM-Softmax. For example, in Figure 3, the features are of dimensions. After normalization, the features are on a circle and the decision boundary of the traditional softmax loss is denoted as the vector . In this case, we have at the decision boundary .

For our AM-Softmax, the boundary becomes a marginal region instead of a single vector. At the new boundary for class , we have , which gives . If we further assume that all the classes have the same intra-class variance and the boundary for class is at , we can get (Fig. 3). Thus, , which is the difference of the cosine scores for class between the two sides of the margin region.

#### 3.2.2 Angular Margin or Cosine Margin

In SphereFace [9], the margin is multiplied to , so the angular margin is incorporated into the loss in a multiplicative way. In our proposed loss function, the margin is enforced by subtracting from , so our margin is incorporated into the loss in an additive way, which is one of the most significant differences than [9]. It is also worth mentioning that despite the difference of enforcing margin, these two types of margin formulations are also different in the base values. Specifically, one is and the other is . Although usually the cosine margin has an one-to-one mapping to the angular margin, there will still be some difference while optimizing them due to the non-linearity induced by the cosine function.

Whether we should use the cosine margin depends on which similarity measurement (or distance) the final loss function is optimizing. Obviously, our modified softmax loss function is optimizing the cosine similarity, not the angle. This may not be a problem if we are using the conventional softmax loss because the decision boundaries are the same in these two forms (). However, when we are trying to push the boundary, we will face a problem that these two similarities (distances) have different densities. Cosine values are more dense when the angles are near or . If we want to optimize the angle, an operation may be required after the value of the inner product is obtained. It will potentially be more computationally expensive.

In general, angular margin is conceptually better than the cosine margin, but considering the computational cost, cosine margin is more appealing in the sense that it could achieve the same goal with less efforts.

#### 3.2.3 Feature Normalization

In the SphereFace model [9], the authors added the weight normalization based on Large Margin Softmax [10], leaving the feature still not normalized. Our loss function, following [19, 12, 15], applies feature normalization and uses a global scale factor to replace the sample-dependent feature norm in SphereFace [9]. One question arises: when should we add the feature normalization?

Our answer is that it depends on the image quality. In [15]’s Figure 1, we can see that the feature norm is highly correlated with the quality of the image. Note that back propagation has a property that,

(7) |

Thus, after normalization, features with small norms will get much bigger gradient compared with features that have big norms (Figure 5). By back-propagation, the network will pay more attention to the low-quality face images, which usually have small norms. Its effect is very similar with hard sample mining [16, 8]. The advantages of feature normalization are also revealed in [11]. As a conclusion, feature normalization is most suitable for tasks whose image quality is very low.

From Figure 5 we can see that the gradient norm may be extremely big when the feature norm is very small. This potentially increases the risk of gradient explosion, even though we may not come across many samples with very small feature norm. Maybe some re-weighting strategy whose feature-gradient norm curve is between the two curves in Figure 5 could potentially work better. This is an interesting topic to be studied in the future.

#### 3.2.4 Feature Distribution Visualization

To better understand the effect of our loss function, we designed a toy experiment to visualize the feature distributions trained by several loss functions. We used Fashion MNIST [21] (10 classes) to train several 7-layer CNN models which output 3-dimensional features. These networks are supervised by different loss functions. After we obtain the 3-dimensional features, we normalize and plot them on a hypersphere (ball) in the 3 dimensional space (Figure 4).

From the visualization, we can empirically show that our AM-Softmax performs similarly with the best SphereFace [9] (A-Softmax) model when we set . Moreover, our loss function can further shrink the intra-class variance by setting a larger . Compared to A-Softmax [9], the AM-Softmax loss also converges easier with proper scaling factor . The visualized 3D features well demonstrates that AM-Softmax could bring the large margin property to the features without tuning too many hyper-parameters.

## 4 Experiment

In this section, we will firstly describe the experimental settings. Then we will discuss the overlapping problem of the modern in-the-wild face datasets. Finally we will compare the performance of our loss function with several previous state-of-the-art loss functions.

LFW[3] | LFW BLUFR[7] | LFW BLUFR[7] | LFW BLUFR[7] | MegaFace[5] | MegaFace[5] | ||

Loss Function | pairs | VR@FAR=0.01% | VR@FAR=0.1% | DIR@FAR=1% | Rank1@ | VR@FAR= | |

Softmax | - | 97.08% | 60.26% | 78.26% | 50.85% | 45.26% | 50.12% |

Softmax+75% dropout | - | 98.62% | 77.64% | 90.91% | 63.72% | 57.32% | 65.58% |

Center Loss [20] | - | 99.00% | 83.30% | 94.50% | 65.46% | 63.38% | 75.68% |

NormFace [19] | - | 98.98% | 88.15% | 96.16% | 75.22% | 65.03% | 75.88% |

A-Softmax [9] | 1.5 | 99.08% | 91.26% | 97.06% | 81.93% | 67.41% | 78.19% |

AM-Softmax | 0.25 | 99.13% | 91.97% | 97.13% | 81.42% | 70.81% | 83.01% |

AM-Softmax | 0.3 | 99.08% | 93.18% | 97.56% | 84.02% | 72.01% | 83.29% |

AM-Softmax | 0.35 | 98.98% | 93.51% | 97.69% | 84.82% | 72.47% | 84.44% |

AM-Softmax | 0.4 | 99.17% | 93.60% | 97.71% | 84.51% | 72.44% | 83.50% |

AM-Softmax | 0.45 | 99.03% | 93.44% | 97.60% | 84.59% | 72.22% | 83.00% |

AM-Softmax | 0.5 | 99.10% | 92.33% | 97.28% | 83.38% | 71.56% | 82.49% |

AM-Softmax w/o FNã | 0.35 | 99.08% | 93.86% | 97.63% | 87.58% | 70.71% | 82.66% |

AM-Softmax w/o FNã | 0.4 | 99.12% | 94.48% | 97.96% | 87.31% | 70.96% | 83.11% |

### 4.1 Implementation Details

Our loss function is implemented using Caffe framework [4]. We follow all the experimental settings from [9], including the image resolution, preprocessing method and the network structure. Specifically speaking, we use MTCNN [23] to detect faces and facial landmarks in images. Then the faces are aligned according to the detected landmarks. The aligned face images are of size , and are normalized by subtracting 128 and dividing 128. Our network structure follows [9], which is a modified ResNet [1] with 20 layers that is adapted to face recognition.

All the networks are trained from scratch. We set the weight decay parameter to be . The batch size is 256 and the learning rate begins with 0.1 and is divided by 10 at the 16K, 24K and 28K iterations. The training is finished at 30K iterations. During training, we only use image mirror to augment the dataset.

In testing phase, We feed both frontal face images and mirror face images and extract the features from the output of the first inner-product layer. Then the two features are summed together as the representation of the face image. When comparing two face images, cosine similarity is utilized as the measurement.

### 4.2 Dataset Overlap Removal

The dataset we use for training is CASIA-Webface [22], which contains 494,414 training images from 10,575 identities. To perform open-set evaluations, we carefully remove the overlapped identities between training dataset (CASIA-Webface [22]) and testing datasets (LFW[3] and MegaFace [5]). Finally, we find 17 overlapped identities between CASIA-Webface and LFW, and 42 overlapped identities between CASIA-Webface and MegaFace set1. Note that there are only 80 identities in MegaFace set1, i.e. over half of the identities are already in the training dataset. The effect of overlap removal is remarkable for MegaFace (Table 2). To be rigorous, all the experiments in this paper are based on the cleaned dataset. We have made our overlap checking code publicly available^{2}^{2}2https://github.com/happynear/FaceDatasets to encourage researchers to clean their training datasets before experiments.

Loss | Overlap | MegaFace | MegaFace |
---|---|---|---|

Function | Removal? | Rank1 | VR |

AM-Softmax | No | 75.23% | 87.06% |

AM-Softmax | Yes | 72.47% | 84.44% |

In our paper, we re-train some of the previous loss functions on the cleaned dataset as the baselines for comparison. Note that, we make our experiments fair by using the same network architecture and training dataset for every compared methods.

### 4.3 Effect of Hyper-parameter

There are two hyper-parameters in our proposed loss function, one is the scale and another is the margin . The scale has already been discussed sufficiently in several previous works [19, 12, 15]. In this paper, we directly fixed it to and will not discuss its effect anymore.

The main hyper-parameter in our loss function is the margin . In Table 1, we list the performance of our proposed AM-Softmax loss function with varies from 0.25 to 0.5. From the table we can see that from to , the performance improves significantly, and the performance become the best when to .

We also provide the result for the loss function without feature normalization (noted as w/o FN) and the scale . As we explained before, feature normalization performs better on low quality images like MegaFace[5], and using the original feature norm performs better on high quality images like LFW [3].

In Figure 6, we draw both of the CMC curves to evaluate the performance of identification and ROC curves to evaluate the performance of verification. From this figure, we can show that our loss function performs much better than the other loss functions when the rank or false positive rate is very low.

## 5 Conclusion and Future Work

In this paper, we propose to impose an additive margin strategy to the target logit of softmax loss with feature and weights normalized. Our loss function is built upon the previous margin schemes[9, 10], but it is more simple and interpretable. Comprehensive experiments show that our loss function performs better than A-Softmax [9] on LFW BLUFR [7] and MegaFace [5].

There is still lots of potentials for the research of the large margin strategies. There could be more creative way of specifying the function other than multiplication and addition. In our AM-Softmax loss, the margin is a manually tuned global hyper-parameter. How to automatically determine the margin and how to incorporate class-specific or sample-specific margins remain open questions and are worth studying.

## References

- [1] K. He, X. Zhang, S. Ren, and J. Sun. Deep residual learning for image recognition. In IEEE Conference on Computer Vision and Pattern Recognition, pages 770–778, 2016.
- [2] G. Hinton, O. Vinyals, and J. Dean. Distilling the knowledge in a neural network. arXiv preprint arXiv:1503.02531, 2015.
- [3] G. B. Huang, M. Ramesh, T. Berg, and E. Learned-Miller. Labeled faces in the wild: A database for studying face recognition in unconstrained environments. Technical report, Technical Report 07-49, University of Massachusetts, Amherst, 2007.
- [4] Y. Jia, E. Shelhamer, J. Donahue, S. Karayev, J. Long, R. Girshick, S. Guadarrama, and T. Darrell. Caffe: Convolutional architecture for fast feature embedding. In Proceedings of the 22nd ACM international conference on Multimedia, pages 675–678. ACM, 2014.
- [5] I. Kemelmacher-Shlizerman, S. M. Seitz, D. Miller, and E. Brossard. The megaface benchmark: 1 million faces for recognition at scale. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 4873–4882, 2016.
- [6] X. Liang, X. Wang, Z. Lei, S. Liao, and S. Z. Li. Soft-margin softmax for deep classification. 24th International Conference on Neural Information Processing, pages 413–421, 2017.
- [7] S. Liao, Z. Lei, D. Yi, and S. Z. Li. A benchmark study of large-scale unconstrained face recognition. In IEEE International Joint Conference on Biometrics, pages 1–8. IEEE, 2014.
- [8] T.-Y. Lin, P. Goyal, R. Girshick, K. He, and P. Dollár. Focal loss for dense object detection. arXiv preprint arXiv:1708.02002, 2017.
- [9] W. Liu, Y. Wen, Z. Yu, M. Li, B. Raj, and L. Song. Sphereface: Deep hypersphere embedding for face recognition. In Proceedings of the IEEE conference on computer vision and pattern recognition, 2017.
- [10] W. Liu, Y. Wen, Z. Yu, and M. Yang. Large-margin softmax loss for convolutional neural networks. In International Conference on Machine Learning, pages 507–516, 2016.
- [11] W. Liu, Y.-M. Zhang, X. Li, Z. Yu, B. Dai, T. Zhao, and L. Song. Deep hyperspherical learning. In Advances in Neural Information Processing Systems, pages 3953–3963, 2017.
- [12] Y. Liu, H. Li, and X. Wang. Rethinking feature discrimination and polymerization for large-scale recognition. arXiv preprint arXiv:1710.00870, 2017.
- [13] O. M. Parkhi, A. Vedaldi, and A. Zisserman. Deep face recognition. In BMVC, volume 1, page 6, 2015.
- [14] G. Pereyra, G. Tucker, J. Chorowski, Ł. Kaiser, and G. Hinton. Regularizing neural networks by penalizing confident output distributions. arXiv preprint arXiv:1701.06548, 2017.
- [15] R. Ranjan, C. D. Castillo, and R. Chellappa. L2-constrained softmax loss for discriminative face verification. arXiv preprint arXiv:1703.09507, 2017.
- [16] F. Schroff, D. Kalenichenko, and J. Philbin. Facenet: A unified embedding for face recognition and clustering. In IEEE Conference on Computer Vision and Pattern Recognition, pages 815–823, 2015.
- [17] Y. Sun, Y. Chen, X. Wang, and X. Tang. Deep learning face representation by joint identification-verification. In Advances in neural information processing systems, pages 1988–1996, 2014.
- [18] Y. Taigman, M. Yang, M. Ranzato, and L. Wolf. Deepface: Closing the gap to human-level performance in face verification. In IEEE Conference on Computer Vision and Pattern Recognition, pages 1701–1708, 2014.
- [19] F. Wang, X. Xiang, J. Cheng, and A. L. Yuille. Normface: L2 hypersphere embedding for face verification. In Proceedings of the 25th ACM international conference on Multimedia. ACM, 2017.
- [20] Y. Wen, K. Zhang, Z. Li, and Y. Qiao. A discriminative feature learning approach for deep face recognition. In European Conference on Computer Vision, pages 499–515. Springer, 2016.
- [21] H. Xiao, K. Rasul, and R. Vollgraf. Fashion-mnist: a novel image dataset for benchmarking machine learning algorithms, 2017.
- [22] D. Yi, Z. Lei, S. Liao, and S. Z. Li. Learning face representation from scratch. arXiv preprint arXiv:1411.7923, 2014.
- [23] K. Zhang, Z. Zhang, Z. Li, and Y. Qiao. Joint face detection and alignment using multitask cascaded convolutional networks. IEEE Signal Processing Letters, 23(10):1499–1503, 2016.