Geeks of Coding

Join us on Telegram

Siamese Neural Networks (SNN) are used to find the similarities between two inputs by determining the difference between the outputs from the inputs given. Sometimes Siamese Neural Network is called Similarity Learning and Twin neural network because the architecture of SNN’s Algorithm works with two inputs.

Similarity Learning with (or without) Convolutional Neural Network

Siamese Neural Network Architecture

Siamese Neural Network

Image A –> Input

Image B –> Input

Image A and Image B would be pass through the base neural network architecture with the same structure and same weights to which the Neural Network will give two individual output vectors to both the inputs.

Vector A and Vector B are the output vectors to the input A and Input B respectively.

Later we use a Mathematical Operation called Euclidean Distance to find the amount of difference in the outputs, i.e., Vector A and Vector B. Based on the amount of that difference, that difference will tell us if both the output Vectors are similar or not.

Siamese Neural Network
Finding Difference between the output vectors, using Euclidean Distance

Note: While Training the Neural Network Model we will feed both the inputs with their respective labels that specify that the inputs are similar or not.

On the basis of the accuracy of the prediction, the model will adjust learn from those inputs and will adjust its weights accordingly.

Siamese Neural Network Model
Model Summary of Siamese Neural Network

Important: when we use the Siamese Network Algorithm while compiling the model we have to write our own loss functions, i.e., custom loss functions.

Siamese Neural Network model output

Here is the link to the Example Siamese Network code for better Understanding. Click Here

Yash Arora

Yash Arora

Engineering Student | Mechatronics | Digital Marketer| Web Developer | Author | Learner | Achiever | Part-time Coder

Recommended Articles

Leave A Comment