テンソルボードなどの視覚的なトレーニングモデルフレームワークを使用していないが、トレーニングプロセス中のインジケーターのステータスを知りたい場合
次のコードは、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()