-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_results.py
More file actions
104 lines (94 loc) · 3.06 KB
/
plot_results.py
File metadata and controls
104 lines (94 loc) · 3.06 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import pandas as pd
import matplotlib.pyplot as plt
from numpy import arange
from sys import argv
filenames = []
average_p_col = False
df_list = []
x_len = 0
x_steps = 5
col_w = 8
col_h = 8
for i in range(1, len(argv)):
filenames.append(argv[i])
if (len(filenames) == 0):
filenames.extend(input("Enter file name(s): ").split())
if (len(filenames) > 1):
average_p_col = int(input("1. Average results\n2. Show as subplots\nChoose: ")) == 1
win_size = int(input("Enter window size: "))
for file in filenames:
print("Reading", file, "as CSV file...")
df = pd.read_csv(file, names=['d_loss_real','d_loss_fake','g_loss', 'd_acc_real', 'd_acc_fake','FID'])
#print(df.head())
df = df.fillna(method='ffill')
#print(df.head())
df = df.rolling(win_size).mean()
df_list.append(df)
if (average_p_col):
print("Averaging results...")
df = df_list[0]
# sum dataframes
for i in range(1, len(df_list)):
df += df_list[i]
df = df / len(df_list)
df_list = [df]
for df in df_list:
if (df.shape[0] > x_len):
x_len = df.shape[0]
if (len(df_list) > 1):
plot, ax = plt.subplots(len(df_list), 4, figsize=(col_w*len(df_list), col_h))
for i in range(len(df_list)):
ax[i, 0].plot(df_list[i][['d_loss_real','d_loss_fake','g_loss']])
ax[i, 0].legend(('d_loss_real','d_loss_fake','g_loss'))
ax[i, 0].set_ylim(top=5)
ax[i, 0].set_ylabel('loss')
ax[i, 1].plot(df_list[i][['d_acc_real', 'd_acc_fake']])
ax[i, 1].legend(('d_acc_real', 'd_acc_fake'))
ax[i, 1].set_ylim(top=1)
ax[i, 1].set_ylabel('accuracy')
ax[i, 2].plot(df_list[i]['FID'])
ax[i, 2].set_ylim(top=8)
ax[i, 2].set_ylabel('FID')
ax[i, 3].plot((df_list[i]['g_loss'] / ((df_list[i]['d_loss_fake'] + df_list[i]['d_loss_real']) / 2)))
ax[i, 3].set_ylim(top=10)
ax[i, 3].set_ylabel('Loss ratio')
for i in range(len(ax)):
ax[i, 0].set_title(filenames[i], loc='left')
for a in ax[i]:
a.set_xlabel('number of batches')
a.set_xlim(right=x_len)
a.set_xticks(arange(0, x_len+1, x_len//x_steps, dtype=int))
a.set_ylim(bottom=0)
else:
choice = int(input('1. all plots\n2. loss only\n3. accuracy only\n4. FID only\n5. Loss ratio\nChoose: '))
if (choice == 1):
plot, sub = plt.subplots(3, figsize=(col_w, col_h))
sub[0].plot(df[['d_loss_real','d_loss_fake','g_loss']])
sub[0].legend(('d_loss_real','d_loss_fake','g_loss'))
sub[0].set_ylabel('loss')
sub[1].plot(df[['d_acc_real', 'd_acc_fake']])
sub[1].legend(('d_acc_real', 'd_acc_fake'))
sub[1].set_ylabel('accuracy')
sub[2].plot(df['FID'])
sub[2].set_ylabel('FID')
for s in sub:
s.set_xlabel('number of batches')
s.set_ylim(bottom=0)
else:
if (choice == 2):
df[['d_loss_real','d_loss_fake','g_loss']].plot()
plt.ylabel('loss')
elif (choice == 3):
df[['d_acc_real', 'd_acc_fake']].plot()
plt.ylabel('accuracy')
elif (choice == 4):
df['FID'].plot()
plt.ylabel('FID')
elif (choice == 5):
(df['g_loss'] - ((df['d_loss_fake'] + df['d_loss_real'])/2)).plot()
plt.ylim(top=1.5)
plt.ylabel('Loss ratio')
plt.xlabel('number of batches')
plt.ylim(bottom=0)
plt.subplots_adjust(left=0.08, right=0.92, hspace=0.5, wspace=0.2)
plt.show()