Twin Network---Study Notes

			孪生网络

1. What is a twin network (one-shot)
In face recognition, there is a so-called one-shot problem. For example, face recognition is performed on company employees. Each employee has only one photo (because there are few training samples for each category), and employees will leave and enter the company (it is unrealistic to retrain the model every time they change) . If it is regarded as a classification problem, it is not feasible to directly train the model for face recognition in practical applications.
In order to solve the one-shot problem, we will train a model to output the similarity of two given images, so the model learns the similarity function, and determines whether they belong to the same person by setting a threshold for the similarity.

2. Significance of twin network (one-shot)
(1) Reducing training data
Deep learning requires a large amount of data MNIST In order to distinguish 10 categories, 60,000 training images are required, and an average of 6,000 training images is required for one category. One-Shot tries to Reduce the training images of a category, and reduce it to one image in extreme cases
(2) When new categories of data appear, there is no need to retrain
traditional deep neural networks that cannot handle categories that do not appear in the training set. Take clock-in as an example, using the traditional deep neural network, each new employee enters a new category, and the deep neural network needs to be retrained. If new employees are recruited every day, the network must be retrained every day, and the cost is very high. One -Shot learning can be applied to new categories of data without retraining
3. The principle of twin network (one-shot) The
traditional neural network tries to learn the expression of a certain category of images.
One-Shot Learning tries to learn different images (can
difference between the same category or different categories)
Given a picture A and a picture B, convert A into an embedding vector p, and convert B into an embedding vector q
If A and B belong to the same category, then we Hope p and q are similar
If A and B do not belong to the same category, then we want p and q to be dissimilar
Measure of similarity, Euclidean distance
insert image description here

4. Network structure of twin network (one-shot)
insert image description here

   Siamese Network有两个结构相同,且共享权值的子网络(同一个网络)。分别接收两个输入X1X1与X2X2,将其转换为向量Gw(X1)与Gw(X2),再通过某种距离度量的方式计算两个输出向量的距离Ew。

Suppose image A and image B are of the same class:
insert image description here

Suppose image A and image B are of different classes:
insert image description here

Network structure:
5. The loss function of the twin network
In the twin neural network (siamese network), the loss function used is contrastive loss, which can effectively deal with the relationship of paired data in the twin neural network. The expression of contrastive loss is as follows
insert image description here

The Euclidean distance (two-norm) P representing the two sample features X_1 and X2 represents the feature dimension of the sample, Y is the label of whether the two samples match, Y=1 means that the two samples are similar or match, Y=0 then Represents a mismatch, m is the set threshold, and N is the number of samples.
When Y=1 (that is, when the samples are similar), only the loss function remains:
insert image description here

When the samples are similar, the smaller the value calculated by the D Euclidean distance, the smaller the loss function.
When Y=0 (that is, when the samples are not similar), the loss function is:
insert image description here

[Note that a threshold margin is set here, which means that we only consider dissimilar features whose Euclidean distance is between 0 and margin. When the distance exceeds margin, the loss is regarded as 0 (that is, dissimilar features are far away. , its loss should be very low; and for similar features that are far away, we need to increase its loss, so as to continuously update the matching degree of paired samples)]

Supongo que te gusta

Origin blog.csdn.net/weixin_43391596/article/details/128062219
Recomendado
Clasificación