TL;DR
FaceNet trains a deep convolutional network so that each face photo becomes a 128-number vector, and two photos of the same person land close together while photos of different people land far apart. The network is trained directly on that distance, using triplets of an anchor, a matching photo and a non-matching photo. With the vectors in hand, face verification is a distance threshold, recognition is nearest-neighbour search, and clustering is a standard algorithm run on the vectors. It reached 99.63% on Labeled Faces in the Wild at the time.
Builds on: Convolutional Neural Network, Euclidean Distance, Triplet Loss, Stochastic Gradient Descent · Leads to: contrastive methods that also train embeddings from pairs or triplets
Why it mattered
Before FaceNet, most deep face recognisers trained a classifier over known identities and used an intermediate layer as the face description. That description generalised less well to new people. FaceNet made the embedding itself the training target, so the vector, a learned representation, is what the loss shapes. Its accuracy on the standard LFW benchmark, 99.63% with face alignment, was described in the paper as a record and cut the error of an earlier DeepFace result by more than a factor of seven. The 128-byte output is also compact enough for large-scale search and for clustering a user's personal photos.
The problem
Face recognition at scale needs three things: a yes-or-no check that two photos show the same person, a lookup that finds who a photo shows, and grouping of many photos into people. Classifier-based systems answer only for identities seen in training, and they need a retraining step for each new person. A distance-based system can handle a new person with no retraining, provided the distances mean "same person or not" for faces it has never seen. The open question was how to train a network so that the distance itself has that meaning.
How it works
Take one anchor photo of person A. Take one more photo of A (the positive) and one photo of person B (the negative). The network maps each photo to a point on a sphere in 128 dimensions, so each photo is a vector of length 1. Use three made-up squared distances to see the idea.
- Embed the three photos. The network outputs three unit vectors: anchor , positive , negative .
- Measure two squared distances. Compute and . Suppose the first is 0.3 and the second is 0.4.
- Compare them with a margin. The margin is 0.2 in the paper. Compute . Check: the positive is not yet at least 0.2 closer than the negative, so the triplet still costs something.
- Turn the gap into a loss. The loss is the positive part of that number, meaning the number itself if it is positive and 0 otherwise, so . Check: if the negative were 0.6 instead, the number would be , and the loss would be 0.
- Update the network. Gradient descent changes the network so the anchor moves toward the positive and away from the negative. Repeat over many triplets until the loss is zero for most of them.
- Use the result. Two photos are the same person if their distance is below a threshold. The paper's LFW threshold is 1.242 in its distance units, and that threshold was chosen on the training folds of LFW.
The important choice is which triplets to use. Most triplets are easy and teach nothing, so the paper mines them inside each training batch, favouring semi-hard negatives that are farther than the positive but still within the margin.
flowchart LR
B[Batch of about 1800 faces, about 40 per person] --> E[Deep CNN embeds each face as a 128-number unit vector]
E --> M[Mine triplets inside the batch: semi-hard negatives]
M --> L[Triplet loss with margin 0.2]
L --> G[SGD updates the network]
G --> E
The math
For an image , the network gives an embedding with . For anchor , positive (same person) and negative (different person), the loss over the training set is
where and is the margin, set to .
Step 1 in symbols: the unit-length constraint
Each embedding is scaled to length 1, so every face lies on a hypersphere. The squared distance between two unit vectors is , where is the angle between them and is the cosine similarity. Distances therefore depend only on direction, which removes one way for the network to cheat by making vectors longer.
Step 2 in symbols: which negatives to use
Among triplets in a batch, the paper keeps semi-hard negatives, those with
The left inequality says the negative is farther than the positive. The right one says it is still inside the margin, so it is hard. The closest negatives tend to be mislabelled or badly imaged faces, and always picking the hardest negative can collapse the network to producing the same output for every image () early in training.
Step 3 in symbols: the margin condition
The loss is zero exactly when every triplet satisfies
In words: the anchor is closer to its positive than to any negative by at least the margin. With the numbers from the walkthrough, is not less than , so that triplet is violated.
Step 4 in symbols: the hinge
The bracket is a hinge: it is zero when the margin condition holds and grows linearly when it does not. That is why easy triplets contribute nothing to the loss and hard ones dominate it.
Results
- Labeled Faces in the Wild (LFW), unrestricted protocol: 99.63% ± 0.09 with the extra face alignment step, and 98.87% ± 0.15 with a fixed centre crop. The paper reports that the alignment version reduces the error of an earlier DeepFace result by more than a factor of 7.
- YouTube Faces DB: 95.12% ± 0.39 using the first 100 frames of each video. The earlier DeepId2+ result was 93.2%.
- Compact output: the embedding is 128 numbers, quantised to 128 bytes without loss of accuracy, according to the paper.
- Model sizes: the large Zeiler-and-Fergus-style network NN1 has 140 million parameters and about 1.6 billion FLOPS per image. The small Inception-style NNS2 has 4.3 million parameters and 20 million FLOPS, and the paper says it runs at about 30 ms per image on a mobile phone.
- Embedding size: on a hold-out set at a false accept rate of 0.001, 128 dimensions gave 87.9% ± 1.9, against 86.8% for 64, 87.7% for 256 and 85.6% for 512. The paper calls these differences statistically insignificant, and chose 128 for its experiments.
- Training data: 100 to 200 million face thumbnails covering about 8 million identities. The paper reports that tens of millions of images reduced error by 60% relative to millions, on a smaller model, and that hundreds of millions gave a smaller further gain.
- Training cost: the paper reports 1,000 to 2,000 hours on a CPU cluster, with a starting learning rate of 0.05, and batches of about 1,800 faces.
The limits matter too. The clustering and recognition results rely on the embedding quality for the people who appear in the test data. The paper also notes that the very low false accept rate region of its personal-photo curve is affected by noisy labels, so a single mislabelled image can move that curve a lot.
Reading guide
- Section 1, Introduction: the three tasks (verification, recognition, clustering) and why a single embedding serves all three.
- Section 2, Related work: classifier-based bottleneck features and Siamese-style pair losses. Read Siamese Network and Contrastive Learning first.
- Section 3.1, Triplet loss: the formula above. Needs Triplet Loss and Euclidean Distance.
- Section 3.2, Triplet selection: online mining within a batch and semi-hard negatives. Needs the batch and sampling ideas in Stochastic Gradient Descent.
- Section 3.3, Architectures: the two families of convolutional networks, Zeiler-and-Fergus style and Inception style. Read Convolutional Neural Network and Going deeper with convolutions.
- Sections 4 and 5, Data and evaluation: the threshold, false accept and validation rates, and LFW and YouTube Faces protocols. The clustering results use off-the-shelf grouping methods on the same vectors, such as K-Means Clustering or agglomerative clustering.
Check yourself
QuestionRecall: what does the triplet loss ask the embedding to do?Show answer
It asks that the anchor be closer to its positive than to its negative by at least the margin . Triplets that already satisfy this contribute zero loss.
QuestionCompute: squared distances are 0.5 for the positive and 0.9 for the negative, and . What is the loss for this triplet?Show answer
The bracket is . The positive part of is 0, so the loss is 0. The triplet already satisfies the margin.
QuestionWhy: why does FaceNet pick semi-hard negatives instead of always the hardest one?Show answer
Always taking the hardest negative can drive early training into bad local minima, including a collapsed network that maps every image to the same output. Semi-hard negatives are still informative but do not dominate training with mislabelled or very difficult faces.
QuestionApplied: a team wants to add a new person to a face system without retraining. Does FaceNet's design allow it, and what must hold?Show answer
Yes, in principle. A new person needs only their photos embedded and compared by distance. This holds only if the learned distances generalise, meaning same-person faces stay within the verification threshold for identities the network never saw. FaceNet's evaluation on held-out identities is the evidence the paper offers for that.