当前位置:网站首页>TensorBoard快速入门(Pytorch使用TensorBoard)
TensorBoard快速入门(Pytorch使用TensorBoard)
2022-07-03 17:17:00 【iioSnail】
文章目录
TensorBoard 简介
TensorBoard 是Google开发的一个机器学习可视化工具。其主要用于记录机器学习过程,例如:
- 记录损失变化、准确率变化等
- 记录图片变化、语音变化、文本变化等,例如在做GAN时,可以过一段时间记录一张生成的图片
- 绘制模型
具体支持的内容可以参考官方文档
TensorBoard 界面介绍
TensorBoard 安装
直接使用pip安装即可:
pip install tensorboard
安装后,在命令行输入:
tensorboard --help
若可以正常输出,则说明安装成功。
TensorBoard 运行
运行启动命令即可:
tensorboard --logdir my_log
my_log
是TensorBoard的log文件所在的目录。Tensorboard面板中展示的数据都来源于log文件,一般一次完整的运行生成一份log文件。
例如,在Pytorch中,我们会调用new一个SummaryWriter
对象,此时就会创建一个log文件,之后我们就会调用其add_something
方法,往log里面写日志,之后在TensorBoard面板中就可以看到数据了。最后在训练完成后,调用close
方法结束。
若看到了如下输出,说明启动成功:
TensorBoard 2.8.0 at http://localhost:6006/ (Press CTRL+C to quit)
此时只需要在浏览器中输入http://localhost:6006/
即可进入TensorBoard界面。
Pytorch 使用 TensorBoard
Pytorch使用Tensorboard主要用到了三个API:
SummaryWriter
:这个用来创建一个log文件,TensorBoard面板查看时,也是需要选择查看那个log文件。add_something
: 向log文件里面增添数据。例如可以通过add_scalar
增添折线图数据,add_image
可以增添图片。close
:当训练结束后,我们可以通过close
方法结束log写入。
接下来,我们来模拟记录训练过程中准确率的变化。
首先需要new一个SummaryWriter
对象:
from torch.utils.tensorboard import SummaryWriter
writer = SummaryWriter(log_dir='runs/mock_loss')
当运行完该行代码后,可以看到当前目录下生成了一个runs/mock_accuracy
文件夹,并且里面有event日志
此时已经可以启动tensorboard来查看了:
tensorboard --logdir runs
此时进入tensorboard页面后,啥都看不到,因为我们还没有向log里面写入任何数据:
接下来使用 add_scalar
绘制准确率折线图:
for i in range(100):
writer.add_scalar(tag="accuracy", # 可以暂时理解为图像的名字
scalar_value=i * random.uniform(0.8, 1), # 纵坐标的值
global_step=i # 当前是第几次迭代,可以理解为横坐标的值
)
time.sleep(2 * random.uniform(0.5, 1.5))
这里模拟 1~3 秒完成一次迭代并计算准确率,然后将准确率增添到 accuracy 这个图下面。
过一会后,我们刷新页面,就可以看到我们的准确率变化曲线了:
由于数据还在写入,所以曲线还在不断变化。
Tensor折线图(Scalars)
- TODO:其他图形的介绍
边栏推荐
- One brush 142 monotone stack next larger element II (m)
- Dagong 21 autumn "power plant electrical part" online operation 1 [standard answer] power plant electrical part
- Redis: operation commands for list type data
- 人生还在迷茫?也许这些订阅号里有你需要的答案!
- [RT thread] NXP rt10xx device driver framework -- RTC construction and use
- VM11289 WAService. js:2 Do not have __ e handler in component:
- Luogu: p2685 [tjoi2012] Bridge
- [combinatorics] recursive equation (the problem of solving recursive equation with multiple roots | the problem is raised)
- A day's work list of an ordinary programmer
- Svn full backup svnadmin hotcopy
猜你喜欢
kubernetes资源对象介绍及常用命令(四)
问题随记 —— 在 edge 上看视频会绿屏
線程池:業務代碼最常用也最容易犯錯的組件
Great changes! National housing prices fell below the 10000 yuan mark
手把手带你入门 API 开发
[RT thread] NXP rt10xx device driver framework -- pin construction and use
Bcvp developer community 2022 exclusive peripheral first bullet
【RT-Thread】nxp rt10xx 设备驱动框架之--Pin搭建和使用
Golang单元测试、Mock测试以及基准测试
鸿蒙第四次培训
随机推荐
Rsync远程同步
One brush 147-force deduction hot question-4 find the median of two positive arrays (H)
Visual studio "usually, each socket address (Protocol / network address / port) can only be used once“
How to promote cross department project collaboration | community essay solicitation
在iptables防火墙下开启vsftpd的端口
Squid 服务启动脚本
One brush 148 force deduction hot question-5 longest palindrome substring (m)
Execute script unrecognized \r
Electronic technology 20th autumn "Introduction to machine manufacturing" online assignment 3 [standard answer]
One brush 149 force deduction hot question-10 regular expression matching (H)
[combinatorics] recursive equation (solution of linear non-homogeneous recursive equation with constant coefficients | standard form and general solution of recursive equation | proof of general solut
[combinatorics] recursive equation (characteristic equation and characteristic root | example of characteristic equation | root formula of monadic quadratic equation)
The largest matrix (H) in a brush 143 monotone stack 84 histogram
[combinatorial mathematics] recursive equation (example of recursive equation 2 Hanoi Tower | example of recursive equation 3 insertion sequencing)
Assignment examination questions of advanced English (III) for the course examination of Fujian Normal University in February 2022
RF analyze demo build step by step
鸿蒙第三次培训
聊聊接口优化的几个方法
One brush 146 force buckle hot question-3 longest substring without repeated characters (m)
图之深度优先搜索