how to make a scatter plots using tensorboard - tensorflow

5.5k views Asked by At

now, i'm studying tensorflow. but, i can't draw dot graph using tensorboard.

if i have sample data for training, like that

train_X = numpy.asarray([3.3, 4.4, 5.5, 6.71, 6.93, 4.168, 9.779])
train_Y = numpy.asarray([1.7, 2.76, 2.09, 3.19, 1.694, 1.573, 3.366])

i want to show scatter plots using tensorboard. i know "import matplotlib.pyplot as plt" can do that. but i can just use console (putty). so can't use this method.

can i see dot graph, like scatter plots using tensorboard.

can anyone help me?

1

There are 1 answers

3
fabian789 On

Not really a full answer, but what I do is import matplotlib for no display use:

import matplotlib as mpl
mpl.use('Agg')  # No display
import matplotlib.pyplot as plt

Then draw my plots into a buffer and save that as a PNG:

# setting up the necessary tensors:
plot_buf_ph = tf.placeholder(tf.string)
image = tf.image.decode_png(plot_buf_ph, channels=4)
image = tf.expand_dims(image, 0)  # make it batched
plot_image_summary = tf.summary.image('some_name', image, max_outputs=1)

# later, to make the plot:
plot_buf = get_plot_buf()
plot_image_summary_ = session.run(
        plot_image_summary,
        feed_dict={plot_buf_ph: plot_buf.getvalue()})
summary_writer.add_summary(plot_image_summary_, global_step=iteration)

where get_plot_buf is:

def get_plot_buf(self):
    plt.figure()

    # ... draw plot here ...

    buf = io.BytesIO()
    plt.savefig(buf, format='png')
    plt.close()

    buf.seek(0)
    return buf