前言
tensorboard可以对很多数据等进行可视化,比如Scalar(s)/ image(s)/ histogram/ figure/ video/ audio/ text/ graph/ PR/ mash等等。
1. 模块导入
from torch.utils.tensorboard import SummaryWriter # default `log_dir` is "runs" - we'll be more specific here writer = SummaryWriter('runs/fashion_mnist_experiment_1')
创建一个保存可视化文件 runs/fashion_mnist_experiment_1的文件夹,默认是runs;
2. 写入tensorboard
writer.add_scalar('Loss/train', np.random.random(), n_iter) writer.add_image('images', grid, 0) writer.add_graph(model, images)
有多中类型的数据可以写入,具体的可查看官网示例;
3. 关闭和查看tensorboard
writer.close()
查看
tensorboard --logdir=runs
打开本地的链接即可查看。包含多个模块IMAGES、SCALES、GRAPHS、PROJECTOR;
参考
1. 使用 TensorBoard 可视化模型,数据和训练;
完