我在带有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
为我提供一个选择不同步骤的滑块?
答案 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)