当前位置:网站首页>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/
边栏推荐
- Skywalking distributed system application performance monitoring tool - upper
- Openresty Lua resty balancer dynamic load balancing
- OSPF comprehensive experimental configuration
- What is the security of Treasury reverse repo
- Customize the default width and height of kindeditor rich text
- Ugui source code analysis - Mask
- Minimum exchange times
- Go log package
- Some properties of differential array operation
- Nodejs builds cloud native microservice applications based on dapr, a quick start guide from 0 to 1
猜你喜欢

O3DE 的Lumberyard 游戏引擎

C文件操作详解

Basic knowledge of trigger (Part 2)

The new idea 2022.2 was officially released, and the new features are nice

Babylon.js cool canvas background animation JS special effects

The process of solving a bug at work

Hcip --- BGP comprehensive experiment

The implementation in unity determines whether missing or null

FTP service and configuration

Simulink代码生成: 可变子系统及其代码
随机推荐
【AMC】联邦量化
Leetcode stack and queue questions
轮播图van-swipe的报错:cannot read a properties of null(reading width)
Bingbing learning notes: basic operation of vim tool
Symbol類型
The simple use of ADB command combined with monkey is super detailed
SolidWorks CAM data cannot be recovered because a processed part has been detected.
PMP preparation experience | good habits, good process, good results
Unity 消息推送
Ue5 split screen (small map) solution
移动通信的新定义:R&SCMX500 将提高5G设备的IP数据吞吐量
Some properties of differential array operation
Nodejs builds cloud native microservice applications based on dapr, a quick start guide from 0 to 1
In the future, when the interviewer asks why you don't recommend using select *, please answer him loudly!
C. Minimum Ties-Educational Codeforces Round 104 (Rated for Div. 2)
go IO操作-文件写
Simulink代码生成: 可变子系统及其代码
Acwing 4498. pointer (DFS)
PMP first-hand data and information acquisition
go IO操作-文件读
https://github.com/lanpa/tensorboardX