metric deep learning loss

本文详细解析了深度学习中常见的三种损失函数:softmax loss、center loss 和 triplet loss 的原理及计算过程。对于每种损失函数,都介绍了其前向传播和反向传播的具体公式,并针对 softmax loss 提出了数值稳定性和学习率调整的建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. softmax loss

Forward:

Zj=wTyjxi+byj1

pj=eZjkeZk2

Lk=jqj,klogpj3

Backward:
pjZm=pj(1pj),m=j

pjZm=pjpm,mj

LkZm======jqj,klogpjZmjqj,k1pjpjZmj=mqj,k1pjpj(1pj)mjqj,k1pj(pjpm)j=mqj,k(1pj)mjqj,k(pm)j=mqj,k(1pj)mjqj,k(pm)pmqm,k

Liwk=LiZmZmwk=xTi(pmqm,i)

wkL=1/NixTi(pmqm,i)+2λwk

交叉熵softmax注意事项:
1. 在用softmaxloss训练模型时,如果学习率太大,可能会导致loss=NAN。考虑上面第(2)式子,如果j=k时, pj 趋近于0,(3)loss就会nan。如果出现这种情况,可以考虑用较小的学习率。也有可能是初始化权重太大,尝试用不同的初始化策略,比如用xaiver把初始化的权重再除以10或100,尝试加batch_normalizetion层,可以把输出scale较小的范围。
2. 考虑数值计算稳定性情况下的Softmax损失函数
pj=eZjmax(Zj)keZkmax(Zj)

因为指数计算和指数求和的结果可能非常大,会出现overflow,超出浮点数的范围。

2. Center loss

Foward:

Lc=12i=1m||xicyi||22

xi :第i张图片的特征值
cyi :该图片所属分类的中心(该分类的特征值的中心)
Backward:
Lcxi=xicyi

cjLc=iδ{yi=j}(cjxi)1+iδ{yi=j}

在线更新 cj :
cj+1=cjcjLc

3.Triplet Loss

COCOA (Collaborative Convolutional Metric Learning) is a deep learning method for metric learning that aims to learn a similarity metric between pairs of images. It is designed for image retrieval applications, where the goal is to find images that are similar to a query image. The COCOA model is based on a collaborative learning approach that combines the strengths of both convolutional neural networks (CNNs) and metric learning. The COCOA model consists of two main components: a CNN encoder and a metric learning module. The CNN encoder is used to extract features from the input images, while the metric learning module is used to learn a similarity metric between pairs of images. The metric learning module is trained using a triplet loss function, which encourages the model to learn embeddings that are close together for similar images and far apart for dissimilar images. One of the unique aspects of COCOA is its collaborative learning approach. The model is trained in a two-stage process, where the CNN encoder is first trained using a classification task, and then the metric learning module is trained using the embeddings produced by the CNN encoder. This approach allows the model to leverage the strengths of both CNNs and metric learning, resulting in a more effective similarity metric. COCOA has been shown to outperform several state-of-the-art methods on benchmark datasets for image retrieval, including CIFAR-10 and CIFAR-100. It has also been applied to real-world applications, such as image-based product search, where it achieved high accuracy and robustness to variations in lighting, pose, and scale. In summary, COCOA is a collaborative convolutional metric learning method that combines the strengths of CNNs and metric learning for effective image retrieval. Its unique approach to collaborative learning and triplet loss function make it a powerful tool for a variety of real-world applications.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值