from torch.utils.tensorboard import SummaryWriter # Create a SummaryWriter writer = SummaryWriter() # Write some scalar values writer.add_scalar('loss/train', 0.1, 1) writer.add_scalar('loss/train', 0.2, 2) writer.add_scalar('loss/train', 0.1, 3) # Flush data to disk writer.flush() # Close the SummaryWriter writer.close()
from torch.utils.tensorboard import SummaryWriter import numpy as np # Create a SummaryWriter writer = SummaryWriter() # Generate some example data data = np.random.normal(loc=0, scale=1, size=(100,)) # Write a histogram of the data writer.add_histogram('data/histogram', data, 0) # Flush data to disk writer.flush() # Close the SummaryWriter writer.close()In this example, we create a SummaryWriter and use it to write a histogram of some example data to a log directory. We then use `flush` to write the data to disk and close the SummaryWriter. Package library: PyTorch.