RuntimeError: size mismatch, m1: [512 x 12800], m2: [2048 x 1024] at C
说一下这错误,意思就是m1和m2两个数组尺寸不一样。
为啥不一样,那就看看自己构建的网络
是不是有问题
或者传入数据是不是有问题,我的网络少了一层池化层
在self.layer2
层少了最后一层。
注意
一定要在每次输出后面标注出来维度,这样就不会容易犯错。
class CNN(nn.Module):
def __init__(self):
super(CNN, self).__init__()
self.layer1 = nn.Sequential(
nn.Conv2d(1, 16, kernel_size=3), # 16, 26 ,26
nn.BatchNorm2d(16