Python 官方文档:入门教程 => 点击学习
文章目录 损失函数总结部分特殊损失函数详解1. 余弦损失函数 `torch.nn.CosineEmbeddingLoss` 损失函数总结 首先直接贴上个人看过比较好的一些的解
首先直接贴上个人看过比较好的一些的解析:
很全的PyTorch loss函数汇总:
torch.nn.CosineEmbeddingLoss
x
:包括x1
和x2
,即需要计算相似度的prediction
和GT
;y
:相当于人为给定的flag
,决定按哪种方式计算得到loss的结果。使用说明:
y=1
,prediction
和GT
完全一致时,loss为0,反之亦然。使用示例:
input1 = torch.randn(100, 128)input2 = torch.randn(100, 128)cos = nn.CosineEmbeddingLoss(reduction='mean')loss_flag = torch.ones([100]) # 需要初始化一个N维的1或-1output = cos(input1, input2, loss_flag)print(output)# tensor(1.0003)
来源地址:https://blog.csdn.net/qq_45779334/article/details/127229281
--结束END--
本文标题: Pytorch——常用损失函数详解
本文链接: https://www.lsjlt.com/news/417026.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0