【发布时间】:2020-04-11 18:35:22
【问题描述】:
尝试训练 mnist 28x28x1 图像
我的模型是
def __init__(self):
super(CNN_mnist, self).__init__()
self.conv = nn.Sequential(
# 3 x 128 x 128
nn.Conv2d(1, 32, 3, 1, 1),
nn.BatchNorm2d(32),
nn.LeakyReLU(0.2),
# 32 x 128 x 128
nn.Conv2d(32, 64, 3, 1, 1),
nn.BatchNorm2d(64),
nn.LeakyReLU(0.2),
# 64 x 128 x 128
nn.MaxPool2d(2, 2),
# 64 x 64 x 64
nn.Conv2d(64, 128, 3, 1, 1),
nn.BatchNorm2d(128),
nn.LeakyReLU(0.2),
# 128 x 64 x 64
nn.Conv2d(128, 256, 3, 1, 1),
nn.BatchNorm2d(256),
nn.LeakyReLU(0.2),
# 256 x 64 x 64
nn.MaxPool2d(2, 2),
# 256 x 32 x 32
nn.Conv2d(256, 10, 3, 1, 1),
nn.BatchNorm2d(10),
nn.LeakyReLU(0.2)
)
# 256 x 32 x 32
self.avg_pool = nn.AvgPool2d(32)
# 256 x 1 x 1
self.classifier = nn.Linear(10, 10)
def forward(self, x):
features = self.conv(x)
flatten = self.avg_pool(features).view(features.size(0), -1)
output = self.classifier(flatten)
return output, features
我收到以下错误
RuntimeError:给定输入大小:(10x7x7)。计算输出大小: (10x0x0)。输出尺寸太小
不确定这个错误是什么意思,我应该在哪里修复它?
【问题讨论】:
-
请检查您的输入形状
x应该是Batch x Channels x Height x Width
标签: python image-processing computer-vision conv-neural-network pytorch