例如,如果我有以下模型类:
class MyTestModel(nn.Module):
def __init__(self):
super(MyTestModel, self).__init__()
self.seq1 = nn.Sequential(
nn.Conv2d(3, 6, 3),
nn.MaxPool2d(2, 2),
nn.Conv2d(6, 16, 3),
nn.MaxPool2d(2, 2),
nn.Flatten(),
nn.Linear(myflattendinput(), 120), # how to automate this?
nn.ReLU(),
nn.Linear(120, 84),
nn.ReLU(),
nn.Linear(84, 2),
)
self.softmax = nn.Softmax(dim=1)
def forward(self, x):
x = self.seq1(x)
x = self.softmax(x)
return x
我知道,通常情况下,你会让数据加载器给模型提供一个固定大小的输入,这样在nn.Flatten()
之后就有一个固定大小的层输入,但是我想知道你是否可以自动计算这个?