当前位置:网站首页>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()
边栏推荐
- 卷积神经网络(CNN)mnist数字识别-Tensorflow
- 面试突击70:什么是粘包和半包?怎么解决?
- STAHL触摸屏维修一体机显示屏ET-316-TX-TFT常见故障
- 大整数相加,相减,相乘,大整数与普通整数的相乘,相除
- 有用的网站
- Go Atomic
- 【torch】张量乘法:matmul,einsum
- 仿牛客论坛项目
- New graduate students, great experience in reading English literature, worthy of your collection
- Failed to re-init queues : Illegal queue capacity setting (abs-capacity=0.6) > (abs-maximum-capacity
猜你喜欢
随机推荐
不同的操作加不同的锁详解
tiup mirror grant
Remove 360's detection and modification of the default browser
Redis does check-in statistics
【Dart】dart之mixin探究
latex论文神器--服务器部署overleaf
系统收集集
给定中序遍历和另外一种遍历方法确定一棵二叉树
Protocol Buffer 使用
excel高级绘图技巧100讲(二十二)-如何对不规则数据进行分列
LinkedList source code sharing
tiup mirror clone
[Personal Work] Remember - Serial Logging Tool
Excel advanced drawing techniques, 100 (22) - how to respectively the irregular data
The Internet giant development process
【节能学院】安科瑞餐饮油烟监测云平台助力大气污染攻坚战
[Energy Conservation Institute] Comparative analysis of smart small busbar and column head cabinet solutions in data room
Wildcard SSL/TLS certificate
密码学的基础:X.690和对应的BER CER DER编码
Use WeChat official account to send information to designated WeChat users