当前位置:网站首页>使用Tenserboard可视化深度学习训练过程
使用Tenserboard可视化深度学习训练过程
2022-07-29 11:31:00 【GIS与Climate】
在深度学习训练的过程中,如果能够可视化一些过程的变化,比如loss的变化过程等,将会对模型的性能表现有更加清晰的认识。
目前, 最常用的深度学习训练过程可视化工具是tensorboard,这个是tensorflow配套的可视化工具,但是Pytorch目前也支持该工具。
下面讲下如何使用该工具来进行训练过程的可视化。
安装
一般来讲如果配置好了Pytorch的深度学习环境,直接用pip安装即可:
pip install tensorboard
使用
总得来说tensorboard的使用过程包括三个步骤:
创建log文件夹 将数据写入log文件中 使用tensorboard可视化
示例代码:
from torch.utils.tensorboard import SummaryWriter
writer = SummaryWriter(comment='test plot')
for x in range(1000):
writer.add_scalar('y=3x^2+5',3*x**2+5,x)
首先实例化一个SummaryWriter的类,comment参数是默认生成的log文件的后缀,刚开始学可以不管,直接全部用默认的即可:
writer = SummaryWriter()
上面的命令会在当前文件夹下生成一个runs文件夹,用于存在后面的log文件。
然后就很简单了,通过writer.add_scalar函数把需要可视化的数据写入log文件即可。
第一个参数文件是绘图的名称; 第二个参数是y轴的值; 第三个参数是x轴的值。
然后在命令行中输入如下命令:
tensorboard --logdir=runs
根据提示信息打开浏览器即可看到如下界面:

右边就是我们绘制的图像了。在实际应用过程中便可以展示相应的信息,比如随着epoch数的增加,loss的下降过程。
补充
tensorboard不仅可以可视化标量,还可以对图像等数据进行可视化,可以自己查看官网文档,对应的就是把 add_scalar函数替换为相应的函数并设置好参数即可;可视化之后还可以把数据下载为csv等文件,把绘图结果保存为svg格式;

参考
【1】https://pytorch.org/docs/stable/tensorboard.html
边栏推荐
- Building and sharing the root of the digital world: Alibaba Cloud builds a comprehensive cloud-native open source ecosystem
- Golang realizes file upload and download
- DNS协议、ICMP协议、NAT技术
- Self collection online computer wallpaper PHP source code v2.0 adaptive end
- Summer vacation training week1
- 如何使用“COPY –link”加速 Docker 构建和优化缓存
- One click blog building: how to use WordPress plug-in to build a dedicated blog
- 自采集在线电脑壁纸php源码v2.0自适应端
- 大伟 Golang之路
- How to use grep to find pattern matching across multiple lines
猜你喜欢

ES6 arrow function this points to

Peking University open classes are coming! Welcome to the "AI for science" class

Based on the flask to write a small shopping mall project

Watch the open source summit first | quick view of the sub Forum & Activity agenda on July 29

Building and sharing the root of the digital world: Alibaba Cloud builds a comprehensive cloud-native open source ecosystem

DOD and Dor, two artifacts to reduce "cognitive bias"

考完PMP后有什么益处

为什么应该在开发环境中使用 Kubernetes

【图像处理】基于中轴变换实现图像骨架提取附matlab代码

How to use grep to find pattern matching across multiple lines
随机推荐
"Knowledge Collection" article to understand mysql index!!(recommended collection)
Based on the flask to write a small shopping mall project
浅谈string中的compareTo方法
Learn weekly - 64 - a v2ex style source BBS program
Deep understanding of c # delegate into the fast lanes
『知识集锦』一文搞懂mysql索引!!(建议收藏)
深入理解C# 可空类型
ECCV 2022 | ssp: a new idea of small sample tasks with self-supporting matching
2.安装MySQL
Package delivery (greedy)
std::vector 拷贝、追加、嵌套访问
Pyqt5 rapid development and practice 6.6 qformlayout & 6.7 nested layout & 6.8 qsplitter
MySQL高级_视图
KRYSTAL:审计数据中基于知识图的战术攻击发现框架
LeetCode_ 416_ Divide equal sum subsets
[image detection] Research on cumulative weighted edge detection method based on gray image, with matlab code
c语言:来实现一个小程序n子棋(已五子棋为例)
精通音视频开发是真的可以为所欲为
Spark efficient data analysis 01. Establishment of idea development environment
8. Interleave - understand ThreadPoolExecutor thread pool from architecture design to practice