关于tensorflow_conv2d_max_pool卷积池化padding参数为SAME和VALID的区别


直接上代码理解,作者觉得same会根据具体的步长和核大小去尽量遍历特征图,因为可以填充这个周边的范围。

import tensorflow as tf
graph = tf.Graph()
with graph.as_default():
    x = tf.constant([[1., 2., 3., 5.],
                 [4., 5., 6., 6.],
                 [1 , 2 , 3 , 4 ],
                 [6 , 5 , 8 , 9 ]])
    x = tf.reshape(x, [1, 4, 4, 1])
    valid_pad = tf.nn.max_pool(x, [1, 3, 3, 1], [1, 2, 2, 1], padding='VALID')
    same_pad = tf.nn.max_pool(x, [1, 3, 3, 1], [1, 2, 2, 1], padding='SAME')
with tf.Session(graph=graph) as sess:
    print(sess.run(valid_pad))

    print(sess.run(same_pad))

结果:


猜你喜欢

转载自blog.csdn.net/weili_/article/details/79971890