当前位置:网站首页>Pytorch框架学习记录8——最大池化的使用
Pytorch框架学习记录8——最大池化的使用
2022-08-01 20:36:00 【柚子Roo】
Pytorch框架学习记录8——最大池化的使用
1. MaxPool2d介绍
torch.nn.MaxPool2d(kernel_size, stride=None, padding=0, dilation=1, return_indices=False, ceil_mode=False)
在由多个输入平面组成的输入信号上应用 2D 最大池化。
参数
- kernel_size – 最大的窗口大小
- stride——窗口的步幅。默认值为
kernel_size - padding – 要在两边添加隐式零填充
- dilation – 控制窗口中元素步幅的参数
- return_indices - 如果
True,将返回最大索引以及输出。torch.nn.MaxUnpool2d以后有用 - ceil_mode – 当为 True 时,将使用ceil而不是floor来计算输出形状
当 ceil_mode=True 时,如果滑动窗口在左侧填充或输入内开始,则允许滑动窗口越界。将在右侧填充区域开始的滑动窗口将被忽略。
2. 举例
import torch
from torch import nn
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 Test(nn.Module):
def __init__(self):
super(Test, self).__init__()
self.maxpool1 = nn.MaxPool2d(kernel_size=3, stride=1, ceil_mode=True)
def forward(self, input):
output = self.maxpool1(input)
return output
test = Test()
output = test(input)
print(output)
从图像上直观展示maxpooling的效果:
import torch
from torch import nn
import torchvision
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
dataset = torchvision.datasets.CIFAR10(root='./dataset', train=False, transform=torchvision.transforms.ToTensor(), download=True)
dataloader = DataLoader(dataset, batch_size=64)
class Test(nn.Module):
def __init__(self):
super(Test, self).__init__()
self.maxpool1 = nn.MaxPool2d(kernel_size=3, stride=1, ceil_mode=True)
def forward(self, input):
output = self.maxpool1(input)
return output
test = Test()
writer = SummaryWriter('logs')
step = 0
for data in dataloader:
imgs, target = data
output = test(imgs)
writer.add_images("maxpool", output, global_step=step)
step += 1
writer.close()

边栏推荐
- Use WeChat official account to send information to designated WeChat users
- Digital twin Beijing the imperial palace, yuan universe is the process of tourism
- 多线程之生产者与消费者
- Redis does web page UV statistics
- useful website
- Get started quickly with MongoDB
- Remove 360's detection and modification of the default browser
- Failed to re-init queues : Illegal queue capacity setting (abs-capacity=0.6) > (abs-maximum-capacity
- 二维、三维、四维矩阵每个维度含义解释
- 扣减库存方案
猜你喜欢

New graduate students, great experience in reading English literature, worthy of your collection

扣减库存方案

数字孪生北京故宫,元宇宙推进旅游业进程

】 【 nn. The Parameter () to generate and why do you want to initialize

【多任务学习】Modeling Task Relationships in Multi-task Learning with Multi-gate Mixture-of-Experts KDD18

面试突击70:什么是粘包和半包?怎么解决?

有点奇怪!访问目的网址,主机能容器却不行

KDD2022 | 自监督超图Transformer推荐系统

我的驾照考试笔记(3)

Postman 批量测试接口详细教程
随机推荐
二维、三维、四维矩阵每个维度含义解释
【Dart】dart之mixin探究
【节能学院】推进农业水价综合改革的意见解读
【Social Media Marketing】How to know if your WhatsApp is blocked?
StringTable Detailed String Pool Performance Tuning String Concatenation
idea插件generateAllSetMethod一键生成set/get方法以及bean对象转换
【nn.Parameter()】生成和为什么要初始化
Custom command to get focus
专利检索常用的网站有哪些?
StringTable详解 串池 性能调优 字符串拼接
tiup mirror clone
tiup mirror genkey
启明云端分享|盘点ESP8684开发板有哪些功能
Fork/Join线程池
Little data on how to learn?Jida latest small learning data review, 26 PDF page covers the 269 - page document small data learning theory, method and application are expounded
What is the difference between a utility model patent and an invention patent?Understand in seconds!
数据库单字段存储多个标签(位移操作)
tiup mirror grant
扣减库存方案
任务调度线程池基本介绍