Back to paper library
Paper notesarXiv 2017ACM Multimedia 2017

NormFace

The New Normal

Original paper

NormFace: L2 Hypersphere Embedding for Face Verification

Paper authors

Feng Wang · Xiang Xiang · Jian Cheng · Alan L. Yuille

Publication
ACM Multimedia 2017Conference
First submitted to arXiv
arXiv:1704.06369
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@misc{facerecognitionnormface2017,
  title = {{NormFace: L2 Hypersphere Embedding for Face Verification}},
  author = {Feng Wang and Xiang Xiang and Jian Cheng and Alan L. Yuille},
  year = {2017},
  eprint = {1704.06369},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1704.06369}
}
On this page

In 2016 Wen et al. released a face model trained with softmax plus center loss. Use it for face verification on LFW, taking the inner product of two faces' features directly as the similarity, and accuracy is 98.27%; first divide each feature by its own length, then take the inner product, and it becomes 98.98%.

SimilarityBeforeAfter
Inner product98.2798.98
Euclidean distance98.3598.95

Compiled from Table 1 of the paper (the model released by Wen et al., LFW, %).

Same model, same features, one extra division before comparing, and the error rate drops from 1.73% to 1.02%. LFW's standard protocol has 6,000 photo pairs, half the same person and half different people, split into 10 folds that take turns: 9 to pick the threshold, the remaining 1 to test. In terms of pairs, that is forty-odd fewer mistakes out of 6,000.

This task of "given two faces, are they the same person?" is called face verification, or 1:1 matching. At the time almost every method compared this way at test time: L2-normalize the features first, then compute the cosine similarity. Yet nobody did this during training; the softmax classification layer always computed unnormalized inner products.

The authors of this paper are Feng Wang of the University of Electronic Science and Technology of China (then visiting Alan L. Yuille's lab at Johns Hopkins University), Xiang Xiang of Johns Hopkins University, Jian Cheng of the University of Electronic Science and Technology of China, and Alan L. Yuille. They wanted to move the test-time normalization into training; since normalization is itself differentiable, it looked like a matter of adding one more layer. But once both the features and the last layer's weights were normalized, the network would not train.

The paper traces back from there and answers four questions. Why is normalization at test time so useful? Why does optimizing the cosine directly with softmax fail to converge? What has to change to make it converge? And besides softmax, are there other losses suited to normalized features?

Defining the Problem

Train on inner products, test on angles

Start with how classification-based face recognition trains. The backbone turns an aligned face into a feature vector f\mathbf f, say 512-dimensional; during training it is followed by a fully connected layer whose weight matrix WW has nn columns, one per identity. The jj-th column WjW_j can be seen as the class center of the jj-th identity; its inner product with the feature gives a logit, which softmax turns into a probability, the paper's Eq. (1):

LS=−1m∑i=1mlog⁡eWyi⊤fi+byi∑j=1neWj⊤fi+bj\mathcal L_S=-\frac1m\sum_{i=1}^{m}\log\frac{e^{W_{y_i}^\top\mathbf f_i+b_{y_i}}}{\sum_{j=1}^{n}e^{W_j^\top\mathbf f_i+b_j}}

mm is the number of samples, yiy_i is the identity of the ii-th face, and bjb_j is the bias. After training the fully connected layer is discarded and only the features are kept. None of the test identities appeared in the training set, so the classification layer is no help; all that is left is comparing how alike two features are.

The inner product can be split into three factors:

Wj⊤f=∥Wj∥ ∥f∥cos⁡θjW_j^\top\mathbf f=\|W_j\|\,\|\mathbf f\|\cos\theta_j

θj\theta_j is the angle between the feature and the class center. The cosine similarity used at test time keeps only the last factor. Divide both vectors by their own lengths, call them x~\tilde{\mathbf x} and y~\tilde{\mathbf y}, and the squared Euclidean distance can be written directly in terms of the cosine:

∥x~−y~∥22=2−2 x~⊤y~\|\tilde{\mathbf x}-\tilde{\mathbf y}\|_2^2=2-2\,\tilde{\mathbf x}^\top\tilde{\mathbf y}

That is why, in the opening table, the normalized inner product and Euclidean distance score about the same: they are two sets of markings on the same ruler. During training, though, softmax looks at the product of all three factors.

Softmax likes to stretch features

The authors first ran a toy experiment: reduce the feature dimension of a LeNet on MNIST to 2 and plot the features of ten thousand training samples directly on the plane. Each of the ten digits grows outward from the origin as a spoke, like the spokes of a bicycle wheel. In such a distribution, two points on the same spoke, one near the origin and one far out, can be farther apart in Euclidean distance than points on two neighboring spokes; the angle, meanwhile, keeps them cleanly apart.

Why spokes? The authors state it as Proposition 1. Remove the bias and let Pi(f)P_i(\mathbf f) be the probability that f\mathbf f is assigned to class ii. If class ii already has the highest score, scaling the feature up by s>1s>1 can only make PiP_i larger, never smaller.

The proof takes one step. Let t=s−1>0t=s-1>0 and divide numerator and denominator by et Wi⊤fe^{t\,W_i^\top\mathbf f}:

Pi(sf)=eWi⊤f∑jeWj⊤f+t (Wj⊤f−Wi⊤f)P_i(s\mathbf f)=\frac{e^{W_i^\top\mathbf f}}{\sum_{j}e^{W_j^\top\mathbf f+t\,(W_j^\top\mathbf f-W_i^\top\mathbf f)}}

Class ii has the highest score, so the difference in parentheses Wj⊤f−Wi⊤f≤0W_j^\top\mathbf f-W_i^\top\mathbf f\le 0; every exponent is smaller than before, the denominator shrinks, and Pi(sf)≥Pi(f)P_i(s\mathbf f)\ge P_i(\mathbf f).

Two planar plots stacked vertically. Top: three class weights W₁, W₂, W₃ point to 0°, 120° and 240°, and the plane is divided by class into orange, green and purple sectors. A feature f points at 20°, and along the same dashed line f, 2f, 3f and 5f are marked in turn; on the right, under "Correct-class probability," are 0.66, 0.88, 0.96 and 0.996. Bottom: f₂ at 50° with length 1 and f₃ at 30° with length 4, both in W₁'s orange region; f₁ at 95° with length 1, in W₂'s green region. A blue line joins f₂ and f₁, length 0.77; a black line joins f₂ and f₃, length 3.08; the right side also lists the angles 45° and 20°.
Drawn for this note, computed from Proposition 1 of the paper.

The top plot works it out with three classes. With the feature at 20° and length 1, the correct-class probability is 0.66; keep the direction and make the length 2, 3 and 5, and the probability becomes 0.88, 0.96 and 0.996. The loss −log⁡P-\log P falls accordingly from 0.41 to 0.004. The easiest way for the network to lower the loss is to stretch features that are already classified correctly, so well-classified samples keep running outward and grow into spokes.

The bottom plot shows the trouble this distribution causes. f2f_2 and f3f_3 both belong to class one, but their lengths differ by a factor of 4; f1f_1 belongs to class two and has the same length as f2f_2. By Euclidean distance, f2f_2 is only 0.77 from f1f_1 but 3.08 from f3f_3; by angle, f2f_2 is 20° from f3f_3 and 45° from f1f_1. From start to finish softmax only cares about the class decided by direction; length is a by-product it inflates along the way. Divide out the length at test time, and what you compare is the part softmax actually learned. That answers the first question.

Biases grab the territory near the origin

Proposition 1 has one precondition, that there is no bias. With a bias, two classes can have identical weight directions and be told apart by the bias alone. The authors actually saw this on MNIST: one or two classes had all their points squeezed near the origin. Close to the origin, every class's inner product is small, and whichever bias is larger wins.

Once these points are normalized, they get projected onto every direction of the unit circle and mix with other classes. So this paper adds no bias before softmax. The later SphereFace, CosFace and ArcFace all set the bias to 0 as well.

After normalization, the loss gets stuck

Now normalize both the features and every column of the weights, and the logit is just cos⁡θj\cos\theta_j, the paper's Eq. (5). The trouble is the range, since cos⁡θj\cos\theta_j can only fall within [−1,1][-1,1]. The authors note that with an ordinary inner-product layer plus softmax, logits usually range between ±20\pm20 and ±80\pm80.

Work out the most ideal case. The correct class has cosine 1, and every other class sits on the far side of the hypersphere with cosine −1-1:

Py=e1e1+(n−1) e−1P_{y}=\frac{e^{1}}{e^{1}+(n-1)\,e^{-1}}

With 10 classes this is 0.45; with 1,000 classes only 0.007 is left.

Here, however well the classes are separated, the correct-class probability cannot rise. The softmax gradient on the correct-class logit is 1−Py1-P_y, so perfectly classified samples still get gradients close to 1, about the same as hard samples, and hard samples get no relative extra attention. The authors actually trained on CASIA-WebFace (10,575 identities): the loss fell from about 9.27 to about 8.50 and then would not budge, however long they trained and however small they made the learning rate.

So the question becomes how low the loss can go in this setting.

Solving the Problem

Proposition 2: a lower bound on the loss

The authors' answer is Proposition 2, and we will derive it step by step.

First assume the best case. Every class has the same number of samples, and every sample's feature is exactly equal to its class weight. In addition, normalize both features and weights to the same length ℓ\ell instead of 1. Each class then only needs to look at its own weight WiW_i, and the loss is:

LS=−1n∑i=1nlog⁡eWi⊤Wi∑j=1neWi⊤Wj\mathcal L_S=-\frac1n\sum_{i=1}^{n}\log\frac{e^{W_i^\top W_i}}{\sum_{j=1}^{n}e^{W_i^\top W_j}}

Wi⊤Wi=ℓ2W_i^\top W_i=\ell^2. Divide numerator and denominator by eℓ2e^{\ell^2}; the numerator becomes 1, and the j=ij=i term in the denominator also becomes 1:

LS=1n∑i=1nlog⁡(1+∑j≠ieWi⊤Wj−ℓ2)\mathcal L_S=\frac1n\sum_{i=1}^{n}\log\Big(1+\sum_{j\neq i}e^{W_i^\top W_j-\ell^2}\Big)

Next, apply Jensen's inequality twice. The first time is on exe^x. exe^x is convex, so the average of the n−1n-1 terms eaje^{a_j} is at least ee raised to "the mean of the aja_j"; hence the sum in parentheses is at least (n−1) eaˉi(n-1)\,e^{\bar a_i}, where aˉi\bar a_i is the mean of Wi⊤Wj−ℓ2W_i^\top W_j-\ell^2 over all j≠ij\neq i. The second time is on log⁡(1+Cex)\log(1+Ce^x), which is also convex in xx, so when averaging over ii the average can likewise be moved inside. Together:

LS≥log⁡(1+(n−1) eaˉ)\mathcal L_S\ge\log\Big(1+(n-1)\,e^{\bar a}\Big) aˉ=1n(n−1)∑i=1n∑j≠i(Wi⊤Wj−ℓ2)\bar a=\frac{1}{n(n-1)}\sum_{i=1}^{n}\sum_{j\neq i}\big(W_i^\top W_j-\ell^2\big)

aˉ\bar a is the average inner product between any two different class centers, minus ℓ2\ell^2. The remaining question is how low the average pairwise inner product of these class centers can go.

Here a simple fact helps. The vector obtained by adding up all the class centers cannot have a negative squared length:

∥∑i=1nWi∥2=nℓ2+∑i=1n∑j≠iWi⊤Wj ≥ 0\Big\|\sum_{i=1}^{n}W_i\Big\|^2=n\ell^2+\sum_{i=1}^{n}\sum_{j\neq i}W_i^\top W_j\ \ge\ 0

So the pairwise inner products sum to at least −nℓ2-n\ell^2, and their mean is at least −ℓ2/(n−1)-\ell^2/(n-1). Try three classes on a plane: three unit vectors 120° apart have pairwise cosines of −0.5-0.5, exactly −1/(3−1)-1/(3-1). With more classes this lower limit approaches 0; with ten thousand classes it is about −0.0001-0.0001. On average, the other classes can at best be perpendicular to you.

Substituting back, aˉ≥−ℓ2/(n−1)−ℓ2=−nn−1ℓ2\bar a\ge-\ell^2/(n-1)-\ell^2=-\frac{n}{n-1}\ell^2, which gives Proposition 2:

LS≥log⁡(1+(n−1) e−nn−1ℓ2)\mathcal L_S\ge\log\Big(1+(n-1)\,e^{-\frac{n}{n-1}\ell^2}\Big)

For equality to hold, all pairwise inner products of the class centers must be equal and the centers must sum to the zero vector, that is, a regular simplex (the family of the equilateral triangle and the regular tetrahedron). A dd-dimensional space can hold at most d+1d+1 such points, and the number of face classes far exceeds the feature dimension, so in practice this bound is never reached; the loss always stays above it.

Plug in CASIA-WebFace's numbers. With n=10,575n=10{,}575 and ℓ=1\ell=1, (n−1)e−1.0001≈3,890(n-1)e^{-1.0001}\approx3{,}890, and the bound is log⁡3,891≈8.27\log 3{,}891\approx8.27. Compare that with the starting point: having learned nothing, with every class equally probable, the loss is log⁡10,575≈9.27\log 10{,}575\approx9.27. In other words, even if the model classified every face perfectly, the loss could only fall from 9.27 to 8.27; the measured loss stalled at 8.50, just 0.23 above the bound, from which the authors conclude the bound is quite tight.

The fix: make the sphere bigger

The only thing in the bound that can move is ℓ\ell. Normalize features and weights to a larger length and the logit becomes ℓ2cos⁡θj\ell^2\cos\theta_j, with its range scaled up accordingly. In practice there is no need to actually change the lengths on both sides: put a scale layer with a single parameter after the cosine layer, let s=ℓ2s=\ell^2, and you get the paper's Eq. (6):

LS′=−1m∑i=1mlog⁡es W~yi⊤f~i∑j=1nes W~j⊤f~i\mathcal L_{S'}=-\frac1m\sum_{i=1}^{m}\log\frac{e^{s\,\tilde W_{y_i}^\top\tilde{\mathbf f}_i}}{\sum_{j=1}^{n}e^{s\,\tilde W_j^\top\tilde{\mathbf f}_i}}

The tilde marks normalized vectors. How large does ss need to be? Plot Proposition 2 against ss.

A line chart; the horizontal axis is the scale s, from 0 to 24; the vertical axis is the loss lower bound, from 0 to 12. Four curves from bottom to top: 10 classes (gray dashed), 1,000 (blue), 10,572 (orange, CASIA-WebFace) and 85,742 (purple, MS1MV2), all falling from the upper left to near 0 at the lower right. The orange line is marked at s = 1 with the bound 8.27, with a note that the paper's training stalls near 8.50. The orange and purple lines each carry a dot marking the s needed for the correct-class probability to reach 0.9, about 11.5 and 13.6 respectively.
Drawn for this note, computed from Proposition 2 of the paper.

The four curves look much alike. At s=0s=0 the bound is log⁡n\log n, the loss when every class is equally probable; the more classes, the higher the starting point and the later the curve reaches 0. On CASIA-WebFace's orange curve, the bound is down to 0.39 at s=10s=10 and just 0.001 at s=16s=16; with MS1MV2's 85,742 classes, it is still 1.59 at s=10s=10.

You can also ask it the other way around. If you want a perfectly classified sample to reach a correct-class probability of at least PP, the bound must not exceed −log⁡P-\log P, which solves to:

s ≥ n−1n log⁡(n−1) P1−Ps\ \ge\ \frac{n-1}{n}\,\log\frac{(n-1)\,P}{1-P}

For P=0.9P=0.9, CASIA-WebFace needs 11.5 and MS1MV2 needs 13.6; for P=0.99P=0.99, 13.9 and 16.0 respectively. Eight times as many classes need only about 2 more in ss, because the number of classes sits inside a logarithm.

The paper suggests that a fixed value be 20 or 30 depending on the number of classes; the authors themselves prefer to let ss be learned through backpropagation, because they do not want an extra hyperparameter. The official scaled_cosine_softmax.prototxt is set up exactly this way: the scale layer starts at 10, is learnable and has a lower limit of 0.01; the inner-product layer before it has no bias; and there are 10,572 classes (CASIA-WebFace minus the 3 identities that overlap with LFW).

The gradient of the normalization layer

The paper also derives how the normalization layer itself backpropagates. Let x~=x/∥x∥\tilde{\mathbf x}=\mathbf x/\|\mathbf x\|, where x\mathbf x can be a feature or a column of the weights (in practice a tiny ε\varepsilon is also added to the denominator to avoid dividing by zero). The partial derivative of x~j\tilde x_j with respect to xix_i has two parts: the numerator xjx_j contributes only when j=ij=i, while the length in the denominator depends on every component:

∂x~j∂xi=δij∥x∥−xi xj∥x∥3\frac{\partial\tilde x_j}{\partial x_i}=\frac{\delta_{ij}}{\|\mathbf x\|}-\frac{x_i\,x_j}{\|\mathbf x\|^3}

δij\delta_{ij} is 1 when i=ji=j and 0 otherwise. Sum over all jj with the chain rule and tidy it into vector form, and you get the paper's Eq. (4):

∂L∂x=1∥x∥(g−x~ (x~⊤g)),g=∂L∂x~\frac{\partial\mathcal L}{\partial\mathbf x}=\frac{1}{\|\mathbf x\|}\Big(\mathbf g-\tilde{\mathbf x}\,(\tilde{\mathbf x}^\top\mathbf g)\Big),\qquad\mathbf g=\frac{\partial\mathcal L}{\partial\tilde{\mathbf x}}

The parentheses subtract the component of the upstream gradient g\mathbf g along x~\tilde{\mathbf x}, keeping only the part perpendicular to x\mathbf x, which is then divided by the length.

A geometric diagram. The origin is at the lower left, with a gray arc of the unit circle. A black arrow x̃ points from the origin to (0.6, 0.8) on the circle. From the tip of x̃, the gray upstream gradient (1, 0) is drawn and split into an orange dashed component labeled Radial, along x̃, and a blue component labeled Tangential, pointing down and to the right, perpendicular to x̃. A green arrow labeled One step goes against the tangential component and ends on a gray dashed arc labeled Length 1.17. At the upper right, under "One gradient, three lengths," lengths 0.5, 1 and 2 are listed with gradients of 1.6, 0.8 and 0.4.
Drawn for this note, computed from Eq. (4) of the paper.

Walk through it with numbers. x~=(0.6,0.8)\tilde{\mathbf x}=(0.6,0.8), and suppose the upstream gradient is g=(1,0)\mathbf g=(1,0). x~⊤g=0.6\tilde{\mathbf x}^\top\mathbf g=0.6; subtract the radial component 0.6 x~=(0.36,0.48)0.6\,\tilde{\mathbf x}=(0.36,0.48) and (0.64,−0.48)(0.64,-0.48) is left, whose inner product with x~\tilde{\mathbf x} is 0.384−0.384=00.384-0.384=0, so it is indeed perpendicular, with length 0.8. This has two consequences.

First, the gradient always lies along the tangent, so a step along it always carries the point off the circle and outward. A point of length 1 that takes one step along the tangent, say with learning rate 0.75, moves 0.6, and its new length is 1+0.36≈1.17\sqrt{1+0.36}\approx1.17; that is just the Pythagorean theorem. As the weights keep getting updated, their lengths keep growing, which is why the authors say normalized vectors need weight decay to hold their lengths in check. The official code uses another trick, rewriting the weights to unit length directly in the forward pass (Feng Wang's explanation in issue #4) and setting that layer's weight decay to 0.

Second, the gradient is divided by the length. For the same upstream gradient, a feature of length 0.5 gets 1.6 and a feature of length 2 gets only 0.4, a factor of 4 apart. Feng Wang later filled in the other side of this in the AM-Softmax paper. Low-quality faces usually have smaller feature norms, so after normalization they receive larger gradients, a bit like hard example mining; when the norm is very small, the gradient can also become large enough to be unstable.

Another loss: give each class an agent

The fourth question is whether, besides softmax, the losses of the metric learning school can take normalized features directly.

The two most common metric learning losses are contrastive and triplet. Contrastive takes two faces and pulls them together if they are the same person, or pushes them beyond a margin mm if not (Eq. (7)); triplet takes three faces and requires the anchor's distance to the same person plus mm to still be smaller than its distance to the other person (Eq. (8)). Both are already commonly used on normalized features; the trouble is sampling. With NN faces in the training set there are O(N2)O(N^2) pairs and O(N3)O(N^3) triplets; CASIA-WebFace has about 490,000 images, so the pairs alone exceed a hundred billion, and the only way through is sampling and hard example mining, which is slow and hard to tune. A classification loss only needs to look at each of the NN faces once per epoch.

The authors first rewrite the normalized softmax. Substitute x~⊤y~=1−12∥x~−y~∥2\tilde{\mathbf x}^\top\tilde{\mathbf y}=1-\frac12\|\tilde{\mathbf x}-\tilde{\mathbf y}\|^2 into Eq. (6); every exponent picks up a common ese^{s}, which cancels between numerator and denominator, leaving distances (Eq. (9)):

LS′=−1m∑i=1mlog⁡e−s2∥f~i−W~yi∥22∑j=1ne−s2∥f~i−W~j∥22\mathcal L_{S'}=-\frac1m\sum_{i=1}^{m}\log\frac{e^{-\frac s2\|\tilde{\mathbf f}_i-\tilde W_{y_i}\|_2^2}}{\sum_{j=1}^{n}e^{-\frac s2\|\tilde{\mathbf f}_i-\tilde W_j\|_2^2}}

Normalized softmax is in fact also comparing the Euclidean distance between the feature and each class center. Following this idea, replace "the other face" in contrastive and triplet with the weight WjW_j of the class that face belongs to; the authors call it the class's agent, and it is learned by backpropagation just like the weights of a fully connected layer. This gives C-contrastive, Eq. (10):

LC′={∥f~i−W~j∥22,ci=jmax⁡(0,m−∥f~i−W~j∥22),ci≠j\mathcal L_{C'}= \begin{cases} \|\tilde{\mathbf f}_i-\tilde W_j\|_2^2, & c_i=j\\ \max(0,m-\|\tilde{\mathbf f}_i-\tilde W_j\|_2^2), & c_i\neq j \end{cases}

and C-triplet, Eq. (11):

LT′=max⁡(0, m+∥f~i−W~j∥22−∥f~i−W~k∥22)\begin{aligned} \mathcal L_{T'}=\max\big(0,\ &m+\|\tilde{\mathbf f}_i-\tilde W_j\|_2^2\\ &-\|\tilde{\mathbf f}_i-\tilde W_k\|_2^2\big) \end{aligned}

cic_i is the identity of the ii-th face; in C-triplet, jj is its own class and kk another class. Each face is compared only against the nn agents, with no pairs to assemble.

Where do the agents settle? With m=0m=0, C-contrastive keeps only the term that pulls features toward their own agent, and the agent ends up near the mean of its class's features, which is exactly what center loss does (in the official repo, the authors reproduce center loss precisely by setting the margin to 0). With m>0m>0, features of other classes inside the margin also push the agent, so agents at the border between two classes get pushed apart; and hard samples stuck at the border receive larger gradients.

The cost is an approximation. What used to be the distance between two real samples now has an agent on one side, and some features near the margin that the original loss would handle end up outside the margin once the agent stands in, and are no longer optimized. Proposition 3 bounds this distortion with the triangle inequality. Using the agent WiW_i in place of every sample fj\mathbf f_j in the class, the average squared error in distance is no more than the average squared distance from the class's features to the agent. This quantity can be computed on the fly during training with a moving average; the authors observed it to be about 0.5 to 0.6, and so recommend a somewhat larger margin: 1 for C-contrastive and 0.8 for C-triplet.

These distances are all squared distances after normalization, ranging from 0 to 4. In terms of angles it is easier to picture: a squared distance of 1 corresponds to a cosine of 0.5, that is, 60°. C-contrastive's m=1m=1 means pushing every other class's agent beyond 60°. C-triplet's m=0.8m=0.8 is relative instead: if a face is 30° from its own agent, a squared distance of 2−2cos⁡30∘≈0.272-2\cos30^\circ\approx0.27, then the agents of other classes must be beyond a squared distance of 1.07, about 62°.

The old practice was to stop every few epochs and search for the margin again, because the feature lengths kept changing. Normalization pins the length down, so the margin can stay fixed too.

Discussion

Experimental setup

The authors picked two public models as baselines and fine-tuned them with the new losses rather than training from scratch. The two baselines are:

  • Wu et al.'s Light CNN: a plain 10-layer CNN with Maxout activations;
  • Wen et al.'s ResNet: 28 layers, trained with softmax plus center loss, which is the model from the opening.

Neither model uses feature or weight normalization, and both are trained only on CASIA-WebFace. The loss is attached after the penultimate layer's features, with features and weights first normalized to 1. Wu's model uses a learning rate of 0.0001 and Wen's 0.001, with SGD, momentum 0.9 and batch size 256. After convergence they train another 5,000 iterations, saving every 1,000, and evaluate each of the five checkpoints and average.

At evaluation, features are extracted once from the original image and once from its horizontal flip and added element-wise; PCA is then fitted on the training folds of the evaluation set, and finally the cosine after PCA is used as the similarity. LFW has 13,233 images of 5,749 people; besides the standard 6,000-pair protocol, BLUFR is also used, covered below. CASIA-WebFace shares identities with LFW; the paper says it removed 3, while the official README later updated this, saying 17 actually overlap.

Normalization is the real star

First, LFW's 6,000 pairs with Wen et al.'s model:

LossNormalizedLFW
softmaxNone98.28
softmax + centerNone99.03
softmaxFeature only98.72
softmaxWeight only98.95
softmaxBoth99.16
C-contrastiveBoth99.15
C-tripletBoth99.11
softmax + C-contrastiveBoth99.19

Compiled from Table 2 of the paper (%); the second row is the baseline model itself.

With both features and weights normalized, the four losses land between 99.11 and 99.19, only 0.08 percentage points apart; the authors conclude that the choice of loss matters little and normalization is the key. Compared with the baseline, 99.03 to 99.19, the error rate falls from 0.97% to 0.81%, about 10 fewer mistakes out of 6,000 pairs. By this time LFW was already squeezed above 99%, and that is all the room there was.

The two experiments that normalize only one side are more intriguing. Normalizing only the weights gives 98.95, about the same as the baseline; normalizing only the features gives 98.72, actually worse than the baseline. The authors also found that normalizing only the features requires a scale layer, or the network collapses, while normalizing only the weights does not; the paper says flatly that they cannot explain this for now. Training from scratch is different again: normalizing only the weights collapses, while normalizing only the features reaches 98.45%, better than plain softmax but far short of the best losses of the time.

How the two losses are weighted when mixed also matters. For softmax plus C-contrastive, with the C-contrastive weight varied from 0.001 to 100, accuracy stays between 99.17% and 99.19%; for softmax plus center loss, accuracy drops to about 99.0% once the weight reaches 1, below the baseline. The authors' explanation is that C-contrastive can train a model on its own, while center loss only shrinks intra-class distance and has to be propped up by another loss.

Switching to Wu et al.'s Light CNN, the baseline with flip fusion is 98.41%, normalized softmax is 98.75% and C-contrastive is 98.78%, a gain of 0.37 percentage points.

Lower the threshold, widen the gap

LFW's 6,000 pairs are too few to measure performance at low false-accept rates. The BLUFR protocol uses all 13,233 LFW images over 10 trials and reports two numbers:

  • TPR@FAR=0.1%: 1:1 verification; with the threshold set so that only one in every thousand different-person pairs is falsely accepted, the share of same-person pairs that pass;
  • DIR@FAR=1%: open-set identification, that is, 1:N. A face is compared against a database, and the closest match must be the right person and also score above the threshold; the threshold is set so that only 1% of strangers not in the database are misidentified.
ModelLoss0.1%DIR
ResNetBaseline93.3567.86
ResNetsoftmax95.7773.92
ResNetsoftmax + C-contrastive95.8377.18
Light CNNBaseline89.1261.79
Light CNNsoftmax90.6465.22
Light CNNC-contrastive90.3268.14

Compiled from Table 3 of the paper (%); "Baseline" is the original model without normalization, and all others are normalized; the "0.1%" column is TPR@FAR=0.1% and the "DIR" column is DIR@FAR=1%.

Two models only 0.16 percentage points apart on the 6,000 pairs differ by 9.3 percentage points on the 1:N DIR. The agent loss also shows its use here: with normalization in both cases, DIR goes further from 73.92% to 77.18%, and Light CNN from 65.22% to 68.14%; on LFW's standard protocol these differences are nearly invisible.

Video: beyond the average

YouTube Faces (YTF) has 1,595 people and 3,425 video clips, and tests whether 5,000 pairs of clips show the same person. The usual approach computes the cosine between every frame of one clip and every frame of the other, giving a similarity matrix, and takes the mean as the pair's score.

The authors instead take a 100-bin histogram of the whole matrix as the pair's feature and hand it to an SVM with a histogram intersection kernel to decide whether it is the same person; the table calls this HIK-SVM. The histogram keeps "how many frame pairs are very alike and how many are not alike at all," while the mean leaves just one number.

LossNormalizedYTF
softmax + centerNo93.74
softmaxYes94.24
softmax + HIK-SVMYes94.56
softmax + C-contrastiveYes94.34
softmax + C-contrastive + HIK-SVMYes94.72

Compiled from Table 5 of the paper (Wen et al.'s model, %).

Normalization brings 0.5 percentage points, and the histogram adds another 0.3 to 0.4.

All of it is fine-tuned

In the tables above, every number with normalization comes from fine-tuning an existing model (climbing a little higher from someone else's summit). The paper's own conclusion admits that for now this is the only way to use it: trained from scratch with C-contrastive, the results are as good as center loss, and only fine-tuning goes higher.

The official repo's issues are more specific. In issue #1 (April 2017), Feng Wang replied that training the scaled softmax from scratch "is similar with softmax," and that training C-contrastive from scratch can reach 98.9%, close to center loss but not beyond it. In issue #14 (July 2017), a user trained a feature-only-normalized version with a fixed scale from scratch and got around 99%; Feng Wang said that C-contrastive from scratch could also reach 99% for them, but that they "fail to get good results using normalized softmax loss." Step 4 of the README's training instructions says it outright too: fine-tune from the original model with a small learning rate.

When someone asked in issue #22 why there was no comparison with triplet, the author's answer was that they could not get reasonable triplet results themselves, nor find code that could, and pointed the asker to the triplet numbers in the SphereFace paper.

The author looking back

In September 2017, someone asked in issue #21 whether NormFace could be combined with SphereFace. Feng Wang replied the same day that simply merging the two only makes things worse and that the right way to do it was being written up as a paper; in November they said that route had failed: the new method only helped on BLUFR, was about the same as SphereFace on MegaFace, and was not good enough for a top conference. The next day, Feng Wang said something very candid about NormFace itself. The gist was that NormFace actually has no theoretical basis; it rests only on "a methodology that we should make training and testing consistent," and whether features should be normalized at all is still doubtful.

The author also offered their later understanding. Feature normalization lets us control the temperature of softmax directly, which is the scale ss in the paper; ordinary softmax cannot, because the temperature gets absorbed into the preceding layers. Put another way, without normalization the network can tune the temperature itself by stretching the features, and Proposition 1 shows it has a motive to do so; normalization takes this knob out of the network's hands and gives it to ss.

The same reply also listed the drawbacks. Normalized features can only move along the surface of the sphere and cannot pass through the inside; it is also unstable near the origin, where a small disturbance can carry a feature across the origin and, after normalization, flip it to the other side of the sphere. This is the same thing as the gradient being divided by the length earlier.

How the scale ss was settled later

Around the same time as NormFace, several other papers were working on the same knob.

L2-softmax (Ranjan, Castillo, Chellappa) appeared on arXiv a little over three weeks before NormFace. It normalizes only the features, to length α\alpha, leaving the weights alone, and also derives a lower bound αlow=log⁡p(C−2)1−p\alpha_{\text{low}}=\log\frac{p(C-2)}{1-p}, assuming the class centers are pairwise at least 90° apart. Its experimental conclusion is the opposite of NormFace's preference: when the network learns α\alpha itself, the learned value comes out large and the constraint loose, and fixing it to a smaller constant works better. On 13,403 identities, results stabilize once α\alpha exceeds 12, close to the 11.7 computed for p=0.9p=0.9; on the final 58,000-person dataset they use α=50\alpha=50.

AM-Softmax is Feng Wang's own next paper, posted to arXiv in January 2018, which subtracts a margin mm from the cosine. The paper says NormFace lets ss be learned through backpropagation, but once the margin is added, ss does not grow and the network converges very slowly, so they fix ss at 30. The same paper's comparison table includes NormFace too (fine-tuned from the center loss model), with a rank-1 of 65.03% on MegaFace with a million distractors, against 72.47% for AM-Softmax (with different backbones).

CosFace came 12 days later and also uses a subtractive margin. Its Eq. (6) gives a lower bound on ss, s≥C−1Clog⁡(C−1)PW1−PWs\ge\frac{C-1}{C}\log\frac{(C-1)P_W}{1-P_W}; the derivation in its supplementary material likewise relies on Jensen's inequality and "the squared length of the sum of class centers is non-negative," and the result is exactly the formula solved above from "pushing the bound below −log⁡P-\log P"; in its experiments, though, ss is set empirically to 64. ArcFace's first version also uses 64, citing L2-softmax's lower bound and Tencent's FaceCNN as the basis.

Conclusion

NormFace explains test-time normalization as a side effect of softmax. Without a bias, well-classified features get stretched further and further, and dividing out the length at matching time leaves just the direction to compare. Direct normalization fails to train because the logits are locked inside [−1,1][-1,1], and Proposition 2 computes that on CASIA-WebFace the loss can go no lower than 8.27; adding a scale ss unlocks it. The agents, meanwhile, free contrastive and triplet from assembling pairs. The experiments are all fine-tuning on two CASIA-WebFace models, with LFW gains of at most 0.16 and 0.37 percentage points and BLUFR's 1:N metric improving by up to 9.3 percentage points.

When training your own cosine classification head, first remove the bias from the last layer, then estimate ss from the number of classes. n−1nlog⁡(n−1)P1−P\frac{n-1}{n}\log\frac{(n-1)P}{1-P} with P=0.9P=0.9 gives about 11.5 for ten thousand classes and about 13.6 for eighty-odd thousand, so the common 64 leaves plenty of headroom; if you add a margin, follow AM-Softmax's experience and fix ss rather than letting it learn. The same applies when matching with someone else's model: normalize the features before computing the similarity.

CosFace, ArcFace and CurricularFace all later wrote ss as a flat 64; not one of them let it learn on its own.