tensorflow隨筆-tf.nn.conv2d
阿新 • • 發佈:2018-12-12
基於騰訊雲開發者實驗室
import tensorflow as tf
a = tf.constant([1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,1,1,0,0,1,1,0,0],dtype=tf.float32,shape=[1,5,5,1])
b = tf.constant([1,0,1,0,1,0,1,0,1],dtype=tf.float32,shape=[3,3,1,1])
c = tf.nn.conv2d(a,b,strides=[1, 2, 2, 1],padding='VALID')
d = tf.nn.conv2d(a,b,strides=[1, 2, 2, 1],padding= 'SAME')
with tf.Session() as sess:
print ("c shape:")
print (c.shape)
print ("c value:")
print (sess.run(c))
print ("d shape:")
print (d.shape)
print ("d value:")
print (sess.run(d))
conv2d( input, filter, strides, padding, use_cudnn_on_gpu=True, data_format=‘NHWC’, name=None )
c shape:
(1, 2, 2, 1)
c value:
[[[[ 4.]
[ 4.]]
[[ 2.]
[ 4.]]]]
d shape:
(1, 3, 3, 1)
d value:
[[[[ 2.]
[ 3.]
[ 1.]]
[[ 1.]
[ 4.]
[ 3.]]
[[ 0.]
[ 2.]
[ 1.]]]]