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]))#
filters = tf.constant(filter_primes.reshape(1, 6, 1, 1)) #
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}))

转载于:https://www.cnblogs.com/hapyygril/p/10945183.html

你可能感兴趣的:(tf.nn.conv2d)