成功解决
RuntimeError: The size of tensor a (22) must match the size of tensor b (32) at non-singleton dimension 3
报错原因
使用print查看了x的维度和out的维度,发现
out = torch.Size([10, 300, 22, 22])
x = torch.Size([10, 3, 32, 32])
为什么输入x是图片是3232大小,out就变成了2222?
仔细检查网络,发现具有3*3卷积核的卷积层没有加padding=1。导致每次卷积图片缩小1个单位。
解决方法
将具有3*3卷积核的卷积层
nn.Conv2d(planes, planes, kernel_size=3, bias=False),
改为
nn.Conv2d(planes, planes, kernel_size=3, padding=1, bias=False),
成功解决!不报错了!