当前位置:网站首页>Gpushare. COM | how to use tensorboardx visualization tool?
Gpushare. COM | how to use tensorboardx visualization tool?
2022-07-24 03:12:00 【Hengyuan cloud】
TensorBoardX Is based on TensorBoard, One can be used for Pytorch Data visualization tools , Yes TensorBoard More familiar users , It's easy to get started TensorBoardX~
Let's see , On our platform , How to use TensorBoardX Well ?
install TensorBoardX
Here is a demonstration of Pytorch Frame usage TensorBoardX visualization , Create a Pytorch Examples of frameworks , Then proceed as follows .
install tensorboardX
~# pip install tensorboardX
You can choose to install crc32c To speed up
~# pip install crc32c
from tensorboardX 2.1 Start , Need to be for add_audio() Function installation soundfile
~# pip install soundfile
# install soundfile The dependence needed
~# apt-get update -y && apt-get install libsndfile1 -y
Upload code
Through here tensorboardX The project provides code to run , In the process of training, you need to use your own code and upload it to the example .
~# git clone https://github.com/lanpa/tensorboardX.git
# see tensorboardX The project provides examples of code , Mainly see how to call TensorBoardX To display
~# cat tensorboardX/examples/demo.py
import torch
import torchvision.utils as vutils
import numpy as np
import torchvision.models as models
from torchvision import datasets
from tensorboardX import SummaryWriter
import datetime
try:
import soundfile
skip_audio = False
except ImportError:
skip_audio = True
resnet18 = models.resnet18(False)
writer = SummaryWriter()
sample_rate = 44100
freqs = [262, 294, 330, 349, 392, 440, 440, 440, 440, 440, 440]
true_positive_counts = [75, 64, 21, 5, 0]
false_positive_counts = [150, 105, 18, 0, 0]
true_negative_counts = [0, 45, 132, 150, 150]
false_negative_counts = [0, 11, 54, 70, 75]
precision = [0.3333333, 0.3786982, 0.5384616, 1.0, 0.0]
recall = [1.0, 0.8533334, 0.28, 0.0666667, 0.0]
for n_iter in range(100):
s1 = torch.rand(1) # value to keep
s2 = torch.rand(1)
# data grouping by `slash`
writer.add_scalar('data/scalar_systemtime', s1[0], n_iter, summary_description="# markdown is supported!")
# data grouping by `slash`
writer.add_scalar('data/scalar_customtime', s1[0], n_iter, walltime=n_iter, display_name="dudubird")
writer.add_scalars('data/scalar_group', {"xsinx": n_iter * np.sin(n_iter),
"xcosx": n_iter * np.cos(n_iter),
"arctanx": np.arctan(n_iter)}, n_iter)
x = torch.rand(32, 3, 64, 64) # output from network
if n_iter % 10 == 0:
x = vutils.make_grid(x, normalize=True, scale_each=True)
writer.add_image('Image', x, n_iter) # Tensor
writer.add_image_with_boxes('imagebox_label', torch.ones(3, 240, 240) * 0.5,
torch.Tensor([[10, 10, 100, 100], [101, 101, 200, 200]]),
n_iter,
labels=['abcde' + str(n_iter), 'fgh' + str(n_iter)])
if not skip_audio:
x = torch.zeros(sample_rate * 2)
for i in range(x.size(0)):
# sound amplitude should in [-1, 1]
x[i] = np.cos(freqs[n_iter // 10] * np.pi *
float(i) / float(sample_rate))
writer.add_audio('myAudio', x, n_iter)
writer.add_text('Text', 'text logged at step:' + str(n_iter), n_iter)
writer.add_text('markdown Text', '''a|b\n-|-\nc|d''', n_iter)
for name, param in resnet18.named_parameters():
if 'bn' not in name:
writer.add_histogram(name, param, n_iter)
writer.add_pr_curve('xoxo', np.random.randint(2, size=100), np.random.rand(
100), n_iter) # needs tensorboard 0.4RC or later
writer.add_pr_curve_raw('prcurve with raw data', true_positive_counts,
false_positive_counts,
true_negative_counts,
false_negative_counts,
precision,
recall, n_iter)
# export scalar data to JSON for external processing
writer.export_scalars_to_json("./all_scalars.json")
dataset = datasets.MNIST('mnist', train=False, download=True)
images = dataset.data[:100].float()
label = dataset.targets[:100]
features = images.view(100, 784)
writer.add_embedding(features, metadata=label, label_img=images.unsqueeze(1))
writer.add_embedding(features, global_step=1, tag='noMetadata')
images_train = dataset.data[100:200].float()
labels_train = dataset.targets[100:200]
features_train = images_train.view(100, 784)
all_features = torch.cat((features, features_train))
all_labels = torch.cat((label, labels_train))
all_images = torch.cat((images, images_train))
dataset_label = ['test'] * 100 + ['train'] * 100
all_labels = list(zip(all_labels, dataset_label))
writer.add_embedding(all_features, metadata=all_labels, label_img=all_images.unsqueeze(1),
metadata_header=['digit', 'dataset'], global_step=2)
# VIDEO
vid_images = dataset.data[:16 * 48]
vid = vid_images.view(16, 48, 1, 28, 28) # BxTxCxHxW
writer.add_video('video', vid_tensor=vid)
writer.add_video('video_1_fps', vid_tensor=vid, fps=1)
writer.close()
writer.add_scalar('implicit reopen writer', 100, 0)
Run the program
In the following example tmux Program to host program operation .
# Create a demo Of tmux window
~# tmux new -s demo
# Run the program
~# python tensorboardX/examples/demo.py
Downloading http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz
Downloading http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz to mnist/MNIST/raw/train-images-idx3-ubyte.gz
function TensorBoardX
The last step passed tmux It's running python project , Here we need to reopen one ssh A terminal window .
# start-up TensorboardX front , You need to close the installed in the official image first tensorboard
~# supervisord ctl stop tensorboard
# start-up TensorBoardX Also through tmux Program managed operation
~# tmux new -s tensorboard
~# tensorboard --logdir runs --host 0.0.0.0
visit TensorBoardX
open Hengyuan cloud console , Then find the currently running instance Tensorboard Just visit .

Platform documentation :
TensorBoardX - Hengyuan cloud user document
https://gpushare.com/docs/best_practices/tensorboardX/
边栏推荐
- Symbol類型
- Microsoft win11/10 package manager Winget will support the installation of applications from zip files
- Summernote font displays Chinese
- AcWing 4498. 指针 (DFS)
- Qt自定义类使用自定义含参信号与槽
- Ue5 split screen (small map) solution
- Soft test --- fundamentals of programming language (Part 1)
- Nodejs builds cloud native microservice applications based on dapr, a quick start guide from 0 to 1
- CMT registration - Google Scholar ID, semantic scholar ID, and DBLP ID
- [C language] file operation
猜你喜欢

Microsoft win11/10 package manager Winget will support the installation of applications from zip files

Soft test --- fundamentals of programming language (Part 1)

JS Array isaarray () Type of

String.split() the most detailed source code interpretation and precautions

CMT 注册——Google Scholar Id,Semantic Scholar Id,和 DBLP Id

Ugui source code analysis - maskablegraphic

summernote富文本编辑器

【HDLBits 刷题】Verilog Language(2)Vectors 部分

Hcip day 9 notes (OSPF routing feedback, routing policy, and Configuration Guide)
![[MySQL learning] install and use multiple versions of MySQL, MySQL 8 and MySQL 5.7 at the same time, compressed version](/img/08/3765b34809cc4c723608f5d2e86ed4.png)
[MySQL learning] install and use multiple versions of MySQL, MySQL 8 and MySQL 5.7 at the same time, compressed version
随机推荐
Open source embedded sig in the openeuler community. Let's talk about its multi OS hybrid deployment framework
O3DE 的Lumberyard 游戏引擎
Binary tree traversal
Microsoft win11/10 package manager Winget will support the installation of applications from zip files
AcWing 4499. 画圆 (相似三角形)
JS array isaarray() typeof
水题: 接雨水
LCD1602 - binge 51
Water topic: connect rainwater
Redux Usage Summary
CMT registration - Google Scholar ID, semantic scholar ID, and DBLP ID
TCP connection principle
Dynamic programming-01 knapsack problem
B. Eastern Exhibition- Codeforces Round #703 (Div. 2)
在openEuler社区开源的Embedded SIG,来聊聊它的多 OS 混合部署框架
Connected graph (day 72)
Symbol type
Open source quantum development framework cirq
PMP preparation experience | good habits, good process, good results
Huawei then responded to the rumor of "cleaning up employees over the age of 34". How can programmers cope with the "35 year old crisis"?
https://github.com/lanpa/tensorboardX