问题
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