CS-671: Deep Learning and Its Applications Distance Metric Learning

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

CS-671: Deep Learning and its Applications

Lecture: 16
Distance metric learning

Aditya Nigam, Assistant Professor


School of Computing and Electrical Engineering (SCEE)
Indian Institute of Technology, Mandi
http://faculty.iitmandi.ac.in/ãditya/ aditya@iitmandi.ac.in

Presentation for CS-671@IIT Mandi (16 April, 2019)


(*Presented by : Daksh Thapar)

February - May, 2019


Need for Similarity Measures

Several applications of Similarity Measures exist in today’s world.


Handwriting recognition.

Detection of faces in camera image.

Aditya Nigam (SCEE, IIT-Mandi) aditya@iitmandi.ac.in Lecture, February - May, 2019


Notion of a Metric

A Metric is a function that quantifies a “distance00 between every


pair of elements in a set, thus inducing a measure of similarity.

A metric f (x, y ) must satisfy the following properties for all x, y , z


belonging to the set:
Non-negativity: f (x, y )0
Identity of Discernible: f (x, y ) = 0 <=> x = y
Symmetry: f (x, y ) = f (y , x)
Triangle Inequality: f (x, z) <= f (x, y ) + f (y , z)

Aditya Nigam (SCEE, IIT-Mandi) aditya@iitmandi.ac.in Lecture, February - May, 2019


Traditional Approaches for Matching

The traditional approach for matching images, relies on the following


pipeline:
1 Extract Features: For instance, color histograms of the input
images.
2 Learn Similarity: Use L1 − norm on the features.

Challenges:
The principal shortcoming of traditional metric learning based methods is
that the feature representation of the data and the metric are not learned
jointly.

Aditya Nigam (SCEE, IIT-Mandi) aditya@iitmandi.ac.in Lecture, February - May, 2019


Problem Statement

Input: Given a pair of input images, we want to know how “similar”


they are to each other.

Output: The output can take a variety of forms:


Either a binary label, i.e. 0 (same) or 1 (different).
A Real number indicating how similar a pair of images are.

Aditya Nigam (SCEE, IIT-Mandi) aditya@iitmandi.ac.in Lecture, February - May, 2019


Siamese Networks

Aditya Nigam (SCEE, IIT-Mandi) aditya@iitmandi.ac.in Lecture, February - May, 2019


Siamese Networks as binary classification

Aditya Nigam (SCEE, IIT-Mandi) aditya@iitmandi.ac.in Lecture, February - May, 2019


Problem Statement

Input: Given a pair of input images, we want to know how “similar”


they are to each other.

Output: The output can take a variety of forms:


Either a binary label, i.e. 0 (same) or 1 (different).
A Real number indicating how similar a pair of images are.
d(img 1, img 2) = Degree of difference between images
1 d(img 1, img 2) < t For images belonging to same class
2 d(img 1, img 2) > t For images belonging to different class

Aditya Nigam (SCEE, IIT-Mandi) aditya@iitmandi.ac.in Lecture, February - May, 2019


Standard Siamese CNN

Input: A pair of input images.


Output: A label, 0 for similar, 1 else.

Aditya Nigam (SCEE, IIT-Mandi) aditya@iitmandi.ac.in Lecture, February - May, 2019


Siamese CNN - Loss Function

Is there a problem with this formulation?

Aditya Nigam (SCEE, IIT-Mandi) aditya@iitmandi.ac.in Lecture, February - May, 2019


Siamese CNN - Loss Function

Yes.
The model could learn to embed every input to a same point i.e.
predict a constant as output.
In such a case, every pair of input would be categorized as positive pair.
Aditya Nigam (SCEE, IIT-Mandi) aditya@iitmandi.ac.in Lecture, February - May, 2019
Siamese CNN - Loss Function

The final loss is defined as:

L = Σloss of positive pairs + Σloss of negative pairs

Aditya Nigam (SCEE, IIT-Mandi) aditya@iitmandi.ac.in Lecture, February - May, 2019


Siamese CNN - Loss Function

We can use different loss functions for the two types of inputs pairs.
Typical positive pair (xp , xq ) loss: L(xp , xq ) = ||xp − xq ||2
(Euclidean Loss)

Aditya Nigam (SCEE, IIT-Mandi) aditya@iitmandi.ac.in Lecture, February - May, 2019


Siamese CNN - Loss Function

Typical negative pair (xn , xq ) loss:


L(xn , xq ) = max(0, m2 − ||xn − xq ||2 ) (Hinge Loss)

Aditya Nigam (SCEE, IIT-Mandi) aditya@iitmandi.ac.in Lecture, February - May, 2019


Architecture Varieties

Design largely governed by what performs well empirically on the task


at hand.

Aditya Nigam (SCEE, IIT-Mandi) aditya@iitmandi.ac.in Lecture, February - May, 2019

You might also like