Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorBoard: How to write images to get a steps slider?

I'm using keras in my ML project with the TensorBoard callback. I have an image autoencoder and I want to visualize its progress in reconstructing some images. So I sub-classed the TensorBoard class as such:

class Monitor(TensorBoard):
    def on_train_begin(self, logs=None):
        super().on_train_begin(logs)
    def on_epoch_begin(self, epoch, logs=None):

        # 1. Get the reconstructed images
        reconstructions = Autoencoder.predict(validation[0])

        # 2. Generate a summary
        summary = tf.summary.image('reconstructions', expand_dims(gallery(reconstructions), axis=0), family='reconstructions')

        # 3. Add the summary with `epoch` as the step
        self.writer.add_summary(summary.eval(), epoch)

        super().on_epoch_begin(epoch, logs)

(the gallery function simply makes a single image from a batch of images)

What I'm seeing in TensorBoard when running the code is this screenshot. The images are written each with a different name, and TensorBoard is not able to put a single slider to switch between them.

How can I write image summaries so that TensorBoard gives me a slider to choose different steps?

like image 790
matan tsuberi Avatar asked Aug 31 '25 16:08

matan tsuberi


1 Answers

The image must have the same tag (Not name, which I was doing before).

plt.figure(figsize=(5,5))
plt.plot([0, 1], [0, 1], "k:", label="Perfectly calibrated")
plt.plot(mean_predicted_values, fraction_of_positives)
reliability_image = io.BytesIO()
plt.savefig(reliability_image, format='png')
reliability_image = tf.Summary.Image(encoded_image_string=reliability_image.getvalue(),
                                   height=7,
                                   width=7)
summary = tf.Summary(value=[tf.Summary.Value(tag="Reliability", 
image=reliability_image)])

writer_train.add_summary(summary, global_step=epoch)

enter image description here

like image 85
Andrew Lim Avatar answered Sep 04 '25 09:09

Andrew Lim