手写体(64,1,28,28)
经过stage1变为(64,16,5,5)
经过view(shape[0],-1)变为(64,1655)即(64,400)
经过线性变化[400,10],变为(64,10)
这就是经过卷积,池化和批标准化后,数据形状的变化。
# 使用批标准化
class conv_bn_net(nn.Module):
def __init__(self):
super(conv_bn_net, self).__init__()
self.stage1 = nn.Sequential(
nn.Conv2d(1, 6, 3, padding=1),
nn.BatchNorm2d(6),
nn.ReLU(True),
nn.MaxPool2d(2, 2),
nn.Conv2d(6, 16, 5),
nn.BatchNorm2d(16),
nn.ReLU(True),
nn.MaxPool2d(2, 2)
)
self.classfy = nn.Linear(400, 10)
def forward(self, x):
x = self.stage1(x)
print('x.stage1.shape', x.shape)
print('x.shape[0]', x.shape[0])
x = x.view(x.shape[0], -1)
print('x.view.shape', x.shape)
x = self.classfy(x)
print('x.classfy.shape', x.shape)
return x