In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how TensorBoard and torchsummary in Pytorch, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
In the process of using pytorch, a good visualization tool is essential. TensorBoard is such a powerful neural network visualization tool. So how do you use this tool? Please take a look at the editor's next introduction:
1.TensorBoard Neural Network Visualization tool
TensorBoard is a powerful visualization tool, and there are two invocation methods in pytorch:
1.from tensorboardX import SummaryWriter
This method was written by a great god on the Internet when the government did not support tensorboard.
2.from torch.utils.tensorboard import SummaryWriter
This method was later updated and officially added.
1.1 call method
1.1.1 create interface SummaryWriter
Function: create an interface
Call method:
Writer = SummaryWriter ("runs")
Parameters:
Log_dir:event file output folder
Comment: folder suffix when log_dir is not specified
Filename_suffix:event file file name suffix
1.1.2 record scalar add_scalars ()
Function: record scalar add_scalars ()
Call method:
Writer.add_scalars ("name", {"dic": val}, epoch)
Parameters:
Tag: the tag name of the image
Scalar_step: the scalar to record
Global_step: rounds
1.1.3 Statistical histogram add_histogram ()
Function: statistical histogram and multiquantile line chart
Call method:
Writer.add_histogram ("weight", self.fc.weight,epoch)
Parameters:
Tag: the tag name of the image
Values: data to draw a histogram
Global_step: rounds
Bins: values include 'tensorflow',' auto', 'fd', etc.
1.1.4 batch display image add_image ()
Function: batch display image
Call method:
Writer.add_image ("Cifar10", img_batch, epoch,'CHW')
Parameters:
Tag: the tag name of the image
Img_tensor: image data, pay attention to the size
Global_step: rounds
Dataformats: data form, CHW,HWC,HW
1.1.5 View model diagram add_graph ()
Function: view model diagram
Call method:
Writer.add_graph (model=net,input_to_model=torch.randn (1,224,224) .to (device))
Parameters:
Model: model, must be nn.Module
Input_to_model: data output to the model
Verbose: whether to print calculation chart structure information
Remember to write writer.close () when you finish writing.
two。 View the network layer shape and parameter torchsummary
Function: view network layer shapes and parameters
Call method:
From torchsummary import summarysummary (net, input_size= (3,224,224))
Parameters:
Model:pytorch model
Input_size: model input size
Batch_size:batch size
Device: "cuda" or "cpu"
3. Start tensorboard
Cmd opens the terminal in the file path, enter
Tensorboard-- logdir= ". / runs"
Runs is the name of the file I saved. Open the following link
Add: pytorch attempts to call the tensorboard method
Tensorboard provides a good interface for monitoring training losses, which can help us better adjust the parameters. The following describes how to call tensorboard in pytorch.
First
Install tensorboard, tensorflow, and tensorboardX
Second
Import SummaryWriter at the beginning of the file
Third in from tensorboardX import SummaryWriter
Like tensorflow's tensorboard, tensorboardX provides a variety of recording methods, such as scalar, image and so on.
Writer = SummaryWriter ('path')
If you do not add a path, it is named after the time by default.
Fourth
Add a monitoring variable
Writer.add_scalar ('Train/Acc', Acc, iter) No. 5
Open tensorboard
Tensorboard-- the sixth logdir 'path'
Open port 6006 in the browser
The above is all the contents of the article "how about TensorBoard and torchsummary in Pytorch". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.