了解 Tensorflow 最大池化

Understanding Tensorflow maxpooling

我无法理解为什么使用我的参数进行 tensorflow maxpooling。

当使用 ksize=2strides=2 执行 maxpool 时,我得到以下带有 padding SAMEpadding VALID

的输出
input :  (?, 28, 28, 1)
conv2d_out :  (?, 28, 28, 32)
maxpool2d_out :  (?, 14, 14, 32)

但是当我尝试使用 ksize=3strides=1 执行 maxpool 时,我得到以下输出:

input :  (?, 28, 28, 1)
conv2d_out :  (?, 28, 28, 32)
maxpool2d_out :  (?, 28, 28, 32) PADDING SAME
maxpool2d_out :  (?, 26, 26, 32) PADDING VALID

maxpool with ksize=2 and strides=2 using padding SAME 应该产生输出 maxpool2d_out : (?, 28, 28, 32)

关于带填充的最大池化的工作原理,我是否遗漏了什么?

**CODE**==python_

您正在使用 padding='SAME',这意味着您的输出将用零填充以具有与输入相同的大小。

如果您将 padding 更改为 VALID,则输出不会用零填充,合并操作将按您预期的方式工作。

我在你的代码中看到你使用 padding=SAME。使用 SAME 填充和 strides=1 时,输入和输出大小相同。为什么你认为tensorflow的实现是错误的?

更新: 根据 tensorflow documentation

使用相同的填充

out_height = ceil(float(in_height) / float(strides[1]))
out_width  = ceil(float(in_width) / float(strides[2]))
  • k=3,stride=1时为28/1=28
  • k=2,stride=2时为28/2=14

使用有效填充

out_height = ceil(float(in_height - filter_height + 1) / float(strides[1]))
out_width  = ceil(float(in_width - filter_width + 1) / float(strides[2]))
  • 当k=3时celing((28-3+1)/1)=26,stride=1

  • k=2时是ceiling((28-2+1)/2)=14,stride=2

可以看到,因为有ceiling函数,所以使用不同的PADDING配置,你的结果恰好是一样的