现在,我正在研究张量流。
但是,我无法使用张量板绘制点图。
如果我有训练样本数据,就像那样
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])
我想使用张量板显示散点图。
我知道“import matplotlib.pyplot as plt”可以做到这一点。
但我只能使用控制台(腻子)。所以不能使用这个方法。
我可以看到点图,例如使用张量板的散点图吗?
谁能帮我?
并不是一个完整的答案,但我所做的是导入 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)
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)