How to use TensorBoard in TensorFlow

This post explains how to use TensorBoard in TensorFlow.TensorBoard is a tool for providing measurements and visualizations needed during the machine learning workflow. In this tutorial you will learn how to use TensorBoard in Jupyter notebook and in browser.

In this example we will use tf.summary module to write summary data and TensorBoard to visualize this data.

Using TensorBoard in Jupyter notebooks and browsers

1. Import required modules

   
import tensorflow as tf
import random
   

2. Create summary data using tf.summary.scaler

   
writer = tf.summary.create_file_writer("logsDir/logs")
with writer.as_default():
  for step in range(1000):    
    tf.summary.scalar("metric", random.uniform(0,1), step=step)
    writer.flush()
   

Above code snippet writes summary to the files in logs folder inside logsDir.

3.1 View the summary in TensorBoard in Jupyter notebook

 
%load_ext tensorboard 
%tensorboard --logdir logsDir/logs
 

3.2 View the summary in TensorBoard in browser

Run below command in terminal and navigate to http://localhost:6006/ for visualizing metric data.

 
tensorboard --logdir logsDir/logs  
 

Category: TensorFlow