TensorBoard

2.20.0 · active · verified Sun Mar 29

TensorBoard is a powerful visualization toolkit for machine learning experimentation, enabling tracking of metrics like loss and accuracy, visualization of model graphs, projection of embeddings, and much more. It is closely integrated with TensorFlow and PyTorch ecosystems, and its releases generally track TensorFlow versions. The current stable version is 2.20.0, and it is actively maintained with regular updates.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `SummaryWriter` from `torch.utils.tensorboard` to log scalar values, creating event files in a timestamped directory. After running the script, you can launch TensorBoard from your terminal to visualize the logged data.

import datetime
from torch.utils.tensorboard import SummaryWriter

log_dir = "runs/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
writer = SummaryWriter(log_dir)

# Log a scalar value
for i in range(100):
    writer.add_scalar('Loss/train', 100 / (i + 1), i)
    writer.add_scalar('Accuracy/train', i / 100, i)
writer.close()

print(f"TensorBoard logs saved to: {log_dir}")
print("To view, run in your terminal: tensorboard --logdir runs")

view raw JSON →