如何使用张量板绘制散点图-TensorFlow [英] how to make a scatter plots using tensorboard - tensorflow

查看:109
本文介绍了如何使用张量板绘制散点图-TensorFlow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我正在研究tensorflow.但是,我无法使用张量板绘制点图.

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])

我想使用张量板显示散点图.我知道将matplotlib.pyplot导入为plt"可以做到这一点.但我只能使用控制台(putty).所以不能使用这种方法.

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.

有人可以帮助我吗?

推荐答案

不是一个完整的答案,但是我要做的是导入matplotlib而不用于任何显示用途:

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

然后将我的绘图绘制到缓冲区中并将其另存为PNG:

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)

其中 get_plot_buf 是:

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

这篇关于如何使用张量板绘制散点图-TensorFlow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆