一开始写模型的时候,网上学习到的都是那种非常简单的模型,可是我要实现的模型是将多个模型套起来,一个大模型,一起训练。
其实只要先定义几个小模型,然后将其定义在大模型的init中,然后用forward来控制内部的运作即可,直接看代码把。
class Model_one(nn.Module):
def __init__(self, n_input, n_output):
super(Model_one, self).__init__()
self.predict = nn.Linear(n_input, n_output, bias=False)
def forward(self, x):
out = self.predict(x)
return out
class Model_two(nn.Module):
def __init__(self, n_input, n_output):
super(Model_two, self)