Deeplearning常用的损失函数

2018-03-13  本文已影响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)

结果是相同的

上一篇 下一篇

猜你喜欢

热点阅读