目录
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
好
最后,老婆压场
喜欢的话,给我老婆点个赞吧☺



