Path: blob/master/site/en-snapshot/tensorboard/tensorboard_in_notebooks.ipynb
25115 views
Copyright 2019 The TensorFlow Authors.
Using TensorBoard in Notebooks
Setup
Start by installing TF 2.0 and loading the TensorBoard notebook extension:
For Jupyter users: If you’ve installed Jupyter and TensorBoard into the same virtualenv, then you should be good to go. If you’re using a more complicated setup, like a global Jupyter installation and kernels for different Conda/virtualenv environments, then you must ensure that the tensorboard
binary is on your PATH
inside the Jupyter notebook context. One way to do this is to modify the kernel_spec
to prepend the environment’s bin
directory to PATH
, as described here.
For Docker users: In case you are running a Docker image of Jupyter Notebook server using TensorFlow's nightly, it is necessary to expose not only the notebook's port, but the TensorBoard's port. Thus, run the container with the following command:
where the -p 6006
is the default port of TensorBoard. This will allocate a port for you to run one TensorBoard instance. To have concurrent instances, it is necessary to allocate more ports. Also, pass --bind_all
to %tensorboard
to expose the port outside the container.
Import TensorFlow, datetime, and os:
TensorBoard in notebooks
Download the FashionMNIST dataset and scale it:
Create a very simple model:
Train the model using Keras and the TensorBoard callback:
Start TensorBoard within the notebook using magics:
You can now view dashboards such as Time Series, Graphs, Distributions, and others. Some dashboards are not available yet in Colab (such as the profile plugin).
The %tensorboard
magic has exactly the same format as the TensorBoard command line invocation, but with a %
-sign in front of it.
You can also start TensorBoard before training to monitor it in progress:
The same TensorBoard backend is reused by issuing the same command. If a different logs directory was chosen, a new instance of TensorBoard would be opened. Ports are managed automatically.
Start training a new model and watch TensorBoard update automatically every 30 seconds or refresh it with the button on the top right:
You can use the tensorboard.notebook
APIs for a bit more control: