Tensorboard(二)

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

img_path = r'D:\Pytorch\hymenoptera_data\train\bees\16838648_415acd9e3f.jpg'
img_PIL = Image.open(img_path)
print(type(img_PIL))
img_arry = np.array(img_PIL)
print(img_arry.shape) # (512, 768, 3)

writer = SummaryWriter('logs')

writer.add_image('test', img_arry, -1, dataformats='HWC') # 高度 宽度 通道
#y = x
for i in range(100):
    writer.add_scalar('y = 2x', 2*i, i)

writer.close()

在这里插入图片描述

 tensorboard --logdir=pythonProject/Tensorboard/logs --port=6007

在这里插入图片描述