苏剑林解读

https://kexue.fm/archives/8656/comment-page-1

Additive Margin Softmax for Face Verification

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~\cite{liu2016large} and Angular Softmax~\cite{liu2017sphereface} have been proposed to incorporate the angular margin in a multiplicative manner.
在本文中,我们提出了一个概念简单且几何上可解释的目标函数,即附加边缘Softmax (AM-Softmax),用于深度人脸验证。一般情况下,人脸验证任务可以看作是一个度量学习问题,因此学习类内变异小、类间差异大的大幅度人脸特征对于取得良好的性能具有重要意义。最近,Large-margin Softmax~\cite{liu2016large}和Angular Softmax~\cite{liu2017sphereface}被提出以乘法的方式合并角边。

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\footnote{\url{https://github.com/happynear/AMSoftmax}}.
在本研究中,我们为Softmax损耗引入了一种新的附加角裕度,它比现有的作品更直观、更易于解释。文中还着重讨论了特征归一化的重要性。最重要的是,我们在LFW和MegaFace上的实验表明,使用相同的网络架构和训练数据集,我们的加性边际软最大损失比当前最先进的方法性能始终更好。我们的代码也提供了\脚注{\url{https://github.com/happynear/AMSoftmax}}。

\section{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~\cite{taigman2014deepface, wen2016discriminative,wang2017normface,liu2017sphereface}, metric learning loss functions~\cite{schroff2015facenet} or both~\cite{sun2014deep,parkhi2015deep}. Metric learning loss functions such as contrastive loss~\cite{sun2014deep} or triplet loss~\cite{schroff2015facenet} 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~\cite{wen2016discriminative, wang2017normface, liu2017sphereface}.
人脸验证被广泛应用于金融、军事、公安等众多领域的身份验证。如今,大多数面临验证模型是建立在深厚的卷积神经网络和监督分类损失函数~ \引用{taigman2014deepface、wen2016discriminative wang2017normface, liu2017sphereface},度量学习丧失功能~ \ {schroff2015facenet}引用或两个~ \引用{sun2014deep, parkhi2015deep}。度量学习损失函数,如对比损失~ (sun2014deep)或三重损失~ (triplet),通常需要精心设计的样本挖掘策略,最终性能对这些策略非常敏感,因此,越来越多的研究人员将注意力转移到基于改进的分类损失函数的深度人脸验证模型上~\引用{wen2016discriminative, wang2017normface, liu2017sphereface}。

\begin{figure}
\centering
\includegraphics[scale=0.48]{fig1.pdf}
\caption{Comparison between the original softmax loss and the additive margin softmax loss. Note that, the angular softmax~\cite{liu2017sphereface} can only impose unfixed angular margin, while the additive margin softmax incorporates the fixed hard angular margin.}
\label{fig:comparison}
\vspace{-5mm}
\end{figure}
原始的softmax损耗与附加裕度softmax损耗的比较。请注意,angular softmax~\cite{liu2017sphereface}只能施加不固定的角边,而添加边softmax包含固定的硬角边。

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. \cite{wen2016discriminative} proposed to add a regularization term to penalize the feature-to-center distances. In \cite{wang2017normface,liu_2017_coco_v2,ranjan2017l2}, researchers proposed to use a scale parameter to control the “temperature”~\cite{hinton2015distilling} of the softmax loss, producing higher gradients to the well-separated samples to further shrink the intra-class variance. In \cite{liu2017sphereface,liu2016large}, the authors introduced an conceptually appealing angular margin to push the classification boundary closer to the weight vector of each class. \cite{liu2017sphereface} also provided a theoretical guidance of training a deep model for metric learning tasks using the classification loss functions. \cite{liang2017soft,liu_2017_coco_v2,ranjan2017l2} also improved the softmax loss by incorporating differnet kinds of margins.
目前流行的人脸深度识别的分类损失函数大多基于广泛使用的软最大损失。softmax损失通常擅长于优化类间的差异(即,分离不同的类),但不擅长于减少类内的差异(即,使同一类的特性紧凑)。为了解决这一问题,提出了许多新的损失函数来最小化类内变化。\cite{wen2016discriminative}建议增加一个正则化项来惩罚特征到中心的距离。在{wang2017normface,liu_2017_coco_v2,ranjan2017l2}中,研究人员提出使用一个尺度参数来控制softmax损失的“温度”~ {hinton2015蒸馏},对分离良好的样本产生更高的梯度,以进一步缩小类内方差。在\cite{liu2017sphereface,liu2016large}中,作者引入了一个概念上吸引人的角边缘来推动分类边界更接近每个类的权向量。同时也为使用分类损失函数训练度量学习任务的深度模型提供了理论指导。通过引入不同类型的边际,也改善了softmax损失。

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 $\cos\theta - m$, which is simpler than \cite{liu2017sphereface} and yields better performance. From Equation \eqref{eq:psisphereface}, we can see that $m$ is multiplied to the target angle $\theta{yi}$ in \cite{liu2017sphereface}, so this type of margin is incorporated in a multiplicative manner. Since our margin is a scalar subtracted from $cos\theta$, we call our loss function Additive Margin Softmax (AM-Softmax).
在本研究中,我们提出了一种新颖的、更易于解释的方法来将角裕度导入软max损耗中。我们通过$ cos\theta - m$建立了一个附加裕度,它比\cite{liu2017sphereface}更简单,并且产生了更好的性能。从等式\eqref{eq:psi_sphereface}中,我们可以看到$m$乘以\cite{liu2017sphereface}中的目标角$ theta
{y_i}$,因此这种类型的边际以乘法方式合并。因为我们的边际是从$cos\theta$中减去一个标量,我们称损失函数为Additive margin Softmax (AM-Softmax)。

Experiments on LFW BLUFR protocol \cite{liao2014benchmark} and MegaFace \cite{kemelmacher2016megaface} show that our loss function with the same network architecture achieves better results than the current state-of-the-art approaches.
在LFW BLUFR协议和MegaFace协议上的实验表明,在相同的网络结构下,我们的损失函数比目前最先进的方法获得了更好的结果。

\section{Preliminaries}
\label{sec: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 \cite{liu2017sphereface}. The formulation of the original softmax loss is given by
为了更好地理解提出的AM-Softmax丢失,我们首先简要回顾了原始的softmax和a -softmax丢失(引用{liu2017sphereface})。给出了原始软最大损耗的计算公式

\begin{equation}
\begin{aligned}
\mathcal{L}S & = -\frac{1}{n}\sum{i=1}^n{log\frac{e^{W{y_i}^T \bm{f}_i}}{\sum{j=1}^{c}{e^{Wj^T \bm{f}_i}}}}\
& = -\frac{1}{n}\sum
{i=1}^n{log\frac{e^{|W{y_i}| |\bm{f}_i|cos(\theta {yi})}}{\sum{j=1}^{c}{e^{|Wj| |\bm{f}_i| cos(\theta{j})}}}},
\label{eq:softmax}
\end{aligned}
\end{equation}
where $\bm{f}$ is the input of the last fully connected layer ($\bm{f}i$ denotes the the $i$-th sample), $W_j$ is the $j$-th column of the last fully connected layer. The $W{y_i}^T \bm{f}_i$ is also called as the target logit \cite{pereyra2017regularizing} of the $i$-th sample.

In the A-softmax loss, the authors proposed to normalize the weight vectors (making $|Wi|$ to be $1$) and generalize the target logit from $|\bm{f}_i|cos(\theta {yi})$ to $|\bm{f}_i|\psi(\theta {yi})$,
\begin{equation}
\mathcal{L}
{AS} = -\frac{1}{n}\sum{i=1}^n{log\frac{e^{|\bm{f}_i|\psi(\theta {yi})}}{e^{|\bm{f}_i|\psi(\theta {yi})} + \sum{j=1,j\neq yi}^{c}{e^{|\bm{f}_i| cos(\theta{j})}}}},
\label{eq:a-softmax}
\end{equation}
where the $\psi(\theta)$ is usually a piece-wise function defined as
\begin{equation}
\begin{split}
\psi(\theta)=\frac{(-1)^k\cos(m\theta)-2k + \lambda cos(\theta)}{1+\lambda}, \
\theta\in[\frac{k\pi}{m},\frac{(k+1)\pi}{m}],
\end{split}
\label{eq:psi_sphereface}
\end{equation}

where $m$ is usually an integer larger than $1$ and $\lambda$ is a hyper-parameter to control how hard the classification boundary should be pushed. During training, the $\lambda$ is annealing from $1,000$ 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 $\lambda$ to be 5 and $m = 4$, which is approximately equivalent to $m = 1.5$ (Figure \ref{fig:logit_curve}).

\begin{figure}
\centering
\includegraphics[scale=0.47]{logit_curve.pdf}
\caption{ $\psi(\theta)$ for conventional Softmax, Angular Softmax~\cite{liu2017sphereface} and our proposed Hard Margin Softmax. For Angular Softmax, we plot the logit curve for three parameter sets. From the curves we can infer that $m = 4, \lambda = 5$ lies between conventional Softmax and Angular Softmax with $m = 2, \lambda = 0$, which means it is approximately $m = 1.5$. Our proposed Additive Margin Softmax with optimized parameter $m=0.35$ is also plotted and we can observe that it is similar with Angular Softmax with $m =4, \lambda = 5$ in the range $[0^\circ, 90^\circ]$, in which most of the real-world $\theta$s lie. }
\label{fig:logit_curve}
\end{figure}

\section{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.

\subsection{Definition}

\cite{liu2016large} defines a general function $\psi(\theta)$ to introduce the large margin property. Motivated by that, we further propose a specific $\psi(\theta)$ that introduces an additive margin to the softmax loss function. The formulation is given by
\begin{equation}
\psi(\theta) = cos\theta - m.
\label{eq:psihardmargin}
\end{equation}
Compared to the $\psi(\theta)$ defined in L-Softmax~\cite{liu2016large} and A-softmax~\cite{liu2017sphereface} (Equation (\ref{eq:psi_sphereface})), our definition is more simple and intuitive. During implementation, the input after normalizing both the feature and the weight is actually $x = cos\theta
{yi} = \frac{W{yi}^T f_i}{|W{y_i}| |f_i|}$, so in the forward propagation we only need to compute
\begin{equation}
\begin{aligned}
\Psi(x) &= x - m.
\end{aligned}
\label{eq:psi_on_cos}
\end{equation}
In this margin scheme, we don’t need to calculate the gradient for back-propagation because $\Psi’(x) = 1$. It is much easier to implement compared with SphereFace \cite{liu2017sphereface}.

Since we use cosine as the similarity to compare two face features, we follow \cite{wang2017normface,liu2017spherenet,liu2017_coco_v2} 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 $s$ as suggested in \cite{wang2017normface,liu2017spherenet,liu_2017_coco_v2}. Finally, the loss function becomes
\begin{equation}
\begin{aligned}
\mathcal{L}
{AMS} & = -\frac{1}{n}\sum{i=1}^n{log\frac{e^{s \cdot \left(cos\theta{yi} - m \right)}}{e^{s \cdot \left(cos\theta{yi} - m \right)} + \sum{j=1,j\neq yi}^{c}{e^{s \cdot cos\theta{j}}}}}\
& = -\frac{1}{n}\sum{i=1}^n{log\frac{e^{s \cdot \left(W{yi}^T \bm{f}_i - m \right)}}{e^{s \cdot \left(W{yi}^T \bm{f}_i - m \right)} + \sum{j=1,j\neq y_i}^c{e^{s W_j^T \bm{f}_i}}}}.
\end{aligned}
\label{eq:am-softmax}
\end{equation}

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

As described in Section \ref{sec:preliminaries}, \cite{liu2016large,liu2017sphereface} propose to use an annealing strategy to set the hyper-parameter $\lambda$ to avoid network divergence. However, to set the annealing curve of $\lambda$, lots of extra parameters are introduced, which are more or less confusing for starters. Although properly tuning those hyper-parameters for $\lambda$ 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 $m$ from scratch. Compared to SphereFace~\cite{liu2017sphereface}, 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 \cite{liang2017soft}. Our AM-Softmax is different than \cite{liang2017soft} in the sense that our feature and weight are normalized to a predefined constant $s$. The normalization is the key to the angular margin property. Without the normalization, the margin $m$ does not necessarily lead to large angular margin.

As explained in Figure 4 of \cite{wang2017normface}, optimizing $cos(\theta)$ will also enlarge the norm (magnitude) of the weights and the features. To prevent the norm from growing aggressively to infinity, we usually apply weight decay for the weight normalization. Similarly, for the feature normalization we regularize the features using feature decay. The feature decay is defined as

\begin{equation}
\mathcal{L}{FD} = \frac{1}{n}\sum{i=1}^n{|f_i|_2^2},
\label{eq:feature_decay}
\end{equation}

which is used to prevent the norm of features from becoming too large. Without this regularization, when we set a large $s$ at the beginning, the feature norm will likely to be very large in the initial a few hundred iterations, which would cause the network diverge sometimes.

\subsection{Discussion}
\label{sec:understanding}

\subsubsection{Geometric Interpretation}
\begin{figure}
\centering
\includegraphics[scale=0.4]{boundary.pdf}
\caption{ Conventional Softmax’s decision boundary and Additive Margin Softmax’s decision boundary. For conventional softmax, the decision boundary is at $P_0$, where $W_1^T P_0 = W_2^T P_0$. For AM-Softmax, the decision boundary for class $1$ is at $P_1$, where $W_1^T P_1 - m = W_2^T P_1 = W_1^T P_2$. Note that the distance marked on this figure doesn’t represent the real distances. The real distance is a function of the cosine of the angle, while in this figure we use the angle as the distance for better visualization effect. Here we use the word center'' to represent the weight vector of the corresponding class in the last inner-product layer, even though they may not be exactly the mean vector of the features in the class. The relationship between the weight vector (agent’’) and the features’ mean vector (``center’’) is described in Figure 6 of \cite{wang2017normface}.
}
\label{fig:boundary}
\end{figure}

Our additive margin scheme has a clear geometric interpretation on the hypersphere manifold. In Figure \ref{fig:boundary}, we draw a schematic diagram to show the decision boundary of both conventional softmax loss and our AM-Softmax. For example, in Figure \ref{fig:boundary}, the features are of $2$ dimensions. After normalization, the features are on a circle and the decision boundary of the traditional softmax loss is denoted as the vector $P_0$. In this case, we have $W_1^T P_0 = W_2^T P_0$ at the decision boundary $P_0$.

For our AM-Softmax, the boundary becomes a marginal region instead of a single vector. At the new boundary $P1$ for class $1$, we have $W_1^T P_1 - m = W_2^T P_1$, which gives $m = (W_1 - W_2)^T P_1 = \cos(\theta{W1,P_1})-\cos(\theta{W2,P_1})$. If we further assume that all the classes have the same intra-class variance and the boundary for class $2$ is at $P_2$, we can get $\cos(\theta{W2,P_1})=\cos(\theta{W1,P_2})$ (Fig. \ref{fig:boundary}). Thus, $m = \cos(\theta{W1,P_1})-\cos(\theta{W_1,P_2})$, which is the difference of the cosine scores for class $1$ between the two sides of the margin region.

\subsubsection{Angular Margin or Cosine Margin}

In SphereFace \cite{liu2017sphereface}, the margin $m$ is multiplied to $\theta$, so the angular margin is incorporated into the loss in a multiplicative way. In our proposed loss function, the margin is enforced by subtracting $m$ from $\cos\theta$, so our margin is incorporated into the loss in an additive way, which is one of the most significant differences than \cite{liu2017sphereface}. 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 $\theta$ and the other is $\cos\theta$. 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 ($\cos\theta_1 = \cos\theta_2 \Rightarrow \theta_1=\theta_2$). 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 $0$ or $\pi$. If we want to optimize the angle, an $\arccos$ operation may be required after the value of the inner product $W^T \bm{f}$ 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.

\subsubsection{Feature Normalization}

\begin{figure}
\centering
\includegraphics[scale=0.2]{scatter2.pdf}
\caption{ Feature distribution visualization of several loss functions. Each point on the sphere represent one normalized feature. Different colors denote different classes. For SphereFace \cite{liu2017sphereface}, we have already tried to use the best hyper-parameters we could find.}
\label{fig:scatter}
\end{figure
}
\begin{figure}
\centering
\includegraphics[scale=0.5]{gradient_norm.pdf}
\caption{ The feature gradient norm w.r.t. the feature norm for softmax loss with and without feature normalization. The gradients are calculated using the weights from a converged network. The feature direction is selected as the mean vector of one selected target center and one nearest class center. Note that the y-axis is in logarithmic scale for better visualization. For softmax loss with feature normalization, we set $s=30$. That is why the intersection of these two curves is at $30$. }
\label{fig:gradient_norm}
\end{figure}

In the SphereFace model \cite{liu2017sphereface}, the authors added the weight normalization based on Large Margin Softmax \cite{liu2016large}, leaving the feature still not normalized. Our loss function, following \cite{wang2017normface,liu_2017_coco_v2,ranjan2017l2}, applies feature normalization and uses a global scale factor $s$ to replace the sample-dependent feature norm in SphereFace \cite{liu2017sphereface}. One question arises: when should we add the feature normalization?

Our answer is that it depends on the image quality. In \cite{ranjan2017l2}’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,

\begin{equation}
y = \frac{x}{\alpha} \quad \Rightarrow \quad \frac{dy}{dx} = \frac{1}{\alpha}.
\end{equation}

Thus, after normalization, features with small norms will get much bigger gradient compared with features that have big norms (Figure \ref{fig:gradient_norm}). 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 \cite{schroff2015facenet,lin2017focal}. The advantages of feature normalization are also revealed in \cite{liu2017spherenet}. As a conclusion, feature normalization is most suitable for tasks whose image quality is very low.

From Figure \ref{fig:gradient_norm} 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 \ref{fig:gradient_norm} could potentially work better. This is an interesting topic to be studied in the future.

\subsubsection{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~\cite{xiao2017fashion} (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~\ref{fig:scatter}).

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

\section{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.

\begin{table}
\centering
\footnotesize
\begin{threeparttable}
\label{tab:performance}
\begin{tabular}{cccccccc}
\toprule
& & LFW\cite{huang2007labeled} & LFW BLUFR\cite{liao2014benchmark} & LFW BLUFR\cite{liao2014benchmark} & LFW BLUFR\cite{liao2014benchmark} & MegaFace\cite{kemelmacher2016megaface} & MegaFace\cite{kemelmacher2016megaface} \
Loss Function & $m$ & $6,000$ pairs & VR@FAR=0.01\% & VR@FAR=0.1\% & DIR@FAR=1\% & Rank1@\num{1e6} & VR@FAR=\num{1e-6} \
\midrule
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 \cite{wen2016discriminative} & - & 99.00\% & 83.30\% & 94.50\% & 65.46\% & 63.38\% & 75.68\%\
NormFace \cite{wang2017normface} & - & 98.98\% & 88.15\% & 96.16\% & 75.22\% & 65.03\% & 75.88\%\
A-Softmax \cite{liu2017sphereface} & $\sim$1.5 & 99.08\% & 91.26\% & 97.06\% & 81.93\% & 67.41\% & 78.19\% \
\midrule
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\% & \textbf{72.47\%} & \textbf{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\%\
\midrule
AM-Softmax w/o FN & 0.35 & 99.08\% & 93.86\% & 97.63\% & \textbf{87.58\%} & 70.71\% & 82.66\%\
AM-Softmax w/o FN & 0.4 & 99.12\% & \textbf{94.48\%} & \textbf{97.96\%} & 87.31\% & 70.96\% & 83.11\% \
\bottomrule
\end{tabular}
\vspace{1mm}
\caption{Performance on modified ResNet-20 with various loss functions. Note that, for Center Loss \cite{wen2016discriminative} and NormFace \cite{wang2017normface}, we used modified ResNet-28 \cite{wen2016discriminative} because we failed to train a model using Center Loss on modified ResNet-20 \cite{liu2017sphereface} and the NormFace model was fine-tuned based on the Center Loss model.}
\end{threeparttable}
\end{table
}

\subsection{Implementation Details}

Our loss function is implemented using Caffe framework \cite{jia2014caffe}. We follow all the experimental settings from \cite{liu2017sphereface}, including the image resolution, preprocessing method and the network structure.
Specifically speaking, we use MTCNN \cite{zhang2016joint} 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 $112\times 96$, and are normalized by subtracting 128 and dividing 128. Our network structure follows \cite{liu2017sphereface}, which is a modified ResNet \cite{he2016deep} with 20 layers that is adapted to face recognition.

All the networks are trained from scratch. We set the weight decay parameter to be \num{5e-4}. 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.

\subsection{Dataset Overlap Removal}

The dataset we use for training is CASIA-Webface \cite{yi2014learning}, 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 \cite{yi2014learning}) and testing datasets (LFW\cite{huang2007labeled} and MegaFace \cite{kemelmacher2016megaface}). 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 \ref{tab:overlap_removal}). To be rigorous, all the experiments in this paper are based on the cleaned dataset. We have made our overlap checking code publicly available\footnote{\url{https://github.com/happynear/FaceDatasets}} to encourage researchers to clean their training datasets before experiments.

\begin{table}[!htb]
\centering
\footnotesize
\label{tab:overlap_removal}
\begin{tabular}{cccccc}
\toprule
Loss & Overlap & MegaFace & MegaFace \
Function & Removal? & Rank1 & VR \
\midrule
%A-Softmax\cite{liu2017sphereface} & No & 73.69\% & 85.05\% \
%A-Softmax\cite{liu2017sphereface} & Yes & 67.41\% & 78.19\% \
AM-Softmax & No & 75.23\% & 87.06\%\
AM-Softmax & Yes & 72.47\% & 84.44\% \
\bottomrule
\end{tabular}
\vspace{2mm}
\caption{Effect of Overlap Removal on modified ResNet-20}
\end{table}

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.

\subsection{Effect of Hyper-parameter $m$}

\begin{figure}
\centering
\includegraphics[scale=0.5]{megaface.pdf}
\caption{ \emph{Left:} CMC curves of different loss functions with 1M distractors on MegaFace\cite{kemelmacher2016megaface} Set 1. \emph{Right:} ROC curves of different loss functions with 1M distractors on MegaFace\cite{kemelmacher2016megaface} Set 1. Note that for Center Loss and NormFace, the backend network is ResNet-28\cite{wen2016discriminative}, while others are based on ResNet-20\cite{liu2017sphereface}. Even though the curves of the Center Loss model and the NormFace model is close to the SphereFace model, please keep in mind that part of the performance comes from the bigger network structure. }
\label{fig:megaface}
\end{figure
}

There are two hyper-parameters in our proposed loss function, one is the scale $s$ and another is the margin $m$. The scale $s$ has already been discussed sufficiently in several previous works \cite{wang2017normface, liu_2017_coco_v2, ranjan2017l2}. In this paper, we directly fixed it to $30$ and will not discuss its effect anymore.

The main hyper-parameter in our loss function is the margin $m$. In Table \ref{tab:performance}, we list the performance of our proposed AM-Softmax loss function with $m$ varies from 0.25 to 0.5. From the table we can see that from $m=0.25$ to $0.3$, the performance improves significantly, and the performance become the best when $m=0.35$ to $m=0.4$.

We also provide the result for the loss function without feature normalization (noted as w/o FN) and the scale $s$. As we explained before, feature normalization performs better on low quality images like MegaFace\cite{kemelmacher2016megaface}, and using the original feature norm performs better on high quality images like LFW \cite{huang2007labeled}.

In Figure \ref{fig:megaface}, 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.

\section{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\cite{liu2017sphereface,liu2016large}, but it is more simple and interpretable. Comprehensive experiments show that our loss function performs better than A-Softmax \cite{liu2017sphereface} on LFW BLUFR \cite{liao2014benchmark} and MegaFace \cite{kemelmacher2016megaface}.

There is still lots of potentials for the research of the large margin strategies. There could be more creative way of specifying the function $\psi(\theta)$ 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.

Learning Transferable Visual Models From Natural Language Supervision

https://huggingface.co/openai/clip-vit-large-patch14

Limitations

CLIP and our analysis of it have a number of limitations. CLIP currently struggles with respect to certain tasks such as fine grained classification and counting objects. CLIP also poses issues with regards to fairness and bias which we discuss in the paper and briefly in the next section. Additionally, our approach to testing CLIP also has an important limitation- in many cases we have used linear probes to evaluate the performance of CLIP and there is evidence suggesting that linear probes can underestimate model performance.

MUGE baseline分析

https://github.com/MUGE-2021/image-retrieval-baseline

https://github.com/MUGE-2021/image-retrieval-baseline/blob/master/src/eval/extract_features.py

图文均normalized
image.png
image.png

https://github.com/MUGE-2021/image-retrieval-baseline/blob/master/src/eval/make_topk_predictions.py
image.png
则此处计算的是余弦相似度

自研笔记

仔细设计,不要把m变成一个无限小或者无限大的量

image.png
似乎可以通过采样直接按这个式子来优化,前两项变成2倍
似乎已经有点region-wise的意思在里面
z1,c1拉近以后,z3如果冲突会拉向相反方向,z3和z1一致的话拉向相同方向
切记要用足够小的学习率来优化
要确认有达标停止机制才能使CL不破坏MLM学习到的语义

image.png
image.png

上面这个式子其实类似于对比学习损失中的某一行或一列,
如果距离函数采用余弦函数开方image.png
最大只能到而e^-1.414,完全反向后就失去优化能力,只优化了角度,没有优化距离,后期换双曲距离其实可以更大
在人脸数据域及配套编码器的条件下,这样的有限优化就足够了
在本研究场景下其实需要优化距离有限,暂不考虑双曲

看MUGE实现
image.png
没做norm那么直接优化的是点积
根据苏剑林博客,
https://kexue.fm/archives/7076
https://zhuanlan.zhihu.com/p/413581747

高维空间向量夹角几乎垂直,似乎主要在优化正例和伪正例,但确实伪正例在推向某种程度的远,但是我们只需要其满足三角不等式就行了

感觉能用(a>b).nonzero()做一个mask,对于满足三角不等式的就不在更新loss
正例拉到无限近也是没有意义的,只要保证三角不等式即可,这样才能保证尽量保留MLM的语义
怎样才能把界的推理引进来,这样的话就很漂亮
似乎可以分真正例,真负例,伪正例,伪负例

欧式距离的批量计算 参考VQ的展开实现