SummaryWriter的使用

from torch.utils.tensorboard import SummaryWriter
import numpy as np
from PIL import Image


writer = SummaryWriter('logs')
image_path = 'hymenoptera_data/train/ants/0013035.jpg'
image_PIL = Image.open(image_path)
image_array = np.array(image_PIL)
print(type(image_array))
print(image_array.shape)

#.add_image的输入格式必须为numpy.array 或者其他,所以用numpy读取,image_array.shape=(512, 768, 3),因此设置dataformats='HWC'
writer.add_image("test",image_array,1,dataformats='HWC')
# for i in range(100):
#     writer.add_scalar("x=y",i,i)
# writer.add_image()
# writer.add_scalar()

writer.close()

运行成功后,在控制台输入tensorboard --logdir=logs(=运行输出文件所在文件夹的名称)
tensorboard --logdir C:\tensorboardLog --host=127.0.0.1

 之后需要在同一个标题下看其余图片,只要修改=2

writer.add_image("test",image_array,2,dataformats='HWC')

或是新建一个Image查看的区域,修改名称即可

writer.add_image("val",image_array,2,dataformats='HWC')

你可能感兴趣的:(深度学习,python,pytorch)