-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloss_plot.py
53 lines (43 loc) · 1.67 KB
/
loss_plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import re
import matplotlib.pyplot as plt
import pandas as pd
loss_filenames = ["losses_sim_1575781367.650115.txt", "losses_vgg_1575624281.130714.txt", "losses_1575458071.3440142.txt"]
#loss_filename = "losses_1575458071.3440142.txt"
#loss_filename = "losses_vgg_1575624281.130714.txt"
#loss_filename = "losses_sim_1575781367.650115.txt"
for loss_filename in loss_filenames:
rgx = r'\[[-?0-9.]*\]'
disc_loss = []
gen_loss = []
with open(loss_filename, "r+") as f:
for line in f.readlines():
try:
nums = re.findall(rgx, line)
disc = float(nums[2][1:-1])
gen = float(nums[3][1:-1])
disc_loss.append(disc)
gen_loss.append(gen)
except IndexError:
pass
#df=pd.DataFrame({'x_disc': range(len(disc_loss)), 'x_gen': range(len(gen_loss)), 'disc_loss': disc_loss, 'gen_loss': gen_loss})
#plt.plot('x_disc', 'disc_loss', data=df, marker='', color='blue', linewidth=2)
#plt.plot('x_gen', 'gen_loss', data=df, marker='', color='orange', linewidth=2)
#plt.legend()
plt.plot(range(len(disc_loss)),disc_loss)
plt.xlabel('iterations')
plt.ylabel('loss')
plt.title('Discriminator Model Loss')
plt.legend(['disc loss'])
plt.savefig(loss_filename[:-4]+'_discriminator'+'.png')
print('Saved figure at {}'.format(loss_filename[:-4]+'_discriminator'+'.png'))
plt.close()
plt.plot(range(len(gen_loss)), gen_loss)
plt.xlabel('iterations')
plt.ylabel('loss')
if loss_filename[7] == 's':
plt.ylim(-14, 1)
plt.title('Generator Model Loss')
plt.legend(['gen loss'])
plt.savefig(loss_filename[:-4]+'_generator'+'.png')
print('Saved figure at {}'.format(loss_filename[:-4]+'_generator'+'.png'))
plt.close()