Skip to content
Deep Dive

Why Face Matching Uses Two Neural Networks at Once

Face matching uses a Siamese network architecture, one network applied to two faces, because a plain classifier can only recognise the people it was trained on. Comparing embeddings instead lets the system match faces it has never seen, including celebrities who became famous after training. Celebrity embeddings are computed in advance, so each search runs the network only once, on your photo.

Liam BradleySeptember 14, 2026 · 5 min read
Diagram of a feed-forward neural network with weighted layers
Image: QuantuMechaniX8, CC0, via Wikimedia Commons

Why a Single Network Is Not Enough

The intuitive approach to face recognition would be a classifier: a network that takes a face image and outputs the identity of the person. This works when you have a fixed, known set of identities with plenty of training images each. But it breaks down completely for the celebrity matching use case, you want to match against celebrities the network has never seen during training, including people who only became famous after the model was built.

What is actually needed is a network that learns a general notion of facial similarity, one that transfers to new identities it has never encountered. This requires a completely different training approach: instead of asking the network to name a face, you ask it whether two face photographs show the same person.

The Siamese Architecture

A Siamese network consists of two identical copies of the same neural network, sharing exactly the same weights, processing two face images simultaneously. Each copy independently produces an embedding for its input. A distance function then measures how far apart the two embeddings are in the embedding space. The network is trained by showing it labelled face pairs: same-identity pairs (the distance should be small) and different-identity pairs (the distance should be large).

The critical innovation is shared weights. Both copies are not just similar, they are literally the same network applied twice. This guarantees that both embeddings live in exactly the same mathematical space, making it meaningful to compute a distance between them. If you trained two separate networks independently, their embeddings would inhabit incompatible spaces and distance computation would be meaningless.

Training: Learning General Similarity

Training a Siamese network requires constructing pairs of face images with known identity labels. The loss function, typically contrastive loss or triplet loss, adjusts the network weights to pull same-identity embeddings together while pushing different-identity embeddings apart by at least a specified margin. Through millions of such pair comparisons, the network learns what makes faces similar at a structural level.

This pair-based training is what enables generalisation to completely new identities. The network has not learned to recognise any specific celebrity's face. It has learned a general structural notion of similarity, one that transfers immediately to any new face it encounters. When you upload a photo of yourself, the network produces an embedding based on the same learned notion of similarity, placing you in the same space as every celebrity it has ever processed.

The same trick applies to Ollie at inference time, even though its network was trained with the CosFace loss rather than with pairs: because one network embeds every face, celebrity embeddings only need to be computed once and stored. When you upload a photo, only your embedding needs to be computed. The search then compares your single embedding against thousands of pre-computed celebrity embeddings, a much more efficient process than running two networks for each comparison.

This pre-computation approach is why the search is so fast. The expensive neural network computation runs once (your photo); the subsequent similarity search in the pre-built index is very fast regardless of database size.

Frequently Asked Questions

Why is it called a Siamese network?

Because it uses two identical, weight-sharing network copies processing inputs in parallel, like Siamese twins. The shared weights ensure both outputs are in the same mathematical space.

Do Siamese networks only work for faces?

No. Siamese networks are used for any pairwise similarity problem: signature verification, drug molecule similarity, image retrieval, question answering similarity. The architecture is general; the training data is domain-specific.

How does a Siamese network learn without being told who each celebrity is?

It learns from pairs: photos labelled as same-person or different-person. It does not need to know the identity, only whether two photos match. This weaker supervision is easier to collect and scales to larger datasets.

Try it yourself

Find your celebrity lookalike

Upload a photo and see which celebrities you look most like. Free to try, and your photo is never stored.

Find my celebrity look alike

Related Articles