Skip to content

Instantly share code, notes, and snippets.

@randcode-generator
Created October 24, 2019 00:21
Show Gist options
  • Save randcode-generator/76fab40b9a708c28dad8b68dd4d81f65 to your computer and use it in GitHub Desktop.
Save randcode-generator/76fab40b9a708c28dad8b68dd4d81f65 to your computer and use it in GitHub Desktop.
import tensorflow as tf
k = tf.constant([
[0, 1, 2],
[1, 2, 3],
[2, 3, 4]
], dtype=tf.float32, name='k')
i = tf.constant([
[0, 1, 2, 3, 4],
[1, 2, 3, 4, 5],
[2, 3, 4, 5, 6],
[3, 4, 5, 6, 7],
[4, 5, 6, 7, 8]
], dtype=tf.float32, name='i')
kernel = tf.reshape(k, [3, 3, 1, 1], name='kernel')
image = tf.reshape(i, [1, 5, 5, 1], name='image')
res = tf.squeeze(tf.nn.conv2d(image, kernel, [1, 2, 2, 1], "SAME"))
with tf.Session() as sess:
print (sess.run(res))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment