They use Euclidean embedding space to find the similarity or difference between faces. Loss minimizes the distances between similar faces and maximizes one between different faces.
classTripletLoss(nn.Module): """ Triplet loss Takes embeddings of an anchor sample, a positive sample and a negative sample """ def__init__(self,margin): super(TripletLoss,self).__init__() self.margin=margin defforward(self,anchor,positive,negative,size_average=True): distance_positive=(anchor-positive).pow(2).sum(1)# .pow(.5) distance_negative=(anchor-negative).pow(2).sum(1)# .pow(.5) losses=F.relu(distance_positive-distance_negative+self.margin) returnlosses.mean()ifsize_averageelselosses.sum()
Schroff F, Kalenichenko D, Philbin J. Facenet: A unified embedding for face recognition and clustering[C]//Proceedings of the IEEE conference on computer vision and pattern recognition. 2015: 815-823.MLA
Wen Y, Zhang K, Li Z, et al. A discriminative feature learning approach for deep face recognition[C]//European Conference on Computer Vision. Springer, Cham, 2016: 499-515.MLA
Hadsell R, Chopra S, LeCun Y. Dimensionality reduction by learning an invariant mapping[C]//null. IEEE, 2006: 1735-1742.
Liu W, Wen Y, Yu Z, et al. Sphereface: Deep hypersphere embedding for face recognition[C]//The IEEE Conference on Computer Vision and Pattern Recognition (CVPR). 2017, 1: 1.
Liu W, Wen Y, Yu Z, et al. Large-Margin Softmax Loss for Convolutional Neural Networks[C]//ICML. 2016: 507-516.