池化层

池化层

前言

卷积对位置信息的敏感度较高,而池化层对位置信息的敏感度较低。
池化层的作用是降低卷积层的敏感度,减少计算量,防止过拟合。

池化方式

  1. 最大池化: 取池化窗口内的最大值作为输出。
  2. 平均池化: 取池化窗口内的平均值作为输出。

代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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


池化层
http://example.com/2025/08/18/25_08_18池化层/
作者
ZF ZHAO
发布于
2025年8月18日
许可协议