版权声明:本文为博主原创文章,欢迎转载,并请注明出处。联系方式:460356155@qq.com
网络定义代码:
#定义网络模型
class LeNet(nn.Module):
def __init__(self):
super(LeNet, self).__init__()
self.cnn = nn.Sequential(
#卷积层1,单通道输入,6个卷积核,核大小5*5
#经过该层图像大小变为28-5+1,24*24
#经2*2最大池化,图像变为12*12
nn.Conv2d(1, 6, 5),
nn.ReLU(),
nn.MaxPool2d(2),
#卷积层2,6通道,16个卷积核,核大小5*5
#经过该层图像变为12-5+1,8*8
# 经2*2最大池化,图像变为4*4
nn.Conv2d(6, 16, 5),
nn.ReLU(),
nn.MaxPool2d(2)
)
self.fc = nn.Sequential(
# 16个feature,每个feature4*4
nn.Linear(16 * 4 * 4, 120),
nn.ReLU(),
nn.Linear(120, 84),
nn.ReLU(),
nn.Linear(84, 10)
)
def forward(self, x):
x = self.c