Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Pytorch use Tensorboard to observe data

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces Pytorch how to use Tensorboard to observe data, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

1.Tensorboard

There are two common methods:

One is add_scalar () showing the curve.

One is the add_image () display image.

Install Tensorboard first

Enter commands in your compilation environment (conda activate XXX)

Pip install tensorboard1. Enter the code using add_scalar ()

From torch.utils.tensorboard import SummaryWriter # switch package writer = SummaryWriter ('logs') # here you create a logs file with the curve generated by your add_scalar, # where the first quantity of writer.add_scalar () is the name of the curve # the second quantity is the ordinate scalar_value, and the third quantity is the Abscissa global_step (also understood as loss worthy step size) for i in range (100): writer.add_scalar ("quadratic", I * * 2, I) writer.close ()

Open this Tensorboard file

Tensorboard-- logdir=logs#1. The file name of this logdir must be the same as the file name created before, otherwise it is easy to report an error, No dashboards are active for the current data set.#2. The command entered by this tensorboard must be in the upper layer of the logs file, otherwise it is also easy to report an error, No dashboards are active for the current data set.

The result is:

two。 Enter the code using add_image ()

Note: functions in add_image () generally have three quantities:

The first is the name of the image, the second is the image (must be tensor or numpy.ndarray), and the third is the step size (which image can be understood as the training or testing phase)

Where the shape of the image must be CHW, but the shape of the image read by opencv is HWC

So you have to use the dataformats conversion to convert the image's shape to HWC as follows

The following code tests two images (one from aligned and the other from original) to simulate which image the training or test phase program runs on

From torch.utils.tensorboard import SummaryWriterimport cv2writer = SummaryWriter ('logs') aligned_img_path = "D:\\ data\\ basic\\ Image\\ aligned\\ test_0001_aligned.jpg" original_img_path = "D:\ data\\ basic\\ Image\\ original\\ test_0001.jpg" aligned_img = cv2.imread (aligned_img_path) original_img = cv2.imread (original_img_path) print (type (aligned_img)) # numpyprint (aligned_img) .shape) # writer.add_image ("img" Aligned_img, 1, dataformats='HWC') # this figure has already used writer.add_image ("img", original_img, 2, dataformats='HWC') in my first test of add_image () # this is my second test writer.close ()

Achieve the result:

IMAGES appears in tensorboard, and step1 is the graph of aligned, while step2 is the graph of original.

Thank you for reading this article carefully. I hope the article "how to use Pytorch to observe data with Tensorboard" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report