对比损失(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的距离大。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值