首页 > 其他 > 详细

损失函数

时间:2021-04-27 14:24:26      阅读:18      评论:0      收藏:0      [点我收藏+]
import torch
import torch.nn as nn
input = torch.randn(3, 3)
#print(input)
sm = nn.Softmax(dim=1)
sl = nn.LogSoftmax(dim=1)
#print(sm(input))
test1 = torch.log(sm(input))
print(test1)
print(sl(input))
print(test1[1][2])
print(abs(test1[0][0] + test1[1][2] + test1[2][1]) / 3)

loss = nn.NLLLoss()
target = torch.tensor([0, 2, 1])
l1 = loss(test1, target)
print(l1)

loss_1 = nn.CrossEntropyLoss()
print(loss_1(input, target))
target = torch.tensor([0])
print(target)

x,y= 2,3
print(x,y)

损失函数

原文:https://www.cnblogs.com/sleven/p/14707618.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!