Pytorch的可视化学习日志2——Pytorch自带的Tensorboard

PyTorch 从 1.2.0 版本开始,正式自带内置的 Tensorboard 支持了,我们可以不再依赖第三方工具来进行可视化。
本文将介绍 PyTorch 1.2.0 中自带 Tensorboard 的基本使用方法。

安装

PyTorch 的版本需要 1.2.0 :

pip install --upgrade torch torchvision

然后安装 Tensorboard 1.14 :

pip install tensorboard

安装完成后,引入响应包:

Python 3.7.4 (default, Aug 13 2019, 20:35:49) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from torch.utils.tensorboard import SummaryWriter
/home/seungjaeryanlee/.conda/envs/torchtest/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: FutureWarning: Passing (type, 1) or \\'1type\\' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / \\'(1,)type\\'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/seungjaeryanlee/.conda/envs/torchtest/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: FutureWarning: Passing (type, 1) or \\'1type\\' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / \\'(1,)type\\'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/seungjaeryanlee/.conda/envs/torchtest/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: FutureWarning: Passing (type, 1) or \\'1type\\' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / \\'(1,)type\\'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/seungjaeryanlee/.conda/envs/torchtest/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:544: FutureWarning: Passing (type, 1) or \\'1type\\' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / \\'(1,)type\\'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/seungjaeryanlee/.conda/envs/torchtest/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:545: FutureWarning: Passing (type, 1) or \\'1type\\' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / \\'(1,)type\\'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/seungjaeryanlee/.conda/envs/torchtest/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:550: FutureWarning: Passing (type, 1) or \\'1type\\' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / \\'(1,)type\\'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
引入相应的 Writer

要使用 Tensorboard 需要在 Python 代码中引入 Writer 类,并定义输出路径:

from torch.utils.tensorboard import SummaryWriter       
writer = SummaryWriter(PATH_to_log_dir)

如果输出路径不存在会被自动创建。

运行 Tensorboard

在命令行中运行下列命令启动 Tensorboard:

tensorboard --logdir=/path_to_log_dir/ --port 6006
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值