"""
本节主要学会最大池化层的使用
池化层大大减少了数据量
"""
import torch
import torchvision
from torch import nn
from torch.nn import Conv2d, MaxPool2d
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
dataset = torchvision.datasets.CIFAR10('./torchvision_dataset', train=False, download=False,
transform=torchvision.transforms.ToTensor())
dataloader = DataLoader(dataset,batch_size=64)
# input = torch.tensor([[1,2,0,3,1],
# [0,1,2,3,1],
# [1,2,1,0,0],
# [5,2,3,1,1],
# [2,1,0,1,1]],dtype=torch.float32)
# input = torch.reshape(input,(-1,1,5,5))
class Zkl(nn.Module):
def __init__(self):
super(Zkl, self).__init__()
self.maxpool1 =MaxPool2d(kernel_size=3,ceil_mode=False)
def forward(self,x):
output = self.maxpool1(x)
return output
zkl = Zkl()
writer = SummaryWriter('nn_maxpool')
step = 0
for data in dataloader:
imgs,targets = data
writer.add_images('input_maxpool',imgs,step)
output = zkl(imgs)
writer.add_images('output_maxpool',output,step)
step += 1
writer.close()
pytorch入门11:最大池化层的使用
最新推荐文章于 2024-03-07 20:34:46 发布