IanQ
IanQ

Reputation: 2129

Tensorflow FileWriter not writing(No image data was found)

I'm trying to make code that will display my matplotlib figures. When I run the below code it produces an events file, however when I run tensorboard and point the logdir to the folder I get

No image data was found.

Sample code:

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()

It's not error-ing out at me so I'm not really sure what's going wrong?

Upvotes: 0

Views: 548

Answers (1)

Nemorior
Nemorior

Reputation: 111

Which TF and Tensorboard version are you using? When I run your code everything seems to be working fine (TF 1.8, Tensorboard 1.7.0).

with "tensorboard --logdir im_data/" I get the following: enter image description here

Upvotes: 1

Related Questions