当前位置:网站首页>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()
边栏推荐
猜你喜欢
STAHL触摸屏维修一体机显示屏ET-316-TX-TFT常见故障
Which websites are commonly used for patent searches?
Remove 360's detection and modification of the default browser
Convolutional Neural Network (CNN) mnist Digit Recognition - Tensorflow
【Untitled】
仿牛客论坛项目
Buttons with good user experience should not have hover state on mobile phones
【Social Media Marketing】How to know if your WhatsApp is blocked?
MySQL语法基础
【个人作品】记之-串口日志记录工具
随机推荐
【Social Media Marketing】How to know if your WhatsApp is blocked?
瀚高数据导入
用户身份标识与账号体系实践
泰德制药董事长郑翔玲荣膺“2022卓越影响力企业家奖” 泰德制药荣获“企业社会责任典范奖”
数据库单字段存储多个标签(位移操作)
"No title"
基于FPGA的任意字节数(单字节、多字节)的串口(UART)发送(含源码工程)
微信小程序云开发|个人博客小程序
使用常见问题解答软件的好处有哪些?
乐观锁批量跟新 纯SQL
[Energy Conservation Institute] Comparative analysis of smart small busbar and column head cabinet solutions in data room
string
Addition, Subtraction, Multiplication of Large Integers, Multiplication and Division of Large Integers and Ordinary Integers
iptables的使用简单测试
互联网大厂研发流程
自定义指令,获取焦点
多线程之生产者与消费者
仿牛客论坛项目
漏刻有时文档系统之XE培训系统二次开发配置手册
Interpretation of the meaning of each dimension of two-dimensional, three-dimensional, and four-dimensional matrices