pytorch 区间loss 损失函数
【摘要】
pytorch 区间loss 损失函数
我们知道sigmoid可以把值转化为0-1之间。
tanh函数可以把值转化到[-1,1]之间,
但是在回归时,希望梯度是均匀的,有么有别的方法呢?
答案是肯定的,
解决方法1:
data=torch.sin(data)
周期性函数,把值变到了0-1之间。
解决方法2:
比如要...
pytorch 区间loss 损失函数
我们知道sigmoid可以把值转化为0-1之间。
tanh函数可以把值转化到[-1,1]之间,
但是在回归时,希望梯度是均匀的,有么有别的方法呢?
答案是肯定的,
解决方法1:
data=torch.sin(data)
周期性函数,把值变到了0-1之间。
解决方法2:
比如要回归A,希望A在1到-1之间,可以设计损失函数:
import torch
class My_Loss3(torch.nn.Module):
def __init__(self):
super(My_Loss3, self).__init__()
def forward(self, pred_angle0, label):
l1 = torch.clamp(torch.abs(pred_angle0)-1, min=0)
c1 = torch.abs(pred_angle0 - label)
c2 =torch.abs(2 - c1)
l3 = torch.where(c1 > c2, c2, c1)
return torch.mean(0.1*l3 + l1)
希望A在0-1之间,将来预测结果为abs(A),这个损失函数是Ok的。
import torch
class My_Loss3(torch.nn.Module):
def __init__(self):
su
文章来源: blog.csdn.net,作者:AI视觉网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/121216624
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
作者其他文章
评论(0)