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

|▌冷眼眸甩不掉的悲伤 提交于 2020-08-05 05:39:21

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/51496619/tensorboard-how-to-write-images-to-get-a-steps-slider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!