-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcaffe_plot.py
More file actions
121 lines (87 loc) · 3.74 KB
/
caffe_plot.py
File metadata and controls
121 lines (87 loc) · 3.74 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
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 05 16:48:32 2016
@author: WuJianping
"""
import re
import matplotlib.pyplot as plt
def parser_log(logfile):
regex_iteration = re.compile('Iteration (\d+)')
regex_train_output_accuarcy = re.compile('Train net output #0: (\S+) = ([\.\deE+-]+)')
regex_train_output_loss = re.compile('Train net output #1: (\S+) = ([\.\deE+-]+)')
regex_test_output_accuarcy = re.compile('Test net output #0: (\S+) = ([\.\deE+-]+)')
regex_test_output_loss = re.compile('Test net output #1: (\S+) = ([\.\deE+-]+)')
regex_learning_rate = re.compile('lr = ([-+]?[0-9]*\.?[0-9]+([eE]?[-+]?[0-9]+)?)')
iteration = -1;
learning_rate = [[], []]
train_accuracy = [[], []]
train_loss = [[], []]
test_accuracy = [[], []]
test_loss = [[], []]
with open(logfile, "r") as fp:
for line in fp:
# print line
iteration_match = regex_iteration.search(line)
if iteration_match:
iteration = int(iteration_match.group(1))
if -1 == iteration:
continue;
# print iteration
learning_rate_match = regex_learning_rate.search(line)
if learning_rate_match:
lr = float(learning_rate_match.group(1))
# print lr
learning_rate[0].append(iteration)
learning_rate[1].append(lr)
train_accuracy_match = regex_train_output_accuarcy.search(line)
if train_accuracy_match:
trainacc = float(train_accuracy_match.group(2))
train_accuracy[0].append(iteration)
train_accuracy[1].append(trainacc)
train_loss_match = regex_train_output_loss.search(line)
if train_loss_match:
trainloss = float(train_loss_match.group(2))
train_loss[0].append(iteration)
train_loss[1].append(trainloss)
test_accuracy_match = regex_test_output_accuarcy.search(line)
if test_accuracy_match:
testacc = float(test_accuracy_match.group(2))
test_accuracy[0].append(iteration)
test_accuracy[1].append(testacc)
test_loss_match = regex_test_output_loss.search(line)
if test_loss_match:
testloss = float(test_loss_match.group(2))
test_loss[0].append(iteration)
test_loss[1].append(testloss)
return learning_rate, train_accuracy, train_loss, test_accuracy, test_loss
def caffe_plot(logfile):
learning_rate, train_accuracy, train_loss, test_accuracy, test_loss = parser_log(logfile)
plt.figure(1)
plt.title('loss vs iter')
plt.xlabel("iter")
plt.ylabel("loss")
plt.plot(test_loss[0], test_loss[1], 'b-', label='test loss')
plt.plot(train_loss[0], train_loss[1], 'r-', label='train loss')
plt.legend()
plt.show()
plt.savefig(r'D:\loss.png')
plt.figure(2)
plt.title("accuracy vs iter")
plt.xlabel("iter")
plt.ylabel("accuracy")
plt.plot(test_accuracy[0], test_accuracy[1], 'b-', label = 'test accuracy')
plt.plot(train_accuracy[0], train_accuracy[1], 'r-', label = 'train accuracy')
plt.legend()
plt.show()
plt.savefig(r'D:\accuracy.png')
plt.figure(3)
plt.title("lr vs iter")
plt.xlabel("iter")
plt.ylabel("learning rate")
plt.plot(learning_rate[0], learning_rate[1], 'b-', label = 'learning rate')
plt.legend()
plt.show()
plt.savefig(r'D:\learning_rate.png')
if __name__ == '__main__':
logfile = r"E:\DATA\FaceData\log\INFO2016-07-12T07-45-24_srcimg.txt"
caffe_plot(logfile)