The Image Dashboard section of the Tensorboard ReadMe says:
Since the image dashboard supports arbitrary pngs, you can use this to embed custom visualizations (e.g. matplotlib scatterplots) into TensorBoard.
I see how a pyplot image could be written to file, read back in as a tensor, and then used with tf.image_summary() to write it to TensorBoard, but this statement from the readme suggests there is a more direct way. Is there? If so, is there any further documentation and/or examples of how to do this efficiently?
It is quite easy to do if you have the image in a memory buffer. Below, I show an example, where a pyplot is saved to a buffer and then converted to a TF image representation which is then sent to an image summary.
This gives the following TensorBoard visualization:
Next script does not use intermediate RGB/PNG encoding. It also fixes the issue with additional operation construction during execution, single summary is reused.
Size of the figure is expected to remain the same during execution
Solution that works:
This intends to complete Andrzej Pronobis' answer. Following closely his nice post, I set up this minimal working example:
Where writer is an instance of tf.summary.FileWriter. This gave me the following error: AttributeError: 'Tensor' object has no attribute 'value' For which this github post had the solution: the summary has to be evaluated (converted into a string) before being added to the writer. So the working code for me remained as follows (simply add the .eval() call in the last line):
This could be short enough to be a comment on his answer, but these can be easily overlooked (and I may be doing something else different too), so here it is, hope it helps!
Cheers,
Andres
A bit late with my answer. With tf-matplotlib a simple scatter plot boils down to:
When executed, this results in the following plot inside Tensorboard
Note that tf-matplotlib takes care about evaluating any tensor inputs, avoids
pyplot
threading issues and supports blitting for runtime critical plotting.