<reponame>q759729997/qytPytorch
from torch import nn


class LeNet(nn.Module):
    """早期用来识别手写数字图像的卷积神经网络"""
    def __init__(self):
        super().__init__()
        self.conv = nn.Sequential(
            nn.Conv2d(1, 6, 5),  # in_channels, out_channels, kernel_size
            nn.Sigmoid(),
            nn.MaxPool2d(2, 2),  # kernel_size, stride
            nn.Conv2d(6, 16, 5),
            nn.Sigmoid(),
            nn.MaxPool2d(2, 2))
        # input_shape = (64, 1, 28, 28)  # 批量大小, 通道, 高, 宽
        self.fc = nn.Sequential(
            nn.Linear(16 * 4 * 4, 120),
            nn.Sigmoid(),
            nn.Linear(120, 84),
            nn.Sigmoid(),
            nn.Linear(84, 10))

    def forward(self, img):
        feature = self.conv(img)
        output = self.fc(feature.view(img.shape[0], -1))
        return output

from torch import nn


class LeNet(nn.Module):
    """早期用来识别手写数字图像的卷积神经网络"""
    def __init__(self):
        super().__init__()
        self.conv = nn.Sequential(
            nn.Conv2d(1, 6, 5),  # in_channels, out_channels, kernel_size
            nn.Sigmoid(),
            nn.MaxPool2d(2, 2),  # kernel_size, stride
            nn.Conv2d(6, 16, 5),
            nn.Sigmoid(),
            nn.MaxPool2d(2, 2))
        # input_shape = (64, 1, 28, 28)  # 批量大小, 通道, 高, 宽
        self.fc = nn.Sequential(
            nn.Linear(16 * 4 * 4, 120),
            nn.Sigmoid(),
            nn.Linear(120, 84),
            nn.Sigmoid(),
            nn.Linear(84, 10))

    def forward(self, img):
        feature = self.conv(img)
        output = self.fc(feature.view(img.shape[0], -1))
        return output
早期用来识别手写数字图像的卷积神经网络 # in_channels, out_channels, kernel_size # kernel_size, stride # input_shape = (64, 1, 28, 28)  # 批量大小, 通道, 高, 宽