栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

简单记录一下,几个经典的网络结构

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

简单记录一下,几个经典的网络结构

目录

LeNet


LeNet

 lenet很经典的网络结构,在1998年由大佬LeCun提出,仅仅只有七层网络(对于今天来说肯定是洒洒水蜡)

两层卷积层+两层下采样层(池化层)+三层全连接层:

话说,这不应该算是 5层吗?(应该是带参数的才算,池化层不算进去的吧),怎么是7层网络的,我也不知道怎么回事,有知道的可以告诉我原因吗?

下面是网络的结构图

图片截自论文,非本人所有

如果看不清,这里高清无码图:

 图片截自WIKI,非本人所有

pytorch代码:

class LeNet(nn.Module):
    def __init__(self):
        super(LeNet, self).__init__()

        layer1 = nn.Sequential()
        layer1.add_module('conv1', nn.Conv2d(1, 6, 5, 1, 0))    ##28
        layer1.add_module('pool1', nn.MaxPool2d(2,2))   ##14
        self.layer1 = layer1

        layer2 = nn.Sequential()
        layer2.add_module('conv2', nn.Conv2d(6, 16, 5, 1, 0)) ##10
        layer2.add_module('pool2', nn.MaxPool2d(2, 2))  ##5
        self.layer2 = layer2

        layer3 = nn.Sequential()
        layer3.add_module('fc1', nn.Linear(400, 120))
        layer3.add_module('fc2', nn.Linear(120, 84))
        layer3.add_module('fc3', nn.Linear(84, 10))
        self.layer3 = layer3

    def forward(self, x):
        x = self.layer1(x)
        x = self.layer2(x)
        x = torch.reshape(x, (x.shape[0], -1))
        x = self.layer3(x)
        return x

AlexNet

AlexNet网络在2012年提出,在ImageNet比赛当中以领先第二名10%精确度的成绩夺得冠军,相对于LeNet,层数更深,同时第一次引入了激活层ReLU,在全连接层引人了Dropout层防止过拟合。

 详细图解:

pytorch代码如下:

class AlexNet(nn.Module):
    def __init__(self):
        super(AlexNet, self).__init__()
        self.features = nn.Sequential(
            nn.Conv2d(1, 96, 11, 4, 1),     #54
            nn.ReLU(inplace=True),
            nn.MaxPool2d(3, 2),             #26

            nn.Conv2d(96, 256, 5, 1, 2),  # 26
            nn.ReLU(inplace=True),
            nn.MaxPool2d(3, 2),              # 12

            nn.Conv2d(256, 384, 3, 1, 1),  # 12
            nn.ReLU(inplace=True),
            nn.Conv2d(384, 384, 3, 1, 1),  # 12
            nn.ReLU(inplace=True),
            nn.Conv2d(384, 256, 3, 1, 1),  # 12
            nn.ReLU(inplace=True),
            nn.MaxPool2d(3, 2)  # 5
        )
        self.classifier = nn.Sequential(
            nn.Dropout(),
            nn.Linear(256*5*5, 4096),
            nn.ReLU(inplace=True),
            nn.Dropout(),
            nn.Linear(4096, 4096),
            nn.ReLU(inplace=True),
            nn.Linear(4096, 10)         #10 为分类的数量
        )

    def forward(self, x):
        x = self.features(x)
        x = torch.reshape(x, (x.shape[0], -1))
        x = self.classifier(x)
        return x

VggNet

是2014年Image大赛的亚军,层数比AlexNet更深,卷积核更小,它之所以使用很多小的滤波器、是因为层叠很多小的滤波器的感受野和一个大的滤波器的感受野是相同的,还能减少参数,同时有更深的网络结构。、

网络结构图:

详细图:

​​​​​​​ 

pytorch代码:

class VGG(nn.Module):
    def __init__(self):
        super(VGG, self).__init__()
        self.features = nn.Sequential(
            nn.Conv2d(1, 64, 3, 1, 1),      #224
            nn.ReLU(True),

            nn.Conv2d(64, 64, 3, 1, 1),     #224
            nn.ReLU(True),
            nn.MaxPool2d(2,2),              ##112

            nn.Conv2d(64, 128, 3, 1, 1),    #112
            nn.ReLU(True),

            nn.Conv2d(128, 128, 3, 1, 1),   #112
            nn.ReLU(True),
            nn.MaxPool2d(2, 2),             ##56

            nn.Conv2d(128, 256, 3, 1, 1),  # 56
            nn.ReLU(True),

            nn.Conv2d(256, 256, 3, 1, 1),  # 56
            nn.ReLU(True),

            nn.Conv2d(256, 256, 3, 1, 1),  # 28
            nn.ReLU(True),
            nn.MaxPool2d(2, 2),  ##28

            nn.Conv2d(256, 512, 3, 1, 1),  # 28
            nn.ReLU(True),

            nn.Conv2d(512, 512, 3, 1, 1),  # 28
            nn.ReLU(True),

            nn.Conv2d(512, 512, 3, 1, 1),  # 28
            nn.ReLU(True),
            nn.MaxPool2d(2,2),              # 14

            nn.Conv2d(512, 512, 3, 1, 1),  # 14
            nn.ReLU(True),

            nn.Conv2d(512, 512, 3, 1, 1),  # 14
            nn.ReLU(True),

            nn.Conv2d(512, 512, 3, 1, 1),  # 14
            nn.ReLU(True),
            nn.MaxPool2d(2, 2),            # 7
        )
        self.clifier = nn.Sequential(
            nn.Linear(512*7*7, 4096),
            nn.ReLU(True),
            nn.Dropout(),

            nn.Linear(4096, 4096),
            nn.ReLU(True),
            nn.Dropout(),

            nn.Linear(4096, 10)
        )

    def forward(self, x ):
        x = self.features(x)
        x = torch.reshape(x, (x.shape[0], -1))
        x = self.clifier(x)

        return x

好

最后,老婆压场

喜欢的话,给我老婆点个赞吧☺

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1025909.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号