Deep Learning with Siamese Networks

Subhangi Dhasmana
4 min readOct 28, 2023

--

Before learning about Siamese networks, one should have a fundamental understanding of deep learning, so we will begin with an introduction to deep learning and then go on to Siamese networks.

Table of content

  1. Deep learning
  2. Siamese networks
  3. Working of Siamese networks
  4. Application of Siamese networks

What is deep learning?

Deep learning is a subset of machine learning that uses multi-layered neural networks (deep neural networks). It varies from typical machine learning in that it can build hierarchical representations from data automatically, allowing it to tackle difficult tasks like picture and speech recognition. Layers of linked neurons form neural networks. Input layers, hidden layers, and output layers are the most important components. These layers’ neurons have weights and biases, and they use activation functions to produce output. The diagram below will give you a basic understanding of what a neural network is and how it works.

Neural Network

Siamese Networks

We’ve all heard of machine learning techniques like classification, clustering, and prediction, but one that gets less attention is similarity between two input data points. We compare two data points and assign a score ranging from 0 to 1, higher the score, the more similar the input.

Now consider an example:- Think about a situation where we are asked to determine whether two images of a person’s face are of the same person or not. By determining the Euclidean distance between the feature vectors of the two images, we can compute it. The similarity between the images increases with decreasing distance. However, the drawback of this approach is that it requires manual feature engineering to extract pertinent features from images and is difficult to implement for large datasets. This method can take a long time, and it is not appropriate for tasks involving dynamic and diverse data. As a result, deep learning methods — such as Siamese networks — have become more well-liked because of their capacity to automatically acquire intricate and discriminative representations, which makes them more appropriate for a wide range of contemporary computer vision and image similarity tasks.

Working of Siamese Networks

Two identical subnetworks with the same architecture and weights — sometimes called “twins” — make up a Siamese network. After receiving pairs of input data (such as images), these subnetworks compute feature embeddings for each input. The main idea is to learn a mapping that pushes dissimilar inputs apart and brings similar inputs closer together in a high-dimensional space.

Input Data: You give the Siamese network pairs of input data, each of which consists of two objects you wish to compare for similarity.
Shared Subnetworks: The architecture and weights of each input in the pair are identical, and it passes through its corresponding subnetwork. It is the subnetwork’s responsibility to extract features from the input data.
Feature extraction: The input data is processed in each subnetwork to extract pertinent features. In the case of images, this usually entails several convolutional layers, pooling layers, and fully connected layers.
Embeddings: The feature embeddings, or high-dimensional vectors that represent the features of the data, are output by the subnetworks for each input. These embeddings are suitable representations of the input data for similarity measurements.
Distance Metric: It is now possible to compare the feature embeddings from the two subnetworks. The similarity between the embeddings of the two inputs is measured using a distance metric, such as cosine similarity or Euclidean distance. The perceived similarity of the inputs increases with decreasing distance or increasing similarity score.

Application of Siamese networks

Face Recognition and Verification: To confirm that two facial photos are of the same person, Siamese networks are frequently employed. They gain knowledge of how to measure facial similarity and extract facial features.
Signature Verification: By learning representations unique to each signature, Siamese networks can be used to determine whether two signatures are from the same person.
Recommendation Systems: To provide more individualized recommendations, Siamese networks are used in recommendation systems to gauge how similar users or products are. Based on their interactions and preferences, they can assist in identifying related users or items.
Duplicate Document Detection: To preserve content quality and prevent redundancy, Siamese networks can recognize duplicate or nearly duplicate documents in information retrieval systems.
Biometric Authentication: Siamese networks can be utilized for biometric authentication techniques like fingerprint or palmprint verification, in addition to facial recognition.

--

--