# CNN-最大池化

## 最大池化的过程

Let's say we have a 4x4 matrix representing our initial input.
Let's say, as well, that we have a 2x2 filter that we'll run over our input. We'll have a stride of 2 (meaning the (dx, dy) for stepping over our input will be (2, 2)) and won't overlap regions.

For each of the regions represented by the filter, we will take the max of that region and create a new, output matrix where each element is the max of a region in the original input.

In order to make this super easy, with a nice pictorial representation - I give you this:

image.png

## 优点

image.png
1. 不增加额外的参数。
所以不用担心最大池化会导致过拟合。
2. 通常会提高模型的准确性。
3. 更大的计算量。Since the convolutions that went below run at lower stride, the model then becomes a lot more expensive to compute.
4. 更多的超参数。比如：池区尺寸、池化步幅。

## 缺点

• 现在的数据集又大又复杂，我们更关心欠拟合问题。
• Dropout 是一个更好的正则化方法。
• 池化导致信息损失。想想最大池化的例子，n 个数字中我们只保留最大的，把余下的 n-1 完全舍弃了。

## tensorflow 实现

### 题目描述

H = height, W = width, D = depth

stride 的高和宽都是 2 (S)

image.png

### 实现

``````input = tf.placeholder(tf.float32, (None, 4, 4, 5))
filter_shape = [1, 2, 2, 1]
strides = [1, 2, 2, 1]