Repository navigation
Expand file tree
/
Copy pathplot.py
More file actions
127 lines (89 loc) · 2.98 KB
/
Copy pathplot.py
File metadata and controls
127 lines (89 loc) · 2.98 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""
Diego Zamora Rodriguez <dzamora@ucsd.edu>
Training log analyzer for the Deepcpg experiments
version 1.0.2
"""
import matplotlib.pyplot as plt
import numpy as np
import sys
def find_data(filename, text):
file = open(filename, "r")
i = 0
for line in file:
i = i + 1
if line.find(text) == 0:
print("Data found in line " + str(i+2))
return i+2
file.close()
def get_values(filename, start):
loss = []
acc = []
file = open(filename, "r")
for i, line in enumerate(file):
l = line.split()
try:
if i > (start-1):
loss.append(l[0])
acc.append(l[2])
if l[0] == "Validation":
break
except:
print("\n")
file.close()
if loss[-1] == "Validation" or acc[-1] == "performance:":
loss.pop()
acc.pop()
print("============== Values found ==============")
print(loss)
print(acc)
return [loss, acc]
def plot_acc(training, validation, no_epoch):
f = plt.figure()
X = np.array(list(range(no_epoch))) # epoch number
Y1 = np.array(training)
Y2 = np.array(validation)
plt.title('Accuracy performance visualization')
plt.ylabel('Performance')
plt.xlabel('Number of Epoch')
# plt.xlim(0, no_epoch)
# plt.ylim(0, 1.5)
plt.grid(True)
plt.plot(X, Y1, 's', color="red", label="Training")
plt.plot(X, Y2, 's', color="blue", label="Validation")
plt.legend()
plt.show()
f.savefig("plot_acc.pdf")
def plot_loss(training, validation, no_epoch):
f = plt.figure()
X = np.array(list(range(no_epoch))) # epoch number
Y1 = np.array(training)
Y2 = np.array(validation)
plt.title('Loss performance visualization')
plt.ylabel('Performance')
plt.xlabel('Number of Epoch')
# plt.xlim(0, no_epoch)
# plt.ylim(0, 1.5)
plt.grid(True)
plt.plot(X, Y1, 's', color="red", label="Training")
plt.plot(X, Y2, 's', color="blue", label="Validation")
plt.legend()
plt.show()
f.savefig("plot_loss.pdf")
def startup(filename):
training = "Training set performance:"
validation = "Validation set performance:"
training_start = find_data(filename, training)
validation_start = find_data(filename, validation)
training_values = get_values(filename, training_start)
validation_values = get_values(filename, validation_start)
no_epoch = len(training_values[0])
print("\n Number of epoch found: "+str(no_epoch))
plot_loss(training_values[0], validation_values[0], no_epoch)
plot_acc(training_values[1], validation_values[1], no_epoch)
# def save_pdf():
# f = plt.figure()
# plt.plot(range(10), range(10), "o")
# plt.show()
# f.savefig("", bbox_inches='tight')
if __name__ == "__main__":
startup(sys.argv[1])