in_channels=1,  # 输入卷积层的图片通道数
            out_channels=20,  # 输出的通道数
            kernelSize=3,  # 卷积核的大小,长宽相等,3*3
            stride=1,  # 滑动步长为1
            padding=2  # 在输入张量周围补的边
            poolKernelSize=2 # 池化层的filters的大小2*2

image-20220416212756296

from torch.nn import Module
from torch import nn


class Model(Module):
def __init__(self):
super(Model, self).__init__()
self.conv1 = nn.Conv2d(in_channels=1, out_channels=6, kernel_size=3, stride=2, padding=2) # w0 = 9
self.relu1 = nn.ReLU()
self.pool1 = nn.MaxPool2d(2) # w1 = 6
self.conv2 = nn.Conv2d(6, 16, 2, padding=1) # w2 = 3
self.relu2 = nn.ReLU()
self.pool2 = nn.MaxPool2d(2) # w3 = 4
self.fc1 = nn.Linear(64, 120)
self.relu3 = nn.ReLU()
self.fc2 = nn.Linear(120, 84)
self.relu4 = nn.ReLU()
self.fc3 = nn.Linear(84, 10)
self.relu5 = nn.ReLU()

def forward(self, x):
y = self.conv1(x)
y = self.relu1(y)
y = self.pool1(y)
y = self.conv2(y)
y = self.relu2(y)
y = self.pool2(y)
y = y.view(y.shape[0], -1)
y = self.fc1(y)
y = self.relu3(y)
y = self.fc2(y)
y = self.relu4(y)
y = self.fc3(y)
y = self.relu5(y)
return y

Resize

9x9 ->ttransform = Compose([Resize(28),ToTensor()])) ->28x28