[土堆]深度学习快速入门教程笔记——池化层——009

1. 池化层原理


  1. 最大池化层有时也被称为下采样。
  2. dilation为空洞卷积,如下图所示。
  3. Ceil_model为当超出区域时,只取最左上角的值。
  4. 池化使得数据由5 * 5 变为3 * 3,甚至1 * 1的,这样导致计算的参数会大大减小。例如1080P的电影经过池化的转为720P的电影、或360P的电影后,同样的网速下,视频更为不卡。


2.torch.nn.MaxPool2d


torch.nn.MaxPool2d(kernel_sizestride=Nonepadding=0dilation=1,

 return_indices=Falseceil_mode=False)

  • kernel_size (Union[intTuple[intint]]) – the size of the window to take a max over

  • stride (Union[intTuple[intint]]) – the stride of the window. Default value is kernel_size

  • padding (Union[intTuple[intint]]) – Implicit negative infinity padding to be added on both sides

  • dilation (Union[intTuple[intint]]) – a parameter that controls the stride of elements in the window

  • return_indices (bool) – if True, will return the max indices along with the outputs. Useful for torch.nn.MaxUnpool2d later

  • ceil_mode (bool) – when True, will use ceil instead of floor to compute the output shape

  • 当 ceil_mode=True 时,如果滑动窗口在左填充内边距内启动,则允许它们越界或输入。将在右侧填充区域开始的滑动窗口将被忽略。


3. 池化层处理图片


import torch
import torchvision
from torch import nn 
from torch.nn import MaxPool2d
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter

dataset = torchvision.datasets.CIFAR10("./dataset",train=False,transform=torchvision.transforms.ToTensor(),download=True)       
dataloader = DataLoader(dataset, batch_size=64)

class Tudui(nn.Module):
    def __init__(self):
        super(Tudui, self).__init__()
        self.maxpool = MaxPool2d(kernel_size=3, ceil_mode=True)
        
    def forward(self, input):
        output = self.maxpool(input)
        return output

tudui = Tudui()
writer = SummaryWriter("logs")
step = 0

for data in dataloader:
    imgs, targets = data
    writer.add_images("input", imgs, step)
    output = tudui(imgs)
    writer.add_images("output", output, step)
    step = step + 1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值