我正在尝试制作能够显示我的matplotlib数字的代码。当我运行下面的代码时,它会生成一个事件文件,但是当我运行tensorboard并将logdir指向我得到的文件夹时
No image data was found.
示例代码:
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import tensorflow as tf
import io
class bla():
def __init__(self, sess):
self.sess = sess
class Dummy():
def __init__(self, sess):
self.fill_scheme = {
'adv': np.linspace(0, 20),
'butt': np.linspace(0, 20) * -1
}
self.model = bla(sess)
def test(self, name=100):
checker = hasattr(self.model, 'sess')
writer = tf.summary.FileWriter('./im_data', graph=None if not checker else self.model.sess.graph)
summary = tf.Summary()
for k, v in self.fill_scheme.items():
plt.figure()
plt.plot(v)
s = io.BytesIO()
plt.savefig(s)
plt.clf()
img_summary = tf.Summary.Image(encoded_image_string=s.getvalue())
summary.value.add(tag='im/it_{}_{}'.format(name, k), image=img_summary)
writer.add_summary(summary, name)
plt.close()
writer.close()
sess = tf.InteractiveSession()
a = Dummy(sess)
a.test()
这对我没有错误,所以我不确定出了什么问题?