池化层【马赛克】

最大池化,也叫下采样。

公式:

参数:

celling的意思:

例子:

尺寸:

code:

复制代码
import torchimport torchvision.datasetsfrom tensorboardX import SummaryWriterfrom torch import nnfrom torch.nn import MaxPool2dfrom torch.utils.data import DataLoader​dataset = torchvision.datasets.CIFAR10("data",train=False,download=True,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))print(input.shape)​class Tudui(nn.Module):    def __init__(self):        super(Tudui,self).__init__()        self.maxpool1 = MaxPool2d(kernel_size=3,ceil_mode = True)    def forward(self,input):        output = self.maxpool1(input)        return  output​tudui = Tudui()output = tudui(input)print(output)​writer = SummaryWriter("logs_maxpool")step = 0for data in dataloader:    imgs,targets = data    writer.add_images("input",imgs,step)    output=tudui(imgs)    writer.add_images("output",output,step)    step = step+1writer.close()
相关推荐
郝学胜-神的一滴4 分钟前
Python数据封装与私有属性:保护你的数据安全
linux·服务器·开发语言·python·程序人生
智航GIS11 分钟前
11.7 使用Pandas 模块中describe()、groupby()进行简单分析
python·pandas
Pyeako16 分钟前
机器学习--矿物数据清洗(六种填充方法)
人工智能·python·随机森林·机器学习·pycharm·线性回归·数据清洗
光羽隹衡17 分钟前
深度学习——卷积神经网络CNN
人工智能·深度学习·cnn
ScilogyHunter1 小时前
SCons:Python驱动的智能构建系统
python·构建系统·scons
luoluoal1 小时前
基于python的基于深度学习的车俩特征分析系(源码+文档)
python·mysql·django·毕业设计·源码
轻竹办公PPT1 小时前
2026 年 AI 办公趋势:AI 生成 PPT 工具谁在领先
人工智能·python
人工智能培训1 小时前
如何大幅降低大模型的训练和推理成本?
人工智能·深度学习·大模型·知识图谱·强化学习·智能体搭建·大模型工程师
之之为知知1 小时前
NLP进化史:一场「打补丁」的技术接力赛
人工智能·深度学习·机器学习·自然语言处理·大模型