PyTorch学习笔记 批标准化

手写体(64,1,28,28)
经过stage1变为(64,16,5,5)
经过view(shape[0],-1)变为(64,1655)即(64,400)
经过线性变化[400,10],变为(64,10)
这就是经过卷积,池化和批标准化后,数据形状的变化。
1

# 使用批标准化
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值