美文网首页
Deeplearning常用的损失函数

Deeplearning常用的损失函数

作者: 山有木紫 | 来源:发表于2018-03-13 22:05 被阅读0次

参考资料:
pytorch中文
pytorch官方doc

1.L1Loss= |x-y|
2.SmoothL1Loss



3.MSELoss均方损失函数 = (x-y)^2
4.CrossEntropyLoss


image.png
5.NLLLoss
loss(x,class)=−x[class]
*注意crossEntropyLoss相当于NLLLoss前加一个logsoftmax层
import torch
from torch.autograd import Variable
import torch.nn as nn
m = nn.LogSoftmax()
NLLLoss = nn.NLLLoss()
CrossEntrooyLoss = nn.CrossEntropyLoss()
input = Variable(torch.rand(3, 5), requires_grad=True)
target = Variable(torch.LongTensor().random_(5)) # random 0-4
crossentropyloss = CrossEntrooyLoss(input, target)
nllloss = NLLLoss(m(input), target)
print(crossentropyloss, nllloss)

结果是相同的

相关文章

网友评论

      本文标题:Deeplearning常用的损失函数

      本文链接:https://www.haomeiwen.com/subject/dxezfftx.html