绘制后台执行训练模型的图

如果没有使用tensor board这样的可视化训练模型的框架,但是还是想要知道训练的过程中指标的状态

下面这个代码演示的是,gan的后台训练的可视化代码,因为我们直接使用nohup执行,而未指定名称,默认追加的日志文件名为nohup.out

思路十分简单,使用正则去匹配相对于的数据,然后进行绘制

具体代码如下:

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()

猜你喜欢

转载自blog.csdn.net/zhou_438/article/details/111568040