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

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

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


当前回答

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.

其他回答

当stride为1时(卷积比池化更典型),我们可以想到以下区别:

“SAME”:输出大小与输入大小相同。这就要求滤镜窗口要在输入贴图外滑动,因此需要垫片。 "VALID":过滤器窗口保持在输入映射中的有效位置,因此输出大小缩小为filter_size - 1。没有填充。

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.

有三种填充选择:有效(无填充),相同(或一半),满。你可以在这里(Theano)找到解释: http://deeplearning.net/software/theano/tutorial/conv_arithmetic.html

有效或无填充:

有效填充不涉及零填充,因此它只覆盖有效输入,不包括人工生成的零。对于内核大小为k的步幅s=1,则输出长度为((输入长度)- (k-1))。

相同或半填充:

当s=1时,相同的填充使输出的大小与输入的大小相同。如果s=1,补零的个数为(k-1)。

完全填充:

完全填充意味着内核运行整个输入,因此在结束时,内核可能只满足一个输入,其他为零。如果s=1,填充的零的数量是2(k-1)。如果s=1,则输出长度为((输入长度)+ (k-1))。

因此,填充的数量:(有效)<=(相同)<=(满)

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

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

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

Tensorflow 2.0兼容答案:上面已经提供了关于“有效”和“相同”填充的详细解释。

但是,我将在Tensorflow 2中指定不同的池化函数和它们各自的命令。X(>= 2.0),为社区的利益。

1.x中的函数:

tf.nn.max_pool

tf.keras.layers.MaxPool2D

tf中平均池值=>无。神经网络,tf.keras.layers.AveragePooling2D

2.x中的函数:

tf.nn。Max_pool如果在2中使用。如果从1迁移,则tf. compat_v1 .nn.max_pool_v2或tf. compat_v2 .nn.max_pool。X到2。X。

tf.keras.layers。MaxPool2D如果在2中使用。x和

tf. compat_v1 .keras.layers. maxpooling2d或tf. compat_v1 .keras.layers. maxpooling2d或tf. compat_v2 .keras.layers. maxpooling2d或tf. compat_v2 .keras.layers. maxpooling2d,如果从1迁移。X到2。X。

平均池=> tf.nn。Avg_pool2d或tf.keras.layers。如果在TF 2中使用AveragePooling2D。x和

tf. compat_v1 . dn .avg_pool_v2或tf. compat_v2 .v2. dn .avg_pool或tf. compat_v1 .keras.layers. averagepooling2d或tf. compat_v1 .keras.layers. avgpool2d或tf. compat_v2 .keras.layers. averagepooling2d或tf. compat_v2 .keras.layers. avgpool2d,如果从1迁移。X到2。X。

有关Tensorflow迁移的更多信息。X到2。请参考本迁移指南。