【发布时间】:2021-03-12 21:15:56
【问题描述】:
我想构建一个堆叠的自动编码器或递归网络。这些是构建动态神经网络所必需的,它可以在每次迭代中改变其结构。
比如我先训练
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.fc1 = nn.Linear(784,500)
self.fc2 = nn.Linear(500,784)
def forward(self, x):
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
return x
接下来,我想使用之前的 fc1 和 fc2 进行训练
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.fc1 = nn.Linear(784,500)
self.fc3 = nn.Linear(500,10)
self.fc4 = nn.Linear(10,500)
self.fc2 = nn.Linear(500,784)
def forward(self, x):
x = F.relu(self.fc1(x))
x = F.relu(self.fc3(x))
x = F.relu(self.fc4(x))
x = F.relu(self.fc2(x))
return x
如何在单一模型中构建这些网络?
【问题讨论】:
-
你能详细说明一下吗?你到底想要什么?例如,即时创建新图层?您可以在 forward 方法中使用一个简单的 for 循环来执行此操作,该循环取决于输入
x。
标签: python neural-network deep-learning pytorch