Skip to content
Deep Dive

Siamese Neural Networks Explained: The Twin-Network Idea Behind Face Matching

A Siamese neural network compares two inputs by passing both through the same network and measuring the distance between the two embeddings: close means similar, far means different. It is a classic approach to face verification and signature checking. Ollie uses the same idea, one shared network that turns every face into comparable numbers, though it was trained with a different loss.

Liam BradleyAugust 10, 2026 · 5 min read
Illustration of a brain drawn as circuit traces
Image: mikemacmarketing / original posted on flickr Liam Huang / clipped and posted on…, CC BY 2.0, via Wikimedia Commons (resized)

What Is a Siamese Network?

A Siamese neural network is built to answer one question: how similar are these two things? It passes both inputs through the same network, turns each into a list of numbers (an embedding), and measures the distance between the two lists. A small distance means similar; a large distance means different.

The name comes from the picture of two identical networks side by side, like twins. In practice there is only one network, used twice. Its two branches share exactly the same weights.

Why the Shared Weights Matter

Because both inputs go through the same weights, their embeddings live in the same space and the distance between them means something. Two separately trained networks would each invent their own coordinate system, and comparing their outputs would be like comparing a distance in miles with one in kilometres.

Shared weights also mean that anything can be embedded once and compared later. That is what makes large-scale search practical: every stored item is embedded ahead of time, and a new query only needs one pass through the network.

How Siamese Networks Are Trained

The classic way to train a Siamese network is with pairs. Contrastive loss shows the network two examples labelled same or different, pulling same pairs together and pushing different pairs at least a set margin apart. Triplet loss uses an anchor, a matching example and a non-matching one, and asks the match to be closer to the anchor than the non-match by a margin.

Pair and triplet training learn a general sense of similarity rather than a fixed list of classes, so the network can compare things it has never seen before. That is exactly what face matching needs: the celebrities you are compared with were not in the training data.

Siamese Networks in Face Recognition

Early deep face recognition systems leaned heavily on these ideas. Google's FaceNet (2015) trained with triplet loss and reached 99.63% on the LFW benchmark.

Later research found a more stable route to the same goal. Losses such as SphereFace (2017), CosFace (2018) and ArcFace (2019) train the network to classify thousands of people with an extra margin, then throw the classifier away and keep the embedding. The result is used exactly like one branch of a Siamese network: embed two faces, measure the distance.

How Ollie Relates to the Siamese Idea

Ollie's network was trained with CosFace on the MS1MV2 dataset, not with pairs. At search time, though, it works on the Siamese principle: the same network with the same weights embeds your photo and every celebrity photo, and the closest embeddings are your matches.

The celebrity embeddings are computed once, ahead of time. When you search, only your photo goes through the network, and comparing your embedding with thousands of stored ones takes milliseconds.

Beyond Faces

The same design shows up wherever two things need comparing: checking a signature against a known one, finding near-duplicate images, matching product photos, and one-shot learning, where a system must recognise something new from a single example.

Frequently Asked Questions

Why is it called a Siamese network?

Because it is drawn as two identical networks side by side, like twins. In reality it is one network with shared weights, applied to both inputs.

Does Ollie use a Siamese network?

Ollie compares faces the Siamese way, with the same network embedding your photo and every celebrity photo. But its network was trained with the CosFace loss on MS1MV2 rather than with pairs.

What is the difference between contrastive loss and triplet loss?

Contrastive loss works on pairs labelled same or different. Triplet loss works on an anchor, a match and a non-match, and asks the match to be closer than the non-match by a margin.

What are Siamese networks used for besides faces?

Signature verification, image retrieval, duplicate detection, product matching and one-shot learning: any task that comes down to how similar two things are.

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