-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparse_logs.py
60 lines (54 loc) · 1.59 KB
/
parse_logs.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
import numpy as np
import matplotlib.pyplot as plt
import os
import argparse
import re
import codecs
def parse_log(fname, dt=False):
with open(fname, 'r', encoding='cp850') as f:
lines = f.readlines()
epochs = []
epoch = 0
training_loss = []
validation_loss = []
for line in lines:
if (dt):
txt = re.split("{+|,+|:+|}+|'+| +", line)
if ('learning_rate' in line and 'epoch' in line):
train_loss = float(txt[5])
epoch = float(txt[17])
epochs.append(epoch)
training_loss.append(train_loss)
else:
if ("Epoch" in line):
epoch += 1
epochs.append(epoch)
if ("Training loss" in line):
txt = line.split(' ')
loss = float(txt[2])
training_loss.append(loss)
if ("Validation loss" in line):
txt = line.split(' ')
loss = float(txt[2])
validation_loss.append(loss)
plt.figure()
plt.plot(epochs, training_loss, label='Train')
if (not dt):
plt.plot(epochs, validation_loss, label='Validation')
# plt.title('Loss history')
plt.ylabel('Loss')
plt.xlabel('Epoch')
plt.grid(True)
plt.legend(loc='best')
logname = os.path.splitext(os.path.basename(fname))[0]
plt.savefig('log_{}.png'.format(logname), dpi=300)
parser = argparse.ArgumentParser()
parser.add_argument(
'fname'
)
parser.add_argument(
'--dt',
action='store_true'
)
args = parser.parse_args()
parse_log(args.fname, args.dt)