A Look Into The Emerging Domain of Metric Learning
All about metric Learning and the impact it makes on the world of computer vision
How do machine learning algorithms work?
The question is how do these machine learning algorithms work and what do they do. So virtually it could be envisioned as a map and our goal is to help the machine understand the path that it takes to reach the goal. For a particular data and its respective label, the agenda is to create certain rules or function that maps the given inputs to their assigned output labels.
But when it comes to image classification learning invariant and discriminative features from data is essential for achieving reliable results. Traditional methods may sometimes fail to accomplish this task successfully and that is exactly why metric learning was applied in the field of deep learning to enhance the ability of the model for better results.
What is Metric Learning?
Metric learning is a method that determines the similarity or dissimilarities between items based on the distance metric. What it fundamentally does is it works on the received data and creates new distance metrics, which then helps to distinguish the new data better. Metric learning increases the distance between dissimilar objects all while shortening the distance between similar objects.
One of the simplest machine learning algorithms where distance information is captured is the KNN or k-Nearest Neighbours algorithm, akin to this the objective of metric learning is to obtain a similarity function from the given data. Metric learning aims to learn data patterns and feature vectors so as to decrease the distance between feature vectors when it comes to similar objects and increases this distance for dissimilar objects.
Why Do We Need Metric Learning
Typically, experts choose standard distance metrics like Euclidean, City-Block, Cosine, etc., by years of experience and knowledge in the domain.
However, it is very laborious to design metrics that are tailor-made to a particular data and task to be done on it.
Distance metric learning is implemented to keep building task-specific metrics from the data presented, while the machine learns and updates on itself. These learned distance metrics can then be used to perform other tasks like KNN which require distance information.
These Tasks also include:
Clustering: metric learning provides a way to bias the clusters found by algorithms like K-Means towards the intended semantics.
Information Retrieval: The learned metric can be used to retrieve the elements of a database that are semantically closest to a query element.
Dimensionality Reduction: Metric learning may be seen as a way to reduce the data dimension in a (weakly) supervised setting.
Mahalanobis Distances
By the research conducted on the topic of metric learning, it’s evident that the studies are directly related to the Mahalanobis distance metric.
Let X=[x1, x2, …, xN]∈ Rd×N be the training samples, where xi∈ Rd is i th training example and N is the total number of training samples. The distance between xi and xj is calculated as:
Where dM(xi,xj) is a distance metric and it must include properties such as the properties of nonnegativity, the identity of indiscernibles, symmetry, and the triangle inequality. M is the inverse of the covariance matrix and acts as a weight term to the square Euclidean distance. M must always be symmetric and positive semidefinite, and all the eigenvalues and determinants of M must be either positive or zero. The Mahalanobis distance equation represents a dissimilarity measure between two random vectors xi and xj, following the same distribution with Covariance Matrix Σ.
M can be decomposed into:
so this equation can be understood as a linear projection in Euclidean space. W has a linear transformation property because of which Euclidean distance in transformed space is equal to the Mahalanobis distance in the original space. Hence this distance metric enables us to represent the data much more distinctly which pumps up the accuracy in distinguishing different classes. To sum up metric learning the main focus is to learn the transformation matrix W.
Uses Of Deep Metric Learning
In recent years, Metric/Distance learning using Deep learning has been shown to output highly satisfying results for many computer vision tasks such as face recognition, face verification, image classification, Anomaly detection, etc.
It is observed that face verification or face recognition can be cheated and passed through when used faces similar to the trained face or the face of the same person in different surroundings and expressions in a run-of-the-mill system.
Therefore, the key to building a solid face verification system is essentially the task of creating an appropriate loss function that distinguishes the data inputs thoroughly.
Metric Learning only has a limited capability to capture non-linearity in the data. So, by deep metric learning, the unique and non-linear structures can be captured by learning a non-linear transformation.
Deep Metric Learning
Generic machine learning algorithms and their potential to process data on the raw have a ceiling to them. Hence feature engineering like preprocessing and feature extraction is imperative before any classification or clustering tasks. All of these steps have a mastery requisite and are not included in the classification structure. On the contrary, deep learning learns these higher-order data directly in the classification structure. Due to this, we can see a clear difference between regular machine learning methods and deep learning methods.
Basic similarity metrics such as Euclidean, Mahalanobis, Matusita, Bhattacharyya, and Kullback-Leibler distances are the norm in data classification but because of their predefined measures, they limit the processing. To overcome this hurdle, an approach based on the Mahalanobis metric was created to separate the data into traditional metric learning.
So, deep metric learning gives task-specific outcomes which are generated by processing the raw data by using a deep approach, figuring out embedded feature similarities through nonlinear learning. Weakly supervised input samples, the topology of the network model, and the metric loss function are the three fundamental components of deep metric learning.
One important note for better performance would be the preselection of informative data sets. Deep metric learning gives outstanding results with contrastive data sets, so the selection of the sample data also plays a huge role to shape the network and achieve better classification accuracy.
Studies Done on Deep Metric Learning
The major part of deep learning approaches is dependent on the deep architectural background, very few implement the distance metric in a new representation space of the data. Due to this peculiarity distance-based techniques have caused quite a lot of noise in the deep learning society and have become one of the most intriguing subjects.
Deep metric learning reduces the difference between the dissimilar data from the dataset while its main focus remains on increasing the distance between similar sample data, is solely related to the distance between the samples, and to execute this classification the metric loss function has been applied in deep learning. We can see this approach visualized in figure(a) given above.
Experiments on the MNIST dataset was taken place while applying the contrastive loss to illustrate this process with a figure. In figure(b) the distance values indicate the mean distances between similar and dissimilar data.
The distance value for similar images kept on decreasing gradually after each training epoch
The distance value for dissimilar images from the MNIST dataset went on to increase slowly at the same time.
This experiment using a Siamese network explains to us the distance coherence for similar and dissimilar images in each epoch and also solidifies the implementation of deep metric learning.
Conclusion
A brief introduction to Mahalanobis distance and how it is inculcated in the distance metric for solving tasks.
Metric learning increases the distance between dissimilar objects all while shortening the distance between similar objects.
Making use of this similarity and dissimilarity concept of the metric loss function, we can clearly see the significance of this subject in the computer vision sector.
Practical examples of deep metric learning show us how the scope and the room for research in Deep Metric learning.
Vevesta: Your Machine Learning Team’s Feature and Technique Repository - Accelerate your Machine learning project by using features, techniques and projects used by your peers
100 early birds who login into Vevesta will get free subscription for lifetime.
References
metric-learn: Metric Learning in Python — metric-learn 0.6.2 documentation (scikit-learn.org)
Symmetry | Free Full-Text | Deep Metric Learning: A Survey (mdpi.com)
A Beginners Guide to Deep Metric Learning (analyticsindiamag.com)
The Why and the How of Deep Metric Learning. | by Aakash Agrawal | Towards Data Science
This article was originally published at https://www.vevesta.com/blog/37-Metric-Learning