tensorflow点滴(1)

来源:互联网 发布:免费域名备案 编辑:程序博客网 时间:2024/06/05 22:22
tf.nn.max_pool中padding的2种形式'SAME','VALID'的差别
import tensorflow as tf
import numpy as np

a= np.random.randint(9,size=(1,9,9,1))
print(np.squeeze(a))
cons = tf.constant(value=a,dtype=tf.float32,shape=(1,9,9,1))
X = tf.nn.max_pool(cons, [1,2,2,1], [1,2,2,1], padding='SAME')
Y= tf.nn.max_pool(cons, [1,2,2,1], [1,2,2,1], padding='VALID')
with tf.Session() as sess:
    print('X is following:')
    print(np.squeeze(np.array(sess.run(X))))
    print('Y is following:')
    print(np.squeeze(np.array(sess.run(Y))))

输出结果:
[[4 2 6 1 6 1 2 7 2]
 [3 1 2 0 5 3 2 2 6]
 [4 4 2 4 5 8 8 4 6]
 [4 6 6 8 8 6 0 3 0]
 [4 0 8 1 8 3 8 8 0]
 [0 5 2 6 4 3 7 8 5]
 [6 6 6 4 5 6 0 8 2]
 [0 1 1 7 4 7 5 3 3]
 [6 0 1 4 5 8 3 5 7]]
X is following:
[[ 4.  6.  6.  7.  6.]
 [ 6.  8.  8.  8.  6.]
 [ 5.  8.  8.  8.  5.]
 [ 6.  7.  7.  8.  3.]
 [ 6.  4.  8.  5.  7.]]
Y is following:
[[ 4.  6.  6.  7.]
 [ 6.  8.  8.  8.]
 [ 5.  8.  8.  8.]
 [ 6.  7.  7.  8.]]

原创粉丝点击