Created
January 19, 2017 00:43
-
-
Save domluna/8808192b38194f2b210ec3d6459824bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import numpy as np | |
w = np.arange(1, 10, dtype=np.float32).reshape((3,3,1,1)) | |
f = tf.Variable(tf.constant(w)) | |
input = tf.placeholder(tf.float32, (None, 28, 28, 1)) | |
conv = tf.nn.conv2d(input, f, [1,2,2,1], 'VALID') | |
s = tf.Session() | |
x = np.zeros((28, 28), dtype=np.float32) | |
# rightmost 3x3 block | |
x[0:3, 25:28] = 1.0 | |
# leftmost 3x3 block | |
x[0:3, 0:3] = 1.0 | |
s.run(tf.global_variables_initializer()) | |
out = s.run(conv, {input: x.reshape((1,28,28,1))}) | |
print(w.reshape((3,3))) | |
print(x.reshape((28, 28))[:3, :]) | |
print(out.shape) | |
nh, nw = out.shape[1], out.shape[2] | |
print(out.reshape((nh,nw))[0, :]) | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment