-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_train_val.py
executable file
·52 lines (43 loc) · 1.56 KB
/
plot_train_val.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import matplotlib.pyplot as plt
from matplotlib import rc
plt.rcParams['mathtext.fontset'] = 'stix'
plt.rcParams['font.family'] = 'STIXGeneral'
# rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
## for Palatino and other serif fonts use:
#rc('font',**{'family':'serif','serif':['Palatino']})
rc('text', usetex=True)
experiment_folder = './output'
def load_json_arr(json_path):
lines = []
with open(json_path, 'r') as f:
for line in f:
lines.append(json.loads(line))
return lines
experiment_metrics = load_json_arr(experiment_folder + '/metrics.json')
# plt.plot(
# [x['iteration'] for x in experiment_metrics],
# [x['total_loss'] for x in experiment_metrics])
# plt.plot(
# [x['iteration'] for x in experiment_metrics if 'validation_loss' in x],
# [x['validation_loss'] for x in experiment_metrics if 'validation_loss' in x])
# plt.legend(['total_loss', 'validation_loss'], loc='upper left')
# plt.show()
# for x in experiment_metrics:
# print(x['total_loss'])
fig = plt.figure()
plt.plot(
[x['iteration'] for x in experiment_metrics],
[x['total_loss'] for x in experiment_metrics])
plt.plot(
[x['iteration'] for x in experiment_metrics if 'total_val_loss' in x],
[x['total_val_loss'] for x in experiment_metrics if 'total_val_loss' in x])
plt.legend(['total train loss', 'total val loss'], loc='upper right')
plt.xlabel('Iterations')
plt.ylabel('Loss')
fig.tight_layout()
# plt.title('Training Loss')
plt.grid(b=True, linestyle=':')
plt.show()