Pytorch 使用SummaryWriter记录日志信息

1. 向事件文件中写入事件和概要

import time
from torch.utils.tensorboard.writer import SummaryWriter

# 获取Tensorboard的writer
def tb_writer():
    timestr = time.strftime('%Y%m%d_%H')
    writer = SummaryWriter('../logs/' + timestr)
    return writer

if __name__ == "__main__":
    writer = tb_writer()
    start = time.time()
    writer.add_scalar('start_time: ', start)
    # 在summary中添加图片数据
    writer.add_image('X-Ray grid', grid, 0)
    writer.flush()
    writer.close()

输出日志信息如下:

Pytorch 使用SummaryWriter记录日志信息_第1张图片

2. 以上日志信息可通过tensor board来显示绘图

你可能感兴趣的:(pytorch,pytorch,tensorflow,人工智能)