1.SummarWriter类的使用
- add_image()函数,作用是添加image data到Summary
- add_scalar()函数,作用是将scalar data添加到Summary
2.TensorBoard三种安装方法
- 在teminal中pip install tensorboard
- 在Mac 终端conda install tensorboard
- 在anaconda 里下载安装
3.TensorBoard的使用
!!!默认浏览器要改成Google,safari不支持
tensorboard --logdir=logs,logs是事件文件所在的文件夹
tensorboard --logdir=logs – port=6007,指定端口
from torch.utils.tensorboard import SummaryWriter
import numpy as np
from PIL import Image
img_path = "/Users/songyuxi/PycharmProjects/pythonProject/hymenoptera_data/train/ants/0013035.jpg"
img_pil = Image.open(img_path) # 返回jpeg类型对象
img_nump = np.array(img_pil) # 将jpeg类型对象转换为numpy类型对象
writer = SummaryWriter(log_dir="logs") # 将日志文件写入logs文件夹
for i in range(100):
writer.add_scalar(tag="y=x^2", scalar_value=i*i, global_step=i)
writer.add_image(tag="test", img_tensor=img_nump, global_step=1, dataformats="hwc") # 默认是chw需要转换成hwc
writer.close()