Tensorboard使用
实例:读取函数
from torch.utils.tensorboard import SummaryWriter
writer = SummaryWriter("logs")#初始化一个logs文件夹
for i in range(100):
writer.add_scalar("y=x*x",3*i,i)#函数y=x^2,设置相应参数
writer.close()
打开conda,先激活pytorch环境:conda activate pytorch
接着运行:tensorboard --logdir=logs --port
最后根据得到的网址,在chrome里面打开。
实例:读取图像
from torch.utils.tensorboard import SummaryWriter
import numpy as np
from PIL import Image
writer = SummaryWriter("logs")
image_path = "dataset/train/bees_image/16838648_415acd9e3f.jpg"
img_PIL = Image.open(image_path)
img_array = np.array(img_PIL)
writer.add_image("test",img_array,1,dataformats='HWC')
writer.close()
以下步骤同上实例: