how to make a scatter plots using tensorboard - tensorflow

做~自己de王妃 提交于 2021-02-07 13:10:32

问题


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:


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


来源:https://stackoverflow.com/questions/41356093/how-to-make-a-scatter-plots-using-tensorboard-tensorflow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!