Reputation: 27994
Assuming I want a generic scatter plot drawn in TensorBoard that draws the 1st batch[:, 0], batch[:, 1]
of every epoch.
How can that be done in TensorBoard?
An old similar question (2017 january) has a workaround, but I hope we now (2020 december) have the technology for a real solution.
Not enough is my attempt:
if self._current_epoch == 0:
self.logger.experiment.add_scalars("epoch", {"batch": batch[:, 1]}, batch[:, 0])
Gives me the wonderful error
assert(scalar.squeeze().ndim == 0), 'scalar should be 0D'
Upvotes: 4
Views: 2955
Reputation: 144
If I understand your question right, you could use add_images
, add_figure
to add image or figure to tensorboard(docs).
Sample code:
from torch.utils.tensorboard import SummaryWriter
import numpy as np
import matplotlib.pyplot as plt
# create summary writer
writer = SummaryWriter('lightning_logs')
# write dummy image to tensorboard
img_batch = np.zeros((16, 3, 100, 100))
writer.add_images('my_image_batch', img_batch, 0)
# write dummy figure to tensorboard
plt.imshow(np.transpose(img_batch[0], [1, 2, 0]))
plt.title('example title')
writer.add_figure('my_figure_batch', plt.gcf(), 0)
writer.close()
Upvotes: 1