当前位置:网站首页>Pytorch framework learning record 2 - the use of TensorBoard
Pytorch framework learning record 2 - the use of TensorBoard
2022-07-30 03:57:00 【Yuzu Roo】
Pytorch框架学习记录2——TensorBoard的使用
Tensorboard在训练模型时很有用,可以看训练过程中loss的变化.之前用于Tensorflow框架,自Pytorch1.1之后,Pytorch也加了这个功能.
1. TensorBoard的使用
从torch.utils.tensorboard
中导入SummaryWriter
类.
1.1 SummaryWriter类使用
SummaryWriter类可以在指定文件夹生成一个事件文件,这个事件文件可以对TensorBoard解析.
首先实例化一个SummaryWriter
的类,The parameter represents the name of the saved folder
writer = SummaryWriter("logs") #文件夹名称
1.2 writer.add_scalar()方法:
def add_scalar(
self,
tag,
scalar_value,
global_step=None,
walltime=None,
new_style=False,
double_precision=False,
):
The above are the officially defined parameters,This method is meant to add a scalar.
tag
:drawn icontitle,str类型,注意引号
scalar_value
:需要保存的数值,对应y轴的y值
global_step
:全局的步数,对应x轴
这里的tagPlay the role of uniquely identifying the image,If you need two pictures,is rewrittentag!!!
1.4 举例
绘制y = x 的图像.
from torch.utils.tensorboard import SummaryWriter
writer = SummaryWriter("logs")
for i in range(100):
writer.add_scalar("y = x", i, i)
writer.close()
1.5 add_image()方法
def add_image(self, tag, img_tensor, global_step=None, walltime=None, dataformats='CHW'):
''' 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``. '''
其中,img_tensor
参数类型要求为:torch.Tensor
、numpy.array
或者string
类型.global_step
为步骤,int
类型.
img_tensor
The default image size format is (3,H,W),But generally our picture format is (H,W,3),Therefore, the image format needs to be adjusted,调整的方法如下:设置dataformats='HWC'
即可!!!
from torch.utils.tensorboard import SummaryWriter
from PIL import Image
import numpy as np
writer = SummaryWriter("logs")
img_path = "C:\\Users\\hp\\PycharmProjects\pythonProject\\Pytorch_Learning\\flower_data\\train\daisy\\5547758_eea9edfd54_n.jpg"
img_PIL = Image.open(img_path)
img_array = np.array(img_PIL)
print(type(img_array))
writer.add_image("test", img_array, 1, dataformats='HWC')
for i in range(100):
writer.add_scalar("y = x", i, i)
writer.close()
1.6 Event file open method:
在PyCharm中,Find where the project isterminal,
tensorboard --logdir=The name of the folder where the event file is located --port=端口号
Just open it on the URL that pops up.
2. Common error cases
2.1 ImportError: TensorBoard logging requires TensorBoard version 1.15 or above
tensorboard版本过低,Reinstall the latest version after uninstalling.
2.2 AttributeError: module ‘tensorflow._api.v1.io’ has no attribute ‘gfile’
tensorflow 的版本和tensorboard的版本不匹配.升级tensorflow版本为2.0版本即可,Execute the following command to automatically upgradetensorflow版本和tensorboard版本:
pip install tensorflow==2.0
2.3 ModuleNotFoundError: No module named ‘grpc’
重新安装grpcio
pip uninstall grpcio
pip install grpcio
2.4 No dashboards are active for the current data set.
The open file location does not exist,Copy the absolute path to the folder location,然后重新执行terminal语句即可
边栏推荐
- spicy(一)基本定义
- When the EasyNVR platform is cascaded to the EasyCVR, why can't the video be played after a while?
- MySQ deadlock
- 护网行动基本介绍
- Small application project works WeChat integral mall small program of graduation design (4) the opening report of finished product
- After 5 years of Ali internship interview~
- 第51篇-知乎请求头参数分析【2022-07-28】
- TCP congestion control technology and acceleration principle of BBR
- 【驱动】udev设置GPIO加载后所有者、所属组和权限
- ospf map
猜你喜欢
[Node accesses MongoDB database]
Chapter 51 - Knowing the request header parameter analysis【2022-07-28】
vscode 调试和远程
Organizations Going Online: A New Trend in Organizational Digital Transformation
Gateway 路由网关
小程序毕设作品之微信二手交易小程序毕业设计成品(4)开题报告
Gateway routing gateway
Nacos service registration and discovery
星光不问赶路人!武汉校区小姐姐三个月成功转行软件测试,收获9k+13薪!
[Switch] Protocol-Oriented Programming in Swift: Introduction
随机推荐
Advanced Microservices Cloud Alibaba
FreeRTOS Personal Notes - Memory Management
Boutique: Taobao/Tmall Get Order Details API for Purchased Products
Anti-shake and throttling
新接口——“淘特”关键词搜索的API接口
Mini Program Graduation Works WeChat Points Mall Mini Program Graduation Design Finished Product (8) Graduation Design Thesis Template
vscode 调试和远程
小程序毕设作品之微信二手交易小程序毕业设计成品(2)小程序功能
淘宝/天猫获取卖出的商品订单列表 API
Nacos installation and deployment
使命、愿景、价值观到底有什么区别
redis分布式锁的原子保证
小程序毕设作品之微信二手交易小程序毕业设计成品(8)毕业设计论文模板
SDL player in action
Forum management system
Mini Program Graduation Works WeChat Second-hand Trading Mini Program Graduation Design Finished Works (3) Background Functions
How does the AI intelligent security video platform EasyCVR configure the simultaneous transmission of audio and video?
护网行动基本介绍
Solve the problem of compiling and installing gdb-10.1 unistd.h:663:3: error: #error “Please include config.h first.”
spicy (two) unit hooks