例如,如果我有以下模型類:
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(),但是我想知道你是否可以以某種方式自動計算這個?
uj5u.com熱心網友回復:
PyTorch (>=1.8) 具有推斷輸入維度的LazyLinear 。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/479016.html
