pytorch loss
参考文献:
loss 测试
import torch
from torch.autograd import Variable
'''
参考文献: https://blog.csdn.net/zhangxb35/article/details/72464152?utm_source=itdadao&utm_medium=referral
如果 reduce = False,那么 size_average 参数失效,直接返回向量形式的 loss;
如果 reduce = True,那么 loss 返回的是标量
如果 size_average = True,返回 loss.mean();
如果 size_average = True,返回 loss.sum();
'''
# nn.L1Loss: loss(input, target)=|input-target|
if False:
loss_fn = torch.nn.L1Loss(reduce=True, size_average=False)
input = torch.autograd.Variable(torch.randn(3, 4))
target = torch.autograd.Variable(torch.randn(3, 4))
loss = loss_fn(input, target)
print(input)
print(target)
print(loss)
p