如何解决模型无法学习:自定义激活功能和/或自定义损失功能存在问题
class QuaternionLoss(torch.nn.Module):
def __init__(self):
super(QuaternionLoss,self).__init__()
def forward(self,output,target):
loss = 100 * (1 - torch.dot(output.squeeze(0),target.squeeze(0)))
return loss
class Linearnormalized(torch.nn.Module):
def __init__(self):
super(Linearnormalized,self).__init__() # init the class
def forward(self,x):
return linear_normalized(x)
class VGGOrientation(torch.nn.Module):
def __init__(self):
super(VGGOrientation,self).__init__()
self.model_vgg_orientation = torchvision.models.vgg16(pretrained=True)
self.model_vgg_orientation.classifier = torch.nn.Sequential(
torch.nn.Linear(25088,256),torch.nn.ReLU(inplace=True),torch.nn.Linear(256,64),torch.nn.Linear(64,2),Linearnormalized()
)
def forward(self,x):
output_orientation = self.model_vgg_orientation(x)
return output_orientation
当我训练模型时,这就是我所拥有的(我打印出损失函数,目标和模型输出): enter image description here
您对我的模型为什么不学习有任何想法吗?激活功能或丢失必定有问题,因为我的数据很好。实际上,我已经在TensorFlow上创建了相同的模型,并且可以正常工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。