2016-12-28 27 views
5

现在,我正在学习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]) 

我想用tensorboard显示散点图。 我知道“进口matplotlib.pyplot为PLT”能做到这一点。 但我可以使用控制台(腻子)。所以不能使用这种方法。

可我看到点图,如使用tensorboard散点图。

任何人都可以帮助我吗?

回答

0

不是一个真正的完整的答案,但我做的是对没有显示使用进口matplotlib:

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

然后画我的情节到缓冲区中,并保存为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 
相关问题