2016-12-28 26 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 
相關問題