当前位置:网站首页>How to use tensorboard add_ histogram

How to use tensorboard add_ histogram

2022-06-22 02:27:00 Melody2050

Code samples https://pytorch.org/docs/stable/tensorboard.html

Run the following code

from torch.utils.tensorboard import SummaryWriter
import numpy as np


#  Code sample from https://pytorch.org/docs/stable/tensorboard.html
writer = SummaryWriter(log_dir="add_histogram_demo_data/log")
for i in range(10):
    x = np.random.random(1000)
    writer.add_histogram('distribution centers', x + i, i)
writer.close()

And in add_histogram_demo_data Run in directory , open tensorboard

tensorboard --logdir="./log"

You can see the results as shown in the figure , The distribution of all the data is shown in the figure , So how to understand this histogram ?

We look at the first data block , It represents writer.add_histogram('distribution centers', x + i, 0) Call to , here global_step=0. identical global_step The data will be placed on the same layer .

The height of the block pointed to in the above figure is 336, Abscissa for 0.167, Ordinate for 0, This represents the second 0 Layer data in 0.167 There are some nearby points 336 individual .

Let's take a screenshot of the distribution of the other two points on this layer , The heights are respectively 324 and 340.336+324+340=1000, It's about x = np.random.random(1000) Corresponding to the . This is what the histogram shows 1000 Numerical distribution of points .

Of course , The data are certainly not all exactly equal to 0.167,0.500 and 0.833, They just happen to be located near these ,debug See the specific data .

原网站

版权声明
本文为[Melody2050]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206212214050139.html