Machine learning 模型未学习:自定义激活功能和/或自定义丢失功能存在问题
当我训练我的模型时,这就是我所拥有的(我打印了损失函数、我的目标和模型的输出): 你知道为什么我的模型不学习吗?因为我的数据是好的,所以激活功能或丢失一定有问题。事实上,我已经在TensorFlow上创建了相同的模型,并且可以正常工作Machine learning 模型未学习:自定义激活功能和/或自定义丢失功能存在问题,machine-learning,deep-learning,pytorch,loss-function,activation-function,Machine Learning,Deep Learning,Pytorch,Loss Function,Activation Function,当我训练我的模型时,这就是我所拥有的(我打印了损失函数、我的目标和模型的输出): 你知道为什么我的模型不学习吗?因为我的数据是好的,所以激活功能或丢失一定有问题。事实上,我已经在TensorFlow上创建了相同的模型,并且可以正常工作 class QuaternionLoss(torch.nn.Module): def __init__(self): super(QuaternionLoss, self).__init__() def forw
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.ReLU(inplace=True),
torch.nn.Linear(64, 2),
LinearNormalized()
)
def forward(self, x):
output_orientation = self.model_vgg_orientation(x)
return output_orientation