tf.nn.conv2d

import numpy as np
filter_primes = np.array([2., 3., 5., 7., 11., 13.], dtype=np.float32)
x = tf.constant(np.arange(1, 13+1, dtype=np.float32).reshape([1, 1, 13, 1]))
filters = tf.constant(filter_primes.reshape(1, 6, 1, 1))

valid_conv = tf.nn.conv2d(x, filters, strides=[1, 1, 5, 1], padding='VALID')
same_conv = tf.nn.conv2d(x, filters, strides=[1, 1, 5, 1], padding='SAME')

with tf.Session() as sess:
       print("VALID:\n", valid_conv.eval())
       print("SAME:\n", same_conv.eval())

 

 

 

import numpy as np
filter_primes = np.array([2., 3., 5., 7., 11., 13.], dtype=np.float32)
x = tf.constant(np.arange(1, 13+1, dtype=np.float32).reshape([1, 1, 13, 1]))#<class 'tensorflow.python.framework.ops.Tensor'>
filters = tf.constant(filter_primes.reshape(1, 6, 1, 1)) #<class 'tensorflow.python.framework.ops.Tensor'>
print(type(x))
print(type(filters))

valid_conv = tf.nn.conv2d(x, filters, strides=[1, 1, 5, 1], padding='VALID')
same_conv = tf.nn.conv2d(x, filters, strides=[1, 1, 5, 1], padding='SAME')


with tf.Session() as sess:
       print("VALID:\n", valid_conv.eval())
       print("SAME:\n", same_conv.eval())

 

 

import tensorflow as tf

a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
c = a + b

with tf.Session() as sess:
       print(c.eval(feed_dict={a:1.0,b:3.3}))

posted on 2019-05-29 17:36  happygril3  阅读(143)  评论(0编辑  收藏  举报

导航