tensorflow 中 VALID 和 SAME

import tensorflow as tf
inp = tf.Variable(tf.random_normal([1,5,5,5]))  
fil = tf.Variable(tf.random_normal([3,3,5,2]))  
op = tf.nn.conv2d(inp, fil, strides=[1, 2, 2, 1], padding='VALID') 
op1 = tf.nn.conv2d(inp, fil, strides=[1, 2, 2, 1], padding='SAME')
init=tf.initialize_all_variables()
sess=tf.Session()
sess.run(init)
#输出   
print('VALID',sess.run(op)) 
print('VALID',op.get_shape())  


print('SAME',sess.run(op1)) 
print('SAME',op1.get_shape()) 
VALID [[[[ -0.77382743  -2.91836953]
   [  6.77092981  -1.72546279]]

  [[ 15.70966816   1.29167044]
   [  5.8997016    6.84991693]]]]
VALID (1, 2, 2, 2)
SAME [[[[ -1.47027338   3.62595987]
   [ -3.12284327 -10.06939793]
   [  2.21386075  -1.36730778]]

  [[  6.03762341   2.28263664]
   [ -1.14067996  -0.3973445 ]
   [ -4.22067022   1.80184615]]

  [[ -4.60390282   0.11502526]
   [ -7.50191736   1.31101084]
   [  1.35902023   4.87215185]]]]
SAME (1, 3, 3, 2)
posted @ 2022-08-19 22:58  luoganttcc  阅读(0)  评论(0编辑  收藏  举报