2018/9/18 Update feel TENSORBOARDX plug-in better use, has been switched to Https://github.com/lanpa/tensorboardX
Update: The new visdom0.1.7 installation method is: Conda install-c SRIVASV visdom
Pytorch can be used as a visualization tool under the Visidom
1. Installation
Pip Install Visdomconda Install Visdom
Start
Python-m Visdom.server
In the browser input: http://localhost:8097/, you can start
Note:
(1) Sometimes after installation can not be used, such as the Web page nothing, you can try to replace anaconda3\lib\site-packages\visdom under the static folder (if you use anaconda words), because of the network, cause the file download is not complete, File link Link: Https://pan.baidu.com/s/1c4liqoK Password: Q1SX, under Linux (Ubuntu) is the same processing, under Lib\site-packages\visdom to replace the static file, Restart effective!!!!
(2) Sometimes when you start Visdom, the display target computer refused to wait for the network connection is unsuccessful, the following test can be used
From visdom Import Visdomviz = Visdom () assert viz.check_connection ()
Mostly I was using the agent to surf the internet, which led to the change of Internet options for my Internet Explorer, such as:
2. Example of a visual loss function
First introduce the line () function in Visdom:
1) Draw a straight line
From visdom import Visdomimport numpy as Npviz = Visdom (env= ' my_wind ') #设置环境窗口的名称是 ' My_wind ' If the name is not set in main tr_loss=list ( Range (+)) Viz.line (Y=np.array (Tr_loss), Opts=dict (showlegend=true))
Before running the above program, first start Visdom, enter Python-m visdom.server in cmd, and then enter in the browser: http://localhost:8097/, the default is in the main environment:
The above code, we set the name of the environment window is ' my_wind ', so we need to open the My_wind environment, as follows:
Run the Code!
2) If you want to draw more than one line
From visdom import Visdomimport numpy as Npviz = Visdom (env= ' my_wind ') #设置环境窗口的名称是 ' My_wind ' If the name is not set in main tr_loss=list ( Range (+)) Ts_loss=list (range (10,110)) Viz.line (Y=np.column_stack (Np.array (Tr_loss), Np.array (Ts_loss)), opts= Dict (Showlegend=true))
Note: The values of the above variables are determined before they are plotted.
3) If you want to draw the values that gradually occur with the program, as in training, you can use the line Update method
From visdom import Visdomimport numpy as Npviz = Visdom (env= ' my_wind ') X,y=0,0win = Viz.line (X=np.array ([x]), Y=np.array ([ Y]), opts=dict (title= ' two_lines ')) for I in range: X+=i y+=i viz.line (X=np.array ([x]), Y=np.array ([y]), win=win,# Win to remain consistent update= ' append ')
Finally, the loss function visualization in the process of deep learning training is referred to the visual operation in the Pytorch Combat Guide.
Visualize the loss function in the visual_loss.py file:
#coding: Utf8import visdomimport timeimport NumPy as NP class Visualizer (object): Def __init__ (self, env= ' default ', **kwar GS): Self.vis = Visdom. Visdom (env=env, Www.yundingyule.cn**kwargs) Self.index = {} def plot_many_stack (self, D): "' Self.plot ( Www.yigou521.com ' loss ', 1.00) ' Name=list (D.keys ()) name_total= "". Join (name) x = Self.index.get (name_www.thd540.com Total, 0) val=list (d.values (www.baidu620.com/)) If Len (Val) ==1:y=np.array (Val) Else:y=np.array (Val). Reshape ( -1,len ( val)) #print (x) self.vis.line (Y=y,x=np.ones (y.shape) *x, Win=str (name_total), #unicode opts=dict (Legend=name, title= Name_total), update=none if x = = 0 Else ' append ') self.index[name_total] = x + 1
function function test in Jupyter NOTEBOOK--LOSS_VISUAL_TEST.IPYNB:
From Visual_loss import visualizerfrom torchnet import meter# use Torchnet to store the loss function, if not, install Conda installation torchnet ' ' Pre-training model, The loss function is set vis = Visualizer (env= ' my_wind ') #为了可视化增加的内容loss_meter = meter. Averagevaluemeter () #为了可视化增加的内容for epoch in range: #每个epoch开始前, clear the stored loss, restart recording Loss_ Meter.reset () #为了可视化增加的内容 Model.train () for II, (Data,label) in Enumerate (Trainloader): ... Out=model (input) loss=. .. Loss_meter.add (loss.data[0]) #为了可视化增加的内容 # Loss visualization #loss_meter. Value () [0] Returns the mean value of the stored loss Vis.plot_many_stack ({' Train_loss ': Loss_ Meter.value () [0]}) #为了可视化增加的内容 "#示例vis = Visualizer (env= ' my_wind ') #为了可视化增加的内容loss_meter = meter. Averagevaluemeter () #为了可视化增加的内容for epoch in range: Loss_meter.reset () #为了可视化增加的内容 LosS_meter.add (Epoch) #假设loss =epoch vis.plot_many_stack ({' Train_loss ': Loss_meter.value () [0]}) # To visualize the added content #如果还想同时显示test loss, follow the same pattern and assign values as a dictionary, as follows. You can also display both the train and the test accuracy #vis. Plot_many_stack ({' Train_loss ': Loss_meter.value () [0], ' test_loss ': Test_loss_ Meter.value () [0]}) #为了可视化增加的内容
File structure:
where __init__.py is empty
Note: My visdom version is
I do not know which one to use, through the Conda install Visdom installed version is older, the latest version of the official website is
The installation method is in the terminal input
Conda install-c SRIVASV Visdom
---------------------
This article from lxx516 's CSDN blog, full-text address please click: 79019328?utm_source=copy
Pytorch can be used as a visualization tool under the Visidom