ArticleslgStudy

computer science

Siamese neural network

Siamese neural network is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Siamese neural network rather than just read about it. In short: A Siamese neural network (sometimes called a twin neural network) is an artificial neural network that uses the same weights while working in tandem on two different input vectors to compute comparable output vectors. Often one of the output vectors is precomputed, thus forming a baseline against which the other output vector is compared.

Key takeaways

  • Siamese neural network belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Siamese neural network to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Siamese neural network from memory before moving on to harder problems.

Reference excerpt

A Siamese neural network (sometimes called a twin neural network) is an artificial neural network that uses the same weights while working in tandem on two different input vectors to compute comparable output vectors. Often one of the output vectors is precomputed, thus forming a baseline against which the other output vector is compared. This is similar to comparing fingerprints but can be described more technically as a distance function for locality-sensitive hashing. It is possible to build an architecture that is functionally similar to a twin network but implements a slightly different function. This is typically used for comparing similar instances in different type sets. Uses of similarity measures where a twin network might be used are such things as recognizing handwritten checks, automatic detection of faces in camera images, and matching text queries with indexed documents. The perhaps most well-known application of twin networks are face recognition, where known images of people are precomputed and compared to an image from a turnstile or similar. It is not obvious at first, but there are two slightly different problems. One is recognizing a person among a large number of other persons, that is the facial recognition problem. DeepFace is an example of such a system. In its most extreme form this is recognizing a single person at a train station or airport. The other is face verification, that is for example, to verify whether a photo in a passport matches the face of the passport's owner. The twin network might be the same, but the implementation can be quite different.

Learning Learning in twin networks can be done with triplet loss or contrastive loss. For learning by triplet loss a baseline vector (anchor image) is compared against a positive vector (truthy image) and a negative vector (falsy image). The negative vector will force learning in the network, while the positive vector will act like a regularizer. For learning by contrastive loss there must be a weight decay to regularize the weights, or some similar operation like a normalization. A distance metric for a loss function may have the following properties

Non-negativity: δ(x,y)≥0 Identity of Non-discernibles: δ(x,y)=0⟺x=y Commutativity: δ(x,y)=δ(y,x) Triangle inequality: δ(x,z)≤δ(x,y)+δ(y,z) In particular, the triplet loss algorithm is often defined with squared Euclidean (which unlike Euclidean, does not have triangle inequality) distance at its core.

Predefined metrics, Euclidean distance metric The common learning goal is to minimize a distance metric for similar objects and maximize for distinct ones. This gives a loss function like

δ(x(i),x(j))={min⁡ ‖f⁡(x(i))−f⁡(x(j))‖,i=jmax⁡ ‖f⁡(x(i))−f⁡(x(j))‖,i≠j i,j are indexes into a set of vectors f⁡(⋅) function implemented by the twin network The most common distance metric used is Euclidean distance, in case of which the loss function can be rewritten in matrix form as

δ⁡(𝐱(i),𝐱(j))≈(𝐱(i)−𝐱(j))T(𝐱(i)−𝐱(j))

Learned metrics, nonlinear distance metric A more general case is where the output vector from the twin network is passed through additional network layers implementing non-linear distance metrics.

ifi=jthenδ⁡[f⁡(x(i)),f⁡(x(j))]is smallotherwiseδ⁡[f⁡(x(i)),f⁡(x(j))]is large i,j are indexes into a set of vectors f⁡(⋅)function implemented by the twin network δ⁡(⋅)function implemented by the network joining outputs from the twin network On a matrix form the previous is often approximated as a Mahalanobis distance for a linear space as

δ⁡(𝐱(i),𝐱(j))≈(𝐱(i)−𝐱(j))T𝐌(𝐱(i)−𝐱(j)) This can be further subdivided in at least Unsupervised learning and Supervised learning.

Learned metrics, half-twin networks This form also allows the twin network to be more of a half-twin, implementing a slightly different functions

ifi=jthenδ⁡[f⁡(x(i)),g⁡(x(j))]is smallotherwiseδ⁡[f⁡(x(i)),g⁡(x(j))]is large i,j are indexes into a set of vectors f⁡(⋅),g⁡(⋅)function implemented by the half-twin network δ⁡(⋅)function implemented by the network joining outputs from the twin network

Twin networks for object tracking Twin networks have been used in object tracking because of its unique two tandem inputs and similarity measurement. In object tracking, one input of the twin network is user pre-selected exemplar image, the other input is a larger search image. The twin network's job is to locate the exemplar inside of the search image. By measuring the similarity between exemplar and each part of the search image, a map of similarity score can be given by the twin network. Furthermore, using a Fully Convolutional Network, the process of computing each sector's similarity score can be replaced with only one cross correlation layer. After being first introduced in 2016, Twin fully convolutional network has been used in many High-performance Real-time Object Tracking Neural Networks. Like CFnet, StructSiam, SiamFC-tri, DSiam, SA-Siam, SiamRPN, DaSiamRPN, Cascaded SiamRPN, SiamMask, SiamRPN++, Deeper and Wider SiamRPN.

See also Artificial neural network Triplet loss

References

Worked examples

Example 1 — a first encounter with Siamese neural network

Start with the simplest possible case. Write down what Siamese neural network claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Siamese neural network before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Siamese neural network ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Siamese neural network

In research
Siamese neural network appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Siamese neural network in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Siamese neural network is common in secondary-school and first-year university syllabi. It links to neighbouring topics Neural network architectures, so understanding it makes those chapters shorter.
In everyday life
Look for Siamese neural network outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Siamese neural network” →

How to study Siamese neural network in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Siamese neural network means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Siamese neural network out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Siamese neural network in simple terms?

A Siamese neural network (sometimes called a twin neural network) is an artificial neural network that uses the same weights while working in tandem on two different input vectors to compute comparable output vectors. Often one of the output vectors is precomputed, thus forming a baseline against w…

Why does Siamese neural network matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Siamese neural network?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Siamese neural network.

Tags

  • Neural network architectures

Keep exploring