在tf.nn中“SAME”和“VALID”填充之间的区别是什么?tensorflow的Max_pool ?

在我看来,'VALID'意味着当我们做max pool时,边缘外不会有零填充。

根据深度学习卷积算法指南,它说池操作符中不会有填充,即只使用tensorflow的“VALID”。 但什么是'SAME'填充的最大池张量流量?


当前回答

这里W和H是输入的宽和高, F为滤波器维数, P是填充大小(即要填充的行数或列数)

对于相同的填充:

对于有效填充:

其他回答

Padding on/off. Determines the effective size of your input. VALID: No padding. Convolution etc. ops are only performed at locations that are "valid", i.e. not too close to the borders of your tensor. With a kernel of 3x3 and image of 10x10, you would be performing convolution on the 8x8 area inside the borders. SAME: Padding is provided. Whenever your operation references a neighborhood (no matter how big), zero values are provided when that neighborhood extends outside the original tensor to allow that operation to work also on border values. With a kernel of 3x3 and image of 10x10, you would be performing convolution on the full 10x10 area.

有效填充是没有填充。 相同的填充在某种程度上是输出与输入大小相同的填充。

TensorFlow Convolution的例子概述了SAME和VALID的区别:

对于相同的填充,输出的高度和宽度计算如下: Out_height = ceil(float(in_height) / float(strides[1])) Out_width = ceil(float(in_width) / float(strides[2]))

And

对于VALID填充,输出高度和宽度的计算如下: Out_height = ceil(float(in_height - filter_height + 1) / float(strides[1])) Out_width = ceil(float(in_width - filter_width + 1) / float(strides[2]))

如果你喜欢ascii艺术:

"VALID" = without padding: inputs: 1 2 3 4 5 6 7 8 9 10 11 (12 13) |________________| dropped |_________________| "SAME" = with zero padding: pad| |pad inputs: 0 |1 2 3 4 5 6 7 8 9 10 11 12 13|0 0 |________________| |_________________| |________________|

在这个例子中:

输入宽度= 13 滤镜宽度= 6 步幅= 5

注:

"VALID"只删除最右边的列(或最底部的行)。 “SAME”尝试均匀地左右填充,但如果要添加的列的数量是奇数,它会将额外的列添加到右侧,就像本例中的情况一样(垂直方向上的逻辑相同:底部可能有额外的一行零)。

编辑:

关于名字:

对于“SAME”填充,如果你使用的步幅为1,该层的输出将具有与其输入相同的空间维度。 使用“VALID”填充,就没有“编造”填充输入。该层只使用有效的输入数据。

总之,“有效”填充意味着没有填充。卷积层的输出大小根据输入大小和内核大小而缩小。

相反,“相同”填充意味着使用填充。当stride设置为1时,卷积层的输出大小保持为输入大小,在计算卷积时在输入数据周围附加一定数量的“0-border”。

希望这个直观的描述能有所帮助。