《动手学》-池化层

1.理论

在这里插入图片描述
卷积对于位置太过于敏感,
最大池化层
在这里插入图片描述
池化层的作用
在这里插入图片描述
超参数
在这里插入图片描述
常用的最大池化层和平均池化层
在这里插入图片描述
总结
在这里插入图片描述
由2点,通常池化层是在卷积层之后进行的。

代码

torch.range和torch.arange区别

  • https://blog.csdn.net/m0_37586991/article/details/88830026
  • torch.range:This function is deprecated and will be removed in a future release
import torch
from torch import nn
from d2l import torch as d2l

def pool2d(X, pool_size, mode='max'):
    p_h, p_w = pool_size
    Y = torch.zeros((X.shape[0] - p_h + 1, X.shape[1] - p_w + 1))
    for i in range(Y.shape[0]):
        for j in range(Y.shape[1]):
            if mode == 'max':
                Y[i, j] = X[i:i + p_h, j:j + p_w].max()
            elif mode == 'avg':
                Y[i, j] = X[i:i + p_h, j:j + p_w].mean()
    return Y


X = torch.tensor([[0.0, 1.0, 2.0], [3.0, 4.0, 5.0], [6.0, 7.0, 8.0]])
pool2d(X, (2, 2))

pool2d(X, (2, 2), 'avg')

#填充和步幅
X = torch.arange(16, dtype=torch.float32).reshape((1, 1, 4, 4))
X

pool2d = nn.MaxPool2d(3, padding=1, stride=2)
pool2d(X)

#多个通道
X = torch.cat((X, X + 1), 1)
X

pool2d = nn.MaxPool2d(3, padding=1, stride=2)
pool2d(X)

X = torch.cat((X, X + 1), 1)就不会新增维度

QA

1.池化层为什么越来越少用?
池化层的作用大致可分为两种:1.减少卷积对位置过于敏感的缺点,2.通过stride减少数据量的运算
针对1->在数据输入时就可以进行各种图像的操作,尽量消除位置敏感的缺点。针对2->可以使用stride卷积代替池化层了
2.池化的窗口重叠有没有影响?
目前来看,池化的窗口重叠没有什么影响
在这里插入图片描述
1.最好是一次性创建完矩阵,或者X[:]这种。否则太低效。
2.可以用python的list 的list这种操作,最后转成tensor格式

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值