forked from martinkersner/train-DeepLab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loss_from_log.py
executable file
·158 lines (122 loc) · 4.97 KB
/
loss_from_log.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python
# Martin Kersner, 2016/03/11
from __future__ import print_function
import sys
import re
import numpy as np
import matplotlib.pyplot as plt
from utils import strstr
def main():
output_data, log_files = process_arguments(sys.argv)
train_iteration = []
train_loss = []
train_accuracy0 = []
train_accuracy1 = []
train_accuracy2 = []
train_accuracy3 = []
train_accuracy4 = []
train_accuracy5 = []
base_train_iter = 0
for log_file in log_files:
with open(log_file, 'rb') as f:
if len(train_iteration) != 0:
base_train_iter = train_iteration[-1]
for line in f:
if strstr(line, 'Iteration') and strstr(line, 'loss'):
matched = match_loss(line)
train_loss.append(float(matched.group(1)))
matched = match_iteration(line)
train_iteration.append(int(matched.group(1))+base_train_iter)
# strong labels
elif strstr(line, 'Train net output #0: accuracy '):
matched = match_net_accuracy(line)
train_accuracy0.append(float(matched.group(1)))
elif strstr(line, 'Train net output #1: accuracy '):
matched = match_net_accuracy(line)
train_accuracy1.append(float(matched.group(1)))
elif strstr(line, 'Train net output #2: accuracy '):
matched = match_net_accuracy(line)
train_accuracy2.append(float(matched.group(1)))
# weak labels
elif strstr(line, 'Train net output #0: accuracy_bbox'):
matched = match_net_accuracy_bbox(line)
train_accuracy0.append(float(matched.group(1)))
elif strstr(line, 'Train net output #1: accuracy_bbox'):
matched = match_net_accuracy_bbox(line)
train_accuracy1.append(float(matched.group(1)))
elif strstr(line, 'Train net output #2: accuracy_bbox'):
matched = match_net_accuracy_bbox(line)
train_accuracy2.append(float(matched.group(1)))
elif strstr(line, 'Train net output #3: accuracy_strong'):
matched = match_net_accuracy_strong(line)
train_accuracy3.append(float(matched.group(1)))
elif strstr(line, 'Train net output #4: accuracy_strong'):
matched = match_net_accuracy_strong(line)
train_accuracy4.append(float(matched.group(1)))
elif strstr(line, 'Train net output #5: accuracy_strong'):
matched = match_net_accuracy_strong(line)
train_accuracy5.append(float(matched.group(1)))
if output_data == 'loss':
for x in train_loss:
print(x)
if output_data == 'acc1':
for x,y,z in zip(train_accuracy0, train_accuracy1, train_accuracy2):
print(x, y, z)
if output_data == 'acc2':
for x,y,z in zip(train_accuracy3, train_accuracy4, train_accuracy5):
print(x, y, z)
## loss
plt.plot(train_iteration, train_loss, 'k', label='Train loss')
plt.legend()
plt.ylabel('Loss')
plt.xlabel('Number of iterations')
plt.savefig('loss.png')
## evaluation
plt.clf()
if len(train_accuracy3) != 0:
plt.plot(range(len(train_accuracy0)), train_accuracy0, 'k', label='accuracy bbox 0')
plt.plot(range(len(train_accuracy1)), train_accuracy1, 'r', label='accuracy bbox 1')
plt.plot(range(len(train_accuracy2)), train_accuracy2, 'g', label='accuracy bbox 2')
plt.plot(range(len(train_accuracy3)), train_accuracy3, 'b', label='accuracy strong 0')
plt.plot(range(len(train_accuracy4)), train_accuracy4, 'c', label='accuracy strong 1')
plt.plot(range(len(train_accuracy5)), train_accuracy5, 'm', label='accuracy strong 2')
else:
plt.plot(range(len(train_accuracy0)), train_accuracy0, 'k', label='train accuracy 0')
plt.plot(range(len(train_accuracy1)), train_accuracy1, 'r', label='train accuracy 1')
plt.plot(range(len(train_accuracy2)), train_accuracy2, 'g', label='train accuracy 2')
plt.legend(loc=0)
plt.savefig('evaluation.png')
def match_iteration(line):
return re.search(r'Iteration (.*),', line)
def match_loss(line):
return re.search(r'loss = (.*)', line)
def match_net_accuracy(line):
return re.search(r'accuracy = (.*)', line)
def match_net_accuracy_bbox(line):
return re.search(r'accuracy_bbox = (.*)', line)
def match_net_accuracy_strong(line):
return re.search(r'accuracy_strong = (.*)', line)
def process_arguments(argv):
if len(argv) < 3:
help()
output_data = None
log_files = argv[2:]
if argv[1].lower() == 'loss':
output_data = 'loss'
elif argv[1].lower() == 'acc1':
output_data = 'acc1'
elif argv[1].lower() == 'acc2':
output_data = 'acc2'
else:
log_files = argv[1:]
return output_data, log_files
def help():
print('Usage: python loss_from_log.py OUTPUT_TYPE [LOG_FILE]+\n'
'OUTPUT_TYPE can be either loss, acc1 or acc 2\n'
'LOG_FILE is text file containing log produced by caffe.\n'
'At least one LOG_FILE has to be specified.\n'
'Files has to be given in correct order (the oldest logs as the first ones).'
, file=sys.stderr)
exit()
if __name__ == '__main__':
main()