Draw a diagram of the background execution training model

If you do not use a visual training model framework such as tensor board, but you still want to know the status of the indicators during the training process

The following code demonstrates the visualization code of gan's background training. Because we directly use nohup to execute without specifying a name, the log file appended by default is named nohup.out

The idea is very simple, use regular to match the relative data, and then draw

The specific code is as follows:

import re
import matplotlib.pyplot as plt

#read log data
_data = open('nohup.out').read()
#get g_loss data
g_loss_data=re.findall("g_loss: \d+.\d+",_data)
g_loss_s=[eval(i.replace('g_loss: ',''))for i in g_loss_data]
#get d_loss data
d_loss_data=re.findall("d_loss: \d+.\d+",_data)
d_loss_s=[eval(i.replace('d_loss: ',''))for i in d_loss_data]
#get spend time data
time_data=re.findall("time: \d+.\d+",_data)
time_s=[eval(i.replace('time: ',''))for i in time_data]
x=[i+1 for i  in range(len(g_loss_s))]

plt.figure()
plt.subplot(3,1,1)
plt.xlabel("epoch") 
plt.ylabel("g_loss") 
plt.plot(x,g_loss_s)

plt.subplot(3,1,2)
plt.xlabel("epoch") 
plt.ylabel("d_loss") 
plt.plot(x,d_loss_s)

plt.subplot(3,1,3)
plt.xlabel("epoch") 
plt.ylabel("time") 
plt.plot(x,time_s)

plt.tight_layout()
plt.show()

 

Guess you like

Origin blog.csdn.net/zhou_438/article/details/111568040