当前位置:   article > 正文

对比损失(Contrastive Loss)、三元损失(Triplet Loss)_对比损失和三元组损失哪个更好一点

对比损失和三元组损失哪个更好一点

目录

06-CVPR-Dimensionality Reduction by Learning an Invariant Mapping

Contrastive Loss Function

15-ICLR-DEEP METRIC LEARNING USING TRIPLET NETWORK

TRIPLET NETWORK​

15-CVPR-FaceNet A Unified Embedding for Face Recognition and Clustering

Triplet Loss

Triplet Selection


06-CVPR-Dimensionality Reduction by Learning an Invariant Mapping

Contrastive Loss Function

低维映射:

共P对

Y = 0 if X1 and X2 are deemd similar, and Y = 1 if they are deemed dissimilar.

m定义了GW(x)的半径,当负样本在m内时才将其推开。
 

15-ICLR-DEEP METRIC LEARNING USING TRIPLET NETWORK

TRIPLET NETWORK


相同深度网络作为嵌入函数,共享参数。

In order to output a comparison operator from the model, a SoftMax function is applied on both outputs - effectively creating a ratio measure.

为了从模型中输出比较运算符,应用softmax函数构建比率度量。为了方便使用概率表示,又将其输入softmax函数。

Similarly to traditional convolutional-networks, training is done by simple SGD on a negative-loglikelihood loss with regard to the 2-class problem.

SGD(随机梯度下降)对2分类问题的负对数似然(negative log likelihood)损失进行训练。

损失函数-负对数似然和交叉熵(Pytorch中的应用)_CityD的博客-CSDN博客_负对数似然损失函数

这里的负对数似然损失指的是什么?

Loss=-log(1-d_{+})-logd_{-}?Loss=-Net(x)logNet(x_{+})-(1-Net(x))logNet(x_{-})

We later examined that better results are achieved when the loss function is replaced by a simple MSE on the soft-max result, compared to the (0,1) vector.

MSE(均方误差)指的是对一个batch里的\left \| d_{+}-(d_{-}-1) \right \|_{2}^{2}求均值获得Loss?

 

\left \| d_{+}-(d_{-}-1) \right \|_{2}^{2}=\left \| d_{+}+1-d_{-}\right \|_{2}^{2}=\left \| 2d_{+} \right \|_{2}^{2}

本质上相当于一个常数乘以anchor与正样本之间距离的平方

代码:Lua https://github.com/eladhoffer/TripletNet

15-CVPR-FaceNet A Unified Embedding for Face Recognition and Clustering

Triplet Loss

将图像x嵌入到d维超球面f(x),L2归一化||f(x)||2=1

合页损失函数(hinge loss function):max{0,正样本对间距离-负样本对间距离+α}

初始 正样本对间距离+α>负样本对间距离(即正负样本对之间距离不足α),优化网络直到 正样本对间距离-负样本对间距离+α=0停止优化(即正负样本对之间有距离α)

α避免把所有东西都学成0,0-0=0也符合。

torch.nn.functional.relu((anchor-positive).pow(2).sum()-(anchor-negative).pow(2).sum()+self.margin)

Triplet Selection

离线:每n步使用最近的网络,子集

在线三元组挖掘:mini-batch C(45)类每类挑K(2)个,共N(90)个,bs=90,bn=1800/90=20

  • 计算embedding distance metric
  • 将每个样本都当做一个anchor
  • 对所有可能的正样本对随机选择semi-hard负样本对

避免f(x)=0 semi-hard负样本和anchor的距离应该比正样本和anchor的距离大。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/730620
推荐阅读
相关标签
  

闽ICP备14008679号