TensorBoard:如何编写图像以获取步骤滑块? [英] TensorBoard: How to write images to get a steps slider?

查看:176
本文介绍了TensorBoard:如何编写图像以获取步骤滑块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在带有TensorBoard回调的ML项目中使用了keras.我有一个图像自动编码器,我想可视化其在重建某些图像时的进度.因此,我将TensorBoard类归为此类:

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)

(gallery函数只是从一批图像中制作出一张图像)

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

运行代码时,我在TensorBoard中看到的是此屏幕截图. 图像分别以不同的名称写入,并且TensorBoard无法放置单个滑块以在图像之间进行切换.

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.

如何编写图像摘要,以便TensorBoard给我一个滑块以选择不同的步骤?

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

推荐答案

图片必须具有相同的标签(不是我以前做过的 name )./p>

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)

在此处输入图片描述

这篇关于TensorBoard:如何编写图像以获取步骤滑块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆