Skip to content

Usage of tensorboardX

Piotr Tempczyk edited this page Feb 7, 2020 · 1 revision

TensorboardX is tensorboard based logger for PyTorch and not only. It can be used fo visualizing scalar values, images, text, etc.

Switching tensorboardX on

To switch tensorboardX on (after starting training) execute in the console:

tensorboard --logdir logs_folder_path

and then in the web browser type:

http://system_user_name:6006

logs_folder_path is set to "logs_" + str(int(time.time())) by default (look at SummaryWriter()).
system_user_name is user's name in the system. For instance, if your user's name is my_pc then use http://my_pc:6006.

Setting up your own tensorboardX

At the beginning, it is needed to create writer instance:

from tensorboardX import SummaryWriter
writer = SummaryWriter(logs_folder_path) 
# logs_folder_path argument can be ommited -> default name of the folder will be used

logs_folder_path is set to runs/CURRENT_DATETIME_HOSTNAME by default (in tensorboardX).

All methods that can be used for sending information to tensorboard have similar syntax writer.add_something(name, object, iteration_number), where:

  • name is the name of object/graph and can be used to group some graphs, for instance 'graphs_group/graph_name' will create a group graphs_group with plot graph_name,
  • object can be one of scalar value, tensor/array, figure, string,
  • iteration_number is used for x axis on the graphs.

Available methods:

  • add_scalar(name, scalar_value, iteration_number) logs scalars to tensorboard plot,
  • add_image(name, image_array, iteration_number) saves an image with shape (3, H, W) to tensorboard,
  • add_figure(name, matplotlib_figure, iteration_number) saves a matplotlib figure to tensorboard,
  • add_histogram(name, array, iteration_number) saves a histogram to tensorboard; NOTE: If training slows down after using this package, check this first,
  • add_graph(model, input_to_model) visualize model in tensorboard.

At the end, remember to close writer instance with close() method.

For more information see tensorboardX's GitHub or Read the Docs.

Clone this wiki locally