from torch.utils.tensorboard import SummaryWriter

writer=SummaryWriter('Practice')#生成文件更改为在当前目录新建Practice文件夹中

for i in range(100):
writer.add_scalar('y=2x',2*i,i)

writer.close()

第二个:

from torch.utils.tensorboard import SummaryWriter

writer=SummaryWriter('Practice')

for i in range(100):
writer.add_scalar('y=2x',3*i,i)#注意此处会为3*i,但是tag依然是y=2x

writer.close()

#writer.add_scalar('y=2x',3*i,i)#注意此处会为3*i,但是tag依然是y=2x会导致生成的图像为了让tag同名的两次图像连接起来,而强行转弯,如下图所示。如下图1所示。


tensorboard_当前目录

 

解决上图1中问题,应该把tag改变,或者把原生成的文件全部删除后,重新在运行生成新的,并改变tag。如上图2,3.

以上为,writer.



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

writer=SummaryWriter('Practice')
img_path="PracticeDataset/train/bees_image/154600396_53e1252e52.jpg"
img_PIL=Image.open(img_path)
img_array=np.array(img_PIL)
print(type(img_array),img_array.shape,sep='\n')
writer.add_image('te',img_array,1,dataformats='HWC')#次数为numpy array,
所以调整一下datafomats为'HWC',默认为'CHW'.另,writer.add_image中的1,表示tensorboard的同一个窗口中,从左划到右的图片的显示顺序。