The official way to visualize a TensorFlow graph is with TensorBoard, but sometimes I just want a quick look at the graph when I'm working in Jupyter.
Is there a quick solution, ideally based on TensorFlow tools, or standard SciPy packages (like matplotlib), but if necessary based on 3rd party libraries?
I wrote a simple helper which starts a tensorboard from the jupyter notebook. Just add this function somewhere at the top of your notebook
And then run it
TB()
whenever you generated your summaries. Instead of opening a graph in the same jupyter window, it:After you are done with exploration, just click the tab, and stop interrupt the kernel. If you want to cleanup your log directory, after the run, just run
TB(1)
Here's a recipe I copied from one of Alex Mordvintsev deep dream notebook at some point
Then to visualize current graph
If your graph is saved as pbtxt, you could do
You'll see something like this
I wrote a Jupyter extension for tensorboard integration. It can:
Github: https://github.com/lspvic/jupyter_tensorboard
Code
Usage
Starting a server does not block Jupyter (except for 2 seconds to ensure the server has the time to start before opening a tab). All TensorBoard servers will stop when you interrupt the kernel.
Advanced usage
If you want more control, you can kill the servers programmatically like this:
You can set
open_tab=False
if you don't want new tabs to open. You can also setsleep
to some other value if 2 seconds is too much or not enough on your system.If you prefer to pause Jupyter while TensorBoard is running, then you can call any server's
wait()
method. This will block Jupyter until you interrupt the kernel, which will stop this server and all the others.Prerequisites
This solution assumes you have installed TensorBoard (e.g., using
pip install tensorboard
) and that it is available in the environment you started Jupyter in.Acknowledgment
This answer was inspired by @SalvadorDali's answer. His solution is nice and simple, but I wanted to be able to start multiple tensorboard instances without blocking Jupyter. Also, I prefer not to delete log directories. Instead, I start tensorboard on the root log directory, and each TensorFlow run logs in a different subdirectory.
A Tensorboard / iframes free version of this visualization that admittedly gets cluttered quickly can
which can then be followed by
to render the graph as records in a static SVG file