LeNet:Gradient-Based Learning Applied to Document Recognition

1.论文:Gradient-Based Learning Applied to Document Recognition

2.网络结构:

 

LeNet包括7个layers(不包括Input),Fig 1中的C、S和F分别指卷积层、下采样层(池化层)和全连接层,其后所跟随的数字1-6指所在层的索引位置。例如,S2意为在网络结构中索引为2的位置的下采样层。

 3.代码实现,pytorch

import torch
import torch.nn as nn


class LeNet(nn.Module):
    def __init__(self, num_class=10):
        super(LeModel, self).__init__()
        self.conv1 = nn.Conv2d(1, 6, 5)   # 1x28x28 -> 6x24x24
        self.pool1 = nn.AvgPool2d(2)    # 6x24x24 -> 6x12x12
        self.conv2 = nn.Conv2d(6, 16, 5)    # 6x12x12 -> 16x8x8
        self.pool2 = nn.AvgPool2d(2)    # 16x8x8 -> 16x4x4
        self.conv3 = nn.Conv2d(16, 120, 4)  # LeNet的input是32x32,MNIST为28x28,对此修改卷积核尺寸为4x4
        self.FC1 = nn.Linear(120*1*1, 84)
        self.Classifier = nn.Linear(84, num_class)

    def forward(self, x):
        x = torch.tanh(self.conv1(x))
        x = self.pool1(x)
        x = torch.tanh(self.conv2(x))
        x = self.pool2(x)
        x = torch.tanh(self.conv3(x))
        x = x.view(-1, 120*1*1)
        x = self.FC1(x)
        x = torch.tanh(x)
        x = self.Classifier(x)
        return x

4.https://blog.csdn.net/weixin_48249563/article/details/109411554

这个链接中有用lenet实现手写数字识别的代码

posted @ 2022-03-09 15:28  Tomorrow1126  阅读(302)  评论(0编辑  收藏  举报