TensorBoard是一个可视化工具,它可以用来展示网络图、张量的指标变化、张量的分布情况等。
add_scalar()
from torch.utils.tensorboard import SummaryWriter
writer = SummaryWriter("log")
# y = x
for i in range(100):
writer.add_scalar("y=x", i, i)
writer.close()
add_image()
from torch.utils.tensorboard import SummaryWriter
import numpy as np
from PIL import Image
writer = SummaryWriter("log")
image_path = "数据集/dataset/train/ants_image/0013035.jpg"
img = Image.open(image_path)
img_array = np.array(img)
writer.add_image("test", img_array, 1, dataformats="HWC")
writer.close()
from PIL import Image
from torch.utils.tensorboard import SummaryWriter
from torchvision import transforms
image_path = "数据集/dataset/train/ants_image/0013035.jpg"
img = Image.open(image_path)
writer = SummaryWriter("log")
# 1、transforms该如何使用
tensor_trans = transforms.ToTensor()
tensor_img = tensor_trans(img)
writer.add_image("Tensor_img", tensor_img)
writer.close()