当前位置:网站首页>度量学习(Metric learning、损失函数、triplet、三元组损失、fastreid)
度量学习(Metric learning、损失函数、triplet、三元组损失、fastreid)
2022-08-04 05:29:00 【TigerZ*】




1)离线挖掘
训练集所有数据经过计算得到对应的embedding,根据embedding计算得到(a,p)和(a,n)之间的距离,根据这个距离判断三元组属于semi-hard triplets,hard triplets还是easy triplets中的哪一类。Offline triplet mining 仅仅用于选择hard或者semi-hard的三元组类型,因为easy triplet太容易了,没有必要训练。总得来说,这个方法效率不高。
2)在线挖掘(不要慌,使用pytorch实现均仅仅需要几行代码便可实现)
为每一batch动态挖掘有用的三元组,即只计算batch中的triplets。假设一个batch的数据有P个人,每人K张图片,则共包含P*K张人脸。针对valid triplet的挑选(即构成A-P-N对),有如下两种策略:
Batch all:计算所有的valid triplet,对hard 和 semi-hard triplets上的loss进行平均(easy triplets不参与计算,平均会导致loss很小),可以得到PK(K-1)(PK-K)个三元组。
Batch hard: 对于每一个锚点,选择距离最大的正样本(a,p)和距离最小的负样本(a,n),可以得到PK个三元组。
加权:对于每一个锚点,通过样本到anchor的最大距离加权计算所有样本到anchor的距离的加权和(正负样本同理),可以得到PK个三元组(逻辑上其实并不再是真实存在的三元组,为加权均值,包含easy,semi-hard 和hard)。
再详细理解可以参考:https://zhuanlan.zhihu.com/p/266916361
Fastreid(截止20210730)实现了batch hard 和加权的功能,,可以参考对应的实现:https://github.com/JDAI-CV/fast-reid/blob/master/fastreid/modeling/losses/triplet_loss.py


triplet loss同时拉近一对正样本和一对负样本,这就导致在选取样本对的时候,当前样本对只能够关注一对负样本对,而缺失了对其他类别样本的区分能力。
为了改善这种情况,N-pair loss就选取了多个负样本对,即一对正样本对,选取其他所有不同类别的样本作为负样本与其组合得到负样本对。如果数据集中有 N个类别,则每个正样本对 yii都对应了N-1个负样本对。




边栏推荐
猜你喜欢
![[Introduction to go language] 12. Pointer](/img/c8/4489993e66f1ef383ce49c95d78b1f.png)
[Introduction to go language] 12. Pointer

Th in thymeleaf: href use notes

postgresql 游标(cursor)的使用

Simple and clear, the three paradigms of database design

PCL1.12 解决memory.h中EIGEN处中断问题

AIDL communication between two APPs
![[CV-Learning] Convolutional Neural Network Preliminary Knowledge](/img/7d/58d9649b06e78eeb019d63615a90c4.png)
[CV-Learning] Convolutional Neural Network Preliminary Knowledge

TensorFlow2学习笔记:8、tf.keras实现线性回归,Income数据集:受教育年限与收入数据集

Jupyter Notebook installed library;ModuleNotFoundError: No module named 'plotly' solution.

逻辑回归---简介、API简介、案例:癌症分类预测、分类评估法以及ROC曲线和AUC指标
随机推荐
逻辑回归---简介、API简介、案例:癌症分类预测、分类评估法以及ROC曲线和AUC指标
MySQL最左前缀原则【我看懂了hh】
双重指针的使用
光条中心提取方法总结(二)
Transformer
PostgreSQL模式(Schema)
Simple and clear, the three paradigms of database design
PP-LiteSeg
动手学深度学习_多层感知机
【go语言入门笔记】12、指针
TensorFlow2 study notes: 4. The first neural network model, iris classification
[Introduction to go language] 12. Pointer
Use of double pointers
属性动画的用法 以及ButterKnife的用法
The difference between oracle temporary table and pg temporary table
Comparison of oracle's number and postgresql's numeric
(十)树的基础部分(一)
【CV-Learning】Object Detection & Instance Segmentation
Logistic Regression --- Introduction, API Introduction, Case: Cancer Classification Prediction, Classification Evaluation, and ROC Curve and AUC Metrics
Vision Transformer 论文 + 详解( ViT )