如何解决使用 Pytorch 对网络结构进行超参数优化
我已经构建了一个具有自定义架构的神经网络,设计如下。 不,我想执行超参数优化以找到最佳学习率、批量大小,以及每个隐藏层的神经元数量和层数。
一开始我有三个单独的 NN,它们连接起来,然后通过一些密集层再次处理。
直到现在我还没有找到在 Pytorch 超参数优化中调整层数的方法。 理想情况下,我也想测试一下这三个网是否需要不同的层数。
class Individual(nn.Module):
def __init__(self):
super(Individual,self).__init__()
self.fc1_left = nn.Linear(30,24)
self.fc1_right = nn.Linear(30,24)
self.fc1_cor = nn.Linear(2,4)
self.fc2_cor = nn.Linear(4,4)
self.fc2_left = nn.Linear(24,4)
self.fc2_right = nn.Linear(24,4)
self.fc3 = nn.Linear(12,36)
self.fc4 = nn.Linear(36,num_classes)
self.Sigmoid_left = nn.Sigmoid()
self.Sigmoid_right = nn.Sigmoid()
def forward(self,x_left,x_right,x_cor,x_con):
x_con_l = x_con[:,0].view(-1,1)
x_con_r = x_con[:,1].view(-1,1)
x_left = F.relu(self.fc1_left(x_left))
x_left = F.relu(self.fc2_left(x_left))
x_left = torch.mul(x_left,x_con_l)
x_right = F.relu(self.fc1_right(x_right))
x_right = F.relu(self.fc2_right(x_right))
x_right = torch.mul(x_right,x_con_r)
x_cor = F.relu(self.fc1_cor(x_cor))
x_cor = F.relu(self.fc2_cor(x_cor))
combined = torch.cat((x_left.view(x_left.size(0),-1),x_right.view(x_right.size(0),-1)),dim=1)
combined = torch.cat((combined.view(combined.size(0),x_cor.view(x_cor.size(0),dim=1)
x1 = F.relu(self.fc3(combined))
x2 = F.relu(self.fc4(x1))
return x2
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。