当前位置:网站首页>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()
边栏推荐
- 【luogu P1912】诗人小G(二分栈)(决策单调性优化DP)
- Digital twin Beijing the imperial palace, yuan universe is the process of tourism
- 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
- 】 【 nn. The Parameter () to generate and why do you want to initialize
- Redis 做签到统计
- 【个人作品】记之-串口日志记录工具
- Fork/Join线程池
- [Personal work] Wireless network image transmission module
猜你喜欢
研究生新同学,牛人看英文文献的经验,值得你收藏
[Energy Conservation Institute] Application of Intelligent Control Device in High Voltage Switchgear
Get started quickly with MongoDB
【Untitled】
New graduate students, great experience in reading English literature, worthy of your collection
【多任务优化】DWA、DTP、Gradnorm(CVPR 2019、ECCV 2018、 ICML 2018)
[Multi-task optimization] DWA, DTP, Gradnorm (CVPR 2019, ECCV 2018, ICML 2018)
vant实现Select效果--单选和多选
【节能学院】安科瑞餐饮油烟监测云平台助力大气污染攻坚战
Godaddy域名解析速度慢问题以及如何使用DNSPod解析解决
随机推荐
Hangao data import
Redis 做签到统计
解除360对默认浏览器的检测与修改
启明云端分享|盘点ESP8684开发板有哪些功能
"No title"
Acrel-5010重点用能单位能耗在线监测系统在湖南三立集团的应用
OSG Notes: Set DO_NOT_COMPUTE_NEAR_FAR to manually calculate far and near planes
iptables的使用简单测试
专利检索常用的网站有哪些?
密码学的基础:X.690和对应的BER CER DER编码
1374. 生成每种字符都是奇数个的字符串 : 简单构造模拟题
有点奇怪!访问目的网址,主机能容器却不行
【Dart】dart构造函数学习记录(含dart单例模式写法)
用户身份标识与账号体系实践
洛谷 P2440 木材加工
98. Embedded controller EC actual combat EC development board development completed
【无标题】
外骨骼机器人(七):标准步态数据库
基于FPGA的任意字节数(单字节、多字节)的串口(UART)发送(含源码工程)
算法---解码方法(Kotlin)