TensorBoard:如何编写图像以获取步骤滑块?

时间:2018-07-24 10:43:42

标签: tensorflow keras visualization tensorboard autoencoder

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

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函数只是从一批图像中制作出一张图像)

运行代码时,我在TensorBoard中看到的是this screenshot。 图像分别以不同的名称写入,TensorBoard无法放置单个滑块以在图像之间切换。

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

1 个答案:

答案 0 :(得分:1)

图片必须具有相同的标签(不是我以前做的 name )。

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