Created
January 19, 2017 00:46
-
-
Save domluna/3a273502ce452a955df425961478aa68 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], 'SAME') | |
s = tf.Session() | |
x = np.zeros((28, 28), dtype=np.float32) | |
x[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