Created
February 27, 2017 15:53
-
-
Save phreeza/f8210e50ef54598f433732e4f69a42aa 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 | |
node1 = tf.constant(3.0, tf.float32) | |
node2 = tf.constant(4.0) # also tf.float32 implicitly | |
with tf.Session() as sess: | |
W = tf.Variable([.3], tf.float32, name='W') | |
b = tf.Variable([-.3], tf.float32, name='b') | |
x = tf.placeholder(tf.float32, name='x') | |
with tf.name_scope("LinearModel"): | |
y = W * x + b | |
f = tf.sin(y,name='f') | |
init = tf.global_variables_initializer() | |
sess.run(init) | |
print sess.run(y, {x:[1,2,3,4]}) | |
with tf.name_scope("Updates"): | |
fixW = tf.assign(W, [-1.]) | |
fixb = tf.assign(b, [1.]) | |
sess.run([fixW, fixb]) | |
print "After transform" | |
print sess.run(y, {x:[1,2,3,4]}) | |
grad_f = tf.gradients(f,x,name='dfdx') | |
grad_y = tf.gradients(y,x,name='dydx') | |
print "Gradients" | |
ret = sess.run([grad_f,grad_y], {x:[1,2,3,4]}) | |
print "df/dx: ",ret[0][0] | |
print "dy/dx: ",ret[1][0] | |
summary_writer = tf.summary.FileWriter('logs', | |
sess.graph) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment