当前位置:网站首页>度量学习(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个负样本对。




边栏推荐
- 简单明了,数据库设计三大范式
- Jupyter Notebook安装库;ModuleNotFoundError: No module named ‘plotly‘解决方案。
- MAE 论文《Masked Autoencoders Are Scalable Vision Learners》
- Transformer
- (六)递归
- TensorFlow2 study notes: 5. Common activation functions
- 【CV-Learning】卷积神经网络预备知识
- 视图、存储过程、触发器
- SQL练习 2022/7/2
- Logistic Regression --- Introduction, API Introduction, Case: Cancer Classification Prediction, Classification Evaluation, and ROC Curve and AUC Metrics
猜你喜欢

【go语言入门笔记】12、指针

Android connects to mysql database using okhttp

AIDL communication between two APPs

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

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

Install dlib step pit record, error: WARNING: pip is configured with locations that require TLS/SSL

Pytorch语义分割理解

YOLOV4流程图(方便理解)

Image-Adaptive YOLO for Object Detection in Adverse Weather Conditions

【CV-Learning】目标检测&实例分割
随机推荐
Thoroughly understand box plot analysis
动手学深度学习_多层感知机
读研碎碎念
postgresql 游标(cursor)的使用
TensorFlow2学习笔记:4、第一个神经网模型,鸢尾花分类
SQL练习 2022/7/2
Logistic Regression --- Introduction, API Introduction, Case: Cancer Classification Prediction, Classification Evaluation, and ROC Curve and AUC Metrics
PCL1.12 解决memory.h中EIGEN处中断问题
[Go language entry notes] 13. Structure (struct)
简单明了,数据库设计三大范式
Linear Regression 02---Boston Housing Price Prediction
Deep Adversarial Decomposition: A Unified Framework for Separating Superimposed Images
双重指针的使用
投稿相关
npm install dependency error npm ERR! code ENOTFOUNDnpm ERR! syscall getaddrinfonpm ERR! errno ENOTFOUND
Android connects to mysql database using okhttp
postgresql中创建新用户等各种命令
彻底搞懂箱形图分析
[Introduction to go language] 12. Pointer
MySQL leftmost prefix principle [I understand hh]