-
Notifications
You must be signed in to change notification settings - Fork 8
/
parseLog.py
95 lines (74 loc) · 2.98 KB
/
parseLog.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
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
'''
Parses a log file as created by caffe and plots learning curves.
Lars Roemheld, [email protected]
'''
__author__ = 'Lars Roemheld'
import re
import matplotlib.pyplot as plt
import sys
import numpy as np
import math
phases = ['Train', 'Test']
metrics = [(' net output #0: accuracy = (.*)', ' global acc.'),
(' net output #1: loss = (.*) \(\*', ' loss'),
(' net output #2: per_class_accuracy = (.*)', ' nolabel acc.'),
(' net output #3: per_class_accuracy = (.*)', ' building acc.'),
(' net output #4: per_class_accuracy = (.*)', ' road acc.'),
(' net output #5: per_class_accuracy = (.*)', ' farm acc.'),
(' net output #6: per_class_accuracy = (.*)', ' wetland acc.'),
(' net output #7: per_class_accuracy = (.*)', ' forest acc.'),
(' net output #8: per_class_accuracy = (.*)', ' water acc.')]
regexes = {}
data = {}
for ph in phases:
for m in metrics:
regexes[ph, m] =re.compile(ph + m[0])
data[ph, m] = []
filename = sys.argv[1]
print "important params: filename {} ".format(filename)
with open(filename, 'r') as f:
for line in f:
for ph in phases:
for m in metrics:
match = regexes[ph, m].search(line)
if match is not None:
data[ph, m].append(float(match.group(1)))
# Running average smoothing. Must be 1 or even for the average-padding to work.
printiters = 10
testiters = 120
epochiters = 120
N = {}
N['Test'] = 1 #int(math.ceil(epochiters / 2.0 / testiters))
N['Train'] = int(math.ceil(epochiters / 2.0 / printiters))
print "important params: Moving average over iters:"
print N
for ph in phases:
for m in metrics:
if N[ph] > 1:
data[ph, m] = [np.average(data[ph, m][0:N[ph]/2])] * (N[ph]/2-1) + data[ph, m]
data[ph, m] = data[ph, m] + [np.average(data[ph, m][-N[ph]/2:])] * (N[ph]/2-1)
data[ph, m] = np.array(data[ph, m])
data[ph, m] = np.convolve(data[ph, m], np.ones((N[ph],))/N[ph], mode='valid')
# Test phase does not check at iteration 0?
if 'Test' in phases:
print "Prepending 0 for test metrics, since no testing is performed on iter=0"
for m in metrics:
data['Test', m] = [0] + data['Test', m]
x = {}
print "important params: print every {} iters, test every {} iters.".format(printiters, testiters)
x['Train'] = range(0, len(data['Train', metrics[0]]) * printiters, printiters)
x['Test'] = range(0, len(data['Test', metrics[0]]) * testiters, testiters)
fig = plt.figure()
fig.patch.set_facecolor('white')
nc = len(phases)
nr = len(metrics)
print "important params: {} iters = 1 epoch.".format(epochiters)
for r, m in enumerate(metrics):
for c, ph in enumerate(phases):
plt.subplot(nr, nc, r * nc + c + 1)
plt.gca().set_axis_bgcolor('white')
plt.plot(x[ph], data[ph, m])
for xx in range(epochiters, max(x[ph])+1, epochiters):
plt.axvline(xx, color='r', linestyle='--')
plt.title(ph + m[1])
plt.show()