TensorBoard:如何编写图像以获得步骤滑块? [英] TensorBoard: How to write images to get a steps slider?
问题描述
我在带有 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?
推荐答案
图像必须具有相同的标签(不是我之前做的名称).
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屋!