如何使用张量板绘制散点图-TensorFlow

jae*_*hin 5 graph scatter-plot tensorflow tensorboard

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

如果我有用于训练的样本数据,像那样

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])
Run Code Online (Sandbox Code Playgroud)

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

我可以看到点图吗,例如使用张量板的散点图。

谁能帮我?

fab*_*789 5

不是一个完整的答案,但我所做的是导入 matplotlib 不用于显示:

import matplotlib as mpl
mpl.use('Agg')  # No display
import matplotlib.pyplot as plt
Run Code Online (Sandbox Code Playgroud)

然后将我的图绘制到缓冲区中并将其保存为 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)
Run Code Online (Sandbox Code Playgroud)

在哪里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
Run Code Online (Sandbox Code Playgroud)