将图层格式更改为不同的图像分辨率



有一个类,所有内容都设置为32x32图像格式从这里拍摄

class Net(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(1, 6, 5) # here I changed the image channel from 3 to 1
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(6, 64, 5)
self.fc1 = nn.Linear(64 * 5 * 5, 120)
self.fc2 = nn.Linear(120, 84)
self.fc3 = nn.Linear(84, 22) # here I changed the number of output neurons from 10 to 22
def forward(self, x):
x = self.pool(F.relu(self.conv1(x)))
x = self.pool(F.relu(self.conv2(x)))
x = torch.flatten(x, 1) # flatten all dimensions except batch
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return x

如何根据第96至96号决议改变这一切?通道1(灰度(?

分辨率32x32时,conv2的输出为(1, 64, 5, 5)。另一方面,如果输入的分辨率96x96,则它将是(1, 64, 21, 21)。这意味着fc1需要具有28_224输入神经元。

>>> self.fc1 = nn.Linear(64 * 21 * 21, 120)

或者,您可以使用nn.LazyLinear,它将根据第一个推断为您推断这个数字。

>>> self.fc1 = nn.Linear(120)

最新更新