In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I would like to share with you the PyTorch visualization tools TensorBoard and Visdom how to use the relevant knowledge points, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you will learn something after reading this article, let's take a look at it.
1. TensorBoard
TensorBoard is generally used as a visualization tool of TensorFlow, which is deeply integrated with TensorFlow. It can show the network computing diagram of TensorFlow, draw the quantitative index map of image generation and additional data.
In addition, TensorBoard is also a stand-alone tool that can be used for visualization in PyTorch.
1. Install:
Pip install tensorboard
2. Start:
Tensorboard-logdir= "log directory"
When starting tensorboard, you can specify parameters such as logdir, port (default 6006), host (default localhost), and so on:
Usage: tensorboard [- h] [--helpfull] [--logdir PATH] [--logdir_spec PATH_SPEC] [--host ADDR] [--bind_all] [--port PORT] [--purge_orphaned_data BOOL] [--db URI] [--db_import] [--inspect] [--version_tb] [--tag TAG] [--event_file PATH] [--path_prefix PATH] [--window_title TEXT] [--max_reload_threads COUNT] [--reload_interval SECONDS] [--reload_task TYPE] [--reload_multifile BOOL] [--reload_multifile_inactive_secs SECONDS ] [--generic_data TYPE] [--samples_per_plugin SAMPLES_PER_PLUGIN] [--debugger_data_server_grpc_port PORT] [--debugger_port PORT] [--master_tpu_unsecure_channel ADDR]
3. Tensorboard visual demonstration (PyTorch framework):
Train the model and import tensorboard. SummaryWriter saves loss, accuracy and other log information.
# Import SummaryWriterfrom torch.utils.tensorboard import SummaryWriter...# to create SummaryWriter instance, specify the location of log_dir summaryWriter = SummaryWriter (log_dir= "/ Users/liyunfei/PycharmProjects/python3practice/06DL/fcnn/logs"). # Model training Write train_loss, test_loss, score and other information summaryWriter.add_scalars ("loss", {"train_loss_avg": train_loss_avg, "test_loss_avg": test_loss_avg}, epoch) summaryWriter.add_scalar ("score", score, epoch)
Start TensorBoar to visualize the training process.
1) start the command:
Tensorboard-logdir=/Users/liyunfei/PycharmProjects/python3practice/06DL/fcnn/logs
2) start successfully as shown in the figure:
3) the visualization results are as follows:
II. Visdom
Visdom is a visualization tool developed by Facebook specifically for PyTorch, which can support the visualization of "remote data" and support Torch and Numpy. GitHub address: https://github.com/fossasia/visdom
1. Install:
Pip install visdom
2. Start:
Python-m visdom.server
-m is started as a module service
In the case of a linux/mac-os environment, you can use the following command to start running in the background
Nohup python-m visdom.server &
When you start Visdom, you can specify other parameters such as port (default 8097), hostname (default localhost), and so on:
Usage: server.py [- h] [- port port] [--hostname hostname] [- base_url base_url] [- env_path env_path] [- logging_level logger_level] [- readonly] [- enable_login] [- force_new_cookie] [- use_frontend_client_polling]
3. Visual demonstration of Visdom
1) start Visdom:
Python-m visdom.server-port 8097
2) the successful startup is as follows:
3) Visualization code of training process:
# Import visdom package import visdom# to create Visdom object, connect to server, specify env environment (do not specify default env= "main") viz = visdom.Visdom (server=' http://localhost', port=8097, env='liyunfei')... viz.line ([0.], [0], win='train_loss', opts=dict (title='train_loss')) viz.line ([0.], [0], win='accuracy', opts=dict (title='accuracy')). # Model training Real-time visualization of loss, accuracy and other information. Viz.line ([train_loss_avg], [epoch], win='train_loss', update='append') viz.line ([accuracy], [epoch], win='accuracy', update='append')
4) Visualization result
5) other operations-visualize one or more images:
Example:
Import visdomimport numpy as npviz = visdom.Visdom (server=' http://localhost', port=8097, env='liyunfei') # one picture viz.image (np.random.rand (3,512256), opts=dict (titlepictures assigned random pictures, caption='How random.'),) # multiple pictures viz.images (np.random.randn (20,3,64,64), nrow=5, opts=dict (title='Random images', caption='How random.'))
Effect:
6) more visual API of Visdom (commonly used are line, image, text):
Vis.scatter: 2D or 3D scatter plot
Vis.line: line graph
Vis.stem: stem and leaf diagram
Vis.heatmap: thermal map
Vis.bar: bar chart
Vis.histogram: histogram
Vis.boxplot: box diagram
Vis.surf: surface view
Vis.contour: contours
Vis.quiver: draw a two-dimensional vector field
Vis.image: picture
Vis.text: text
Vis.mesh: grid chart
Vis.save: serialization statu
These are all the contents of this article entitled "how to use PyTorch Visualization tools TensorBoard and Visdom". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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.