深度学习可视化工具--tensorboard的使用
2024-09-06 00:22:12
tensorboard的使用
官方文档
# writer.add_scalar() # 添加标量
"""
Args:
tag (string): Data identifier # 图表的Title
scalar_value (float or string/blobname): Value to save # 对应的y轴
global_step (int): Global step value to record # 对应的x轴
walltime (float): Optional override default walltime (time.time())
with seconds after epoch of event
"""
# demo
from torch.utils.tensorboard import SummaryWriter
writer = SummaryWriter('runs') # 实例化一个对象
for i in range(100):
writer.add_scalar("y=x^2", i**2, i) # 分别对应title y轴 x轴
writer.close()
# writer.add_image() # 添加图片
"""Add image data to summary.
Note that this requires the ``pillow`` package.
Args:
tag (string): Data identifier
img_tensor (torch.Tensor, numpy.array, or string/blobname): Image data
global_step (int): Global step value to record
walltime (float): Optional override default walltime (time.time())
seconds after epoch of event
Shape:
img_tensor: Default is :math:`(3, H, W)`. You can use ``torchvision.utils.make_grid()`` to
convert a batch of tensor into 3xHxW format or call ``add_images`` and let us do the job.
Tensor with :math:`(1, H, W)`, :math:`(H, W)`, :math:`(H, W, 3)` is also suitable as long as
corresponding ``dataformats`` argument is passed, e.g. ``CHW``, ``HWC``, ``HW``.
Examples::
from torch.utils.tensorboard import SummaryWriter
import numpy as np
img = np.zeros((3, 100, 100))
img[0] = np.arange(0, 10000).reshape(100, 100) / 10000
img[1] = 1 - np.arange(0, 10000).reshape(100, 100) / 10000
img_HWC = np.zeros((100, 100, 3))
img_HWC[:, :, 0] = np.arange(0, 10000).reshape(100, 100) / 10000
img_HWC[:, :, 1] = 1 - np.arange(0, 10000).reshape(100, 100) / 10000
writer = SummaryWriter()
writer.add_image('my_image', img, 0)
# If you have non-default dimension setting, set the dataformats argument.
writer.add_image('my_image_HWC', img_HWC, 0, dataformats='HWC')
writer.close()
Expected result:
.. image:: _static/img/tensorboard/add_image.png
:scale: 50 %
"""
# demo
from torch.utils.tensorboard import SummaryWriter
import cv2
write = SummaryWriter("logs")
img_array1 = cv2.imread('./dog.jpeg') # 读取图片,类型为ndarray
write.add_image("img", img_array1, 1, dataformats='HWC') # title, 数据: ndarray/tensor step 数据的类型: 默认:'CHW'
write.close()
开启面板
# 方法1: tensorboard --logdir=runs
# 方法2: tensorboard --logdir runs
# 方法3: tensorboard --logdir=runs --port=6007 如果端口冲突使用不冲突的端口
最新文章
- Oracle同义词
- Yii2 定时任务创建(Console 任务)
- sql执行
- ASP.NET AJAX Control Toolkit
- JNDI 是什么
- 解决Cisco VPN Client:Reason 442: Failed to Enable Virtual Adapter VPN连接问题
- [置顶] js对象
- 第06讲- DDMS中logcat的使用
- windows 7 旗舰版 切换 中英文 界面
- 超高性能的json序列化
- C++中的基本数据类型
- I/O模型
- React文档(二十二)context
- 应届生第一次Java面试问题分享
- govendor 无法添加.h文件
- (转载)中文Appium API 文档
- XQuery使用sum求和,提示char不能转换为money解决方法
- java web 读取文件,文件路劲不对的问题
- 如何从MTK机器的NVRAM中获取WIFI mac地址
- java 错误:无法找到或装入主类