Created
March 9, 2017 15:21
-
-
Save koaning/641be8b98dc2ff02468969d10e0ec939 to your computer and use it in GitHub Desktop.
tensorflow starter
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 uuid | |
x = tf.Variable(tf.random_normal(shape=[1,1], mean=5, stddev=2)) | |
y = tf.sin(x) + tf.sin(x**2/2) - tf.abs(x) | |
optimizer = tf.train.RMSPropOptimizer(0.001).minimize(-y) | |
init = tf.global_variables_initializer() | |
tf.summary.scalar("x-val", tf.reduce_mean(x)) | |
tf.summary.scalar("y-val", tf.reduce_mean(y)) | |
merged_summary_op = tf.summary.merge_all() | |
with tf.Session() as sess: | |
sess.run(init) | |
uniq_id = "/tmp/tensorboard-gradient/" + uuid.uuid1().__str__()[:6] | |
summary_writer = tf.summary.FileWriter(uniq_id, graph=tf.get_default_graph()) | |
for step in range(3000): | |
_, val, summary = sess.run([optimizer, y, merged_summary_op]) | |
if step % 5 == 0: | |
print("step: {}, value: {}".format(step, val[0][0])) | |
summary_writer.add_summary(summary, step) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment