[英]How to draw a scatter plot in Tensorboard Pytorch?
Assuming I want a generic scatter plot drawn in TensorBoard that draws the 1st batch[:, 0], batch[:, 1]
of every epoch.假设我想要一个在 TensorBoard 中绘制的通用散点图 plot ,该散点图绘制每个时期的第
batch[:, 0], batch[:, 1]
。
How can that be done in TensorBoard?如何在 TensorBoard 中做到这一点?
An old similar question (2017 january) has a workaround, but I hope we now (2020 december) have the technology for a real solution. 一个类似的老问题(2017 年 1 月)有一个解决方法,但我希望我们现在(2020 年 12 月)拥有真正解决方案的技术。
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'
assert(scalar.squeeze().ndim == 0), '标量应该是 0D'
If I understand your question right, you could use add_images
, add_figure
to add image or figure to tensorboard( docs ).如果我正确理解您的问题,您可以使用
add_images
、 add_figure
将图像或图形添加到张量板( 文档)。
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.