Proxy-NCA Loss、Proxy Anchor Loss
目录
17-ICCV-No Fuss Distance Metric Learning using Proxies
Proxy Ranking Loss
20-CVPR-Proxy Anchor Loss for Deep Metric Learning
Proxy Anchor Loss
17-ICCV-No Fuss Distance Metric Learning using Proxies
Heaviside step function
L梯度处处为0->替代损失
- margin-based triplet loss
hinge function合页损失函数[x ]+=max(x,0)
- Neighborhood Component Analysis (NCA)
采样:k个类,|D|=n个样本 x y z
Proxy Ranking Loss
|P|<<|D|,P作为所有数据点的近似
x的代表:离x最近的p。
代理近似误差:所有数据点中最差的近似。
静态代理分配
每个代表关联一个语义标签,根据标签给数据点x分配代表。
不需要采样三元组,只需要采样anchor x。
动态代理分配
没有语义标签,给x分配最近的代表。
proxy-based loss是triplet loss的严格上界,不需要采样,收敛速度快。
class ProxyNCA(torch.nn.Module):def __init__(self, nb_classes,sz_embedding,smoothing_const = 0.1,scaling_x = 1,scaling_p = 3):torch.nn.Module.__init__(self)# initialize proxies s.t. norm of each proxy ~1 through div by 8# i.e. proxies.norm(2, dim=1)) should be close to [1,1,...,1]# TODO: use norm instead of div 8, because of embedding sizeself.proxies = Parameter(torch.randn(nb_classes, sz_embedding) / 8)self.smoothing_const = smoothing_constself.scaling_x = scaling_xself.scaling_p = scaling_pdef forward(self, X, T):P = F.normalize(self.proxies, p = 2, dim = -1) * self.scaling_pX = F.normalize(X, p = 2, dim = -1) * self.scaling_xD = torch.cdist(X, P) ** 2T = binarize_and_smooth_labels(T, len(P), self.smoothing_const)# note that compared to proxy nca, positive included in denominatorloss = torch.sum(-T * F.log_softmax(-D, -1), -1)return loss.mean()
scaling_x,scaling_p?
代码:https://github.com/dichotomies/proxy-nca
20-CVPR-Proxy Anchor Loss for Deep Metric Learning
N-pair loss、Lifted Structure loss:没有利用batch中的全部数据,元组采样->调整超参数。
Proxy-NCA loss:没有利用数据-数据的关系,关联每个数据点的只有代表。
s(x,p)余弦相似度
LSE Log-Sum-Exp function
解决上溢下溢
关于LogSumExp - 知乎
Proxy Anchor Loss
每个代表作为一个anchor,和batch中的所有数据点关联。
P表示所有代表,P+正代表
根据样本的困难程度以不同的力度来拉近或者拉远embedding vectors
class Proxy_Anchor(torch.nn.Module):def __init__(self, nb_classes, sz_embed, mrg = 0.1, alpha = 32):torch.nn.Module.__init__(self)# Proxy Anchor Initializationself.proxies = torch.nn.Parameter(torch.randn(nb_classes, sz_embed).cuda())nn.init.kaiming_normal_(self.proxies, mode='fan_out')self.nb_classes = nb_classesself.sz_embed = sz_embedself.mrg = mrgself.alpha = alphadef forward(self, X, T):P = self.proxiescos = F.linear(l2_norm(X), l2_norm(P)) # Calcluate cosine similarityP_one_hot = binarize(T = T, nb_classes = self.nb_classes)N_one_hot = 1 - P_one_hotpos_exp = torch.exp(-self.alpha * (cos - self.mrg))neg_exp = torch.exp(self.alpha * (cos + self.mrg))with_pos_proxies = torch.nonzero(P_one_hot.sum(dim = 0) != 0).squeeze(dim = 1) # The set of positive proxies of data in the batchnum_valid_proxies = len(with_pos_proxies) # The number of positive proxiesP_sim_sum = torch.where(P_one_hot == 1, pos_exp, torch.zeros_like(pos_exp)).sum(dim=0) N_sim_sum = torch.where(N_one_hot == 1, neg_exp, torch.zeros_like(neg_exp)).sum(dim=0)pos_term = torch.log(1 + P_sim_sum).sum() / num_valid_proxiesneg_term = torch.log(1 + N_sim_sum).sum() / self.nb_classesloss = pos_term + neg_term return loss
代码:https://github.com/tjddus9597/Proxy-Anchor-CVPR2020/tree/51db57031e38f75c03f69bbdfad1a3233afd9787
Proxy-NCA Loss、Proxy Anchor Loss相关推荐
- 目标检测算法横向比较,包括backbone、特征融合、loss、proposal/anchor/heatmap、NMS、正负样本设置等
目标检测算法发展移步:目标检测算法 本文从算法改进的方向,进行横向比较,包括backbone,特征融合.loss.proposal/anchor/heatmap.NMS.正负样本设置等 Referen ...
- 常用损失函数总结(L1 loss、L2 loss、Negative Log-Likelihood loss、Cross-Entropy loss、Hinge Embedding loss、Margi)
常用损失函数总结(L1 loss.L2 loss.Negative Log-Likelihood loss.Cross-Entropy loss.Hinge Embedding loss.Margi) ...
- 分布式系统——zabbix 用 onealert实现报警、agent主动模式、proxy代理
实验环境 物理机: rhel 7.3系统--172.25.54.250 server1:rhel 7.3系统--172.25.54.1 server2:rhel 6.5系统--172.25.54.11 ...
- CV之FRec之ME/LF:人脸识别中常用的模型评估指标/损失函数(Triplet Loss、Center Loss)简介、使用方法之详细攻略
CV之FRec之ME/LF:人脸识别中常用的模型评估指标/损失函数(Triplet Loss.Center Loss)简介.使用方法之详细攻略 目录 T1.Triplet Loss 1.英文原文解释 ...
- (HEM/OHEM)hard negative(example)mining难例挖掘 与focal loss、GHM损失函数
目录 分类任务中的样本不均衡及hard negative mining的必要性 hard negative example HEM(hard example/negative mining) 与 OH ...
- [网络安全自学篇] 三.Burp Suite安装配置、Proxy基础用法及流量分析示例
最近开始学习网络安全相关知识,接触了好多新术语,感觉自己要学习的东西太多,真是学无止境,也发现了好几个默默无闻写着博客.做着开源的大神.接下来系统分享一些网络安全的自学笔记,希望读者们喜欢. 上一篇文 ...
- 【AI面试】L1 loss、L2 loss和Smooth L1 Loss,L1正则化和L2正则化
损失函数是深度学习模型优化的一个灵魂基础,所以无论是很新的transform模型,还是比较早期的AlexNet,都不可避免的要涉及到损失函数的设计和应用. 所以,各种形形色色的损失函数(Loss)也就 ...
- 10.梯度、激活函数和loss
文章目录 梯度 1.初始状态 2.学习率 3.动量(怎么逃离局部最小值) 4.stochastic gradient descent 5.梯度消失和梯度爆炸.退化问题 常见的函数梯度 梯度API 1. ...
- CAFFE-SSD中loss、accuracy曲线可视化(双Y轴)
CAFFE-SSD中loss.accuracy曲线可视化(双Y轴) 1.利用输出的.log文件(应该在caffe/jobs/VGGNet/VOC0712/SSD_300x300目录下)生成.test ...
- 神经网络训练解决loss、validation loss(损失函数)波动或不收敛问题
神经网络训练解决loss.validation loss(损失函数)波动或不收敛问题 1.没有对数据进行预处理.数据分类标注是否准确?数据是否正确对应标签或者是否有错误数据? 2.将数据进行归一化.将 ...
最新文章
- Python3中Pillow(PIL)介绍
- Oracle RAC系列之:利用srvctl管理RAC数据库
- javascript动画函数封装(升级版)
- 77.SQL 查询方式整理
- 【数据结构与算法】之深入解析“随机翻转矩阵”的求解思路与算法示例
- python的中文文本挖掘库snownlp进行购物评论文本情感分析实例
- P2114-[NOI2014]起床困难综合症【位运算】
- 下列哪项属于正确的锁定计算机桌面,【2018年职称计算机考试WindowsXp练习题及答案1】- 环球网校...
- @Builder(toBuilder=true) 链式初始化对象、修改对象
- QT 定时关机、共享内存、启动浏览器、浏览器前进后退刷新、进度条、设置浏览器标题、QML入门
- 信息学奥赛一本通——1001:Hello,World!
- oracle rac 高并发性能_高并发业务下 JVM 涉及的垃圾回收与性能问题分析与定位...
- set python_Python的set集合详解
- java中int和Integer对比的一些坑
- string equals java_Java equals比较方法(Java StringEquals)
- 电力-开闭所/配电房/变电所/变电站
- 汽车方向盘转角传感器
- 四部金融投资经典教材和30部必读的投资学经
- 基于站长之家(CNZZ)的网站流量统计分析 (以vue代码为例)
- 玩游戏学编程,寓教于乐:12个学习编程的游戏化平台
热门文章
- 2022-2028年中国高尔夫行业市场现状分析及投资前景评估报告
- Android钢琴滑动代码,如何使用Kotlin构建Android旋转旋钮以帮助儿子练习钢琴
- python读取ttf_python读取.ttf字体文件
- 墨羽卿画第二章第7节:跬步
- WebSocket is already in CLOSING or CLOSED state
- 极路由2(HC5761)免云平台开启SSH
- 搜狗输入法不能再idea上输入中文
- 安装win7时,出现“windows无法安装到这个磁盘,选中的磁盘采用GPT分区形式”的处理方式
- 论文阅读:Semantic Parsing on Freebase from Question-Answer Pairs
- Spread 16.0 for WinForms Crack