Skip to content Skip to sidebar Skip to footer

Getting A Simple Plot In Tensorboard

I'm trying to a simple plot on tensorboard, just like they have it on homepage, something like this: To understand how this is working I've wrote the following : import tenso

Solution 1:

So right off the bat, I want to suggest reading this. It goes a little more in detail what a session is.

As to the code and why it doesn't produce results: you're not initializing the variables. You can do this with: sess.run(tf.global_variables_initializer()). So your code would be:

import tensorflow as tf
import numpy as np

x = tf.placeholder('float',name='X')
y=  tf.placeholder('float',name='y')
addition = tf.add(x,y)

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    for i inrange(100):
        var1=  np.random.rand()
        var2=  np.random.rand()
        print(var1,var2)
        tf.summary.scalar('addition',sess.run(addition, feed_dict={x:var1,y:var2}))               
        writer = tf.summary.FileWriter('Graphs',sess.graph)

I wouldn't embed sess.run into the summary.scalar call, but for this simple example, you'll get some results.

Edit: tested and this is actually working:

import tensorflow as tf
import numpy as np

x = tf.placeholder('float',name='X')
y=  tf.placeholder('float',name='y')
addition = tf.add(x,y, name='add')
tf.summary.scalar('addition', addition)
summary_op = tf.summary.merge_all()     
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    writer = tf.summary.FileWriter('Graphs',sess.graph)
    for i inrange(100):
        var1=  np.random.rand()
        var2=  np.random.rand()
        print(var1,var2)
        add, s_ = sess.run([addition, summary_op], feed_dict={x:var1,y:var2})
        writer.add_summary(s_, i)

output: enter image description here

Post a Comment for "Getting A Simple Plot In Tensorboard"