-
Notifications
You must be signed in to change notification settings - Fork 1
/
log_report.py
82 lines (66 loc) · 2.13 KB
/
log_report.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
import json
import os
import numpy as np
import matplotlib as mpl
mpl.use('Agg')
from matplotlib import pyplot as plt
class LogReport():
def __init__(self, log_dir, log_name='log'):
self.log_dir = log_dir
self.log_name = log_name
self.log_ = []
def __call__(self, log):
self.log_.append(log)
with open(os.path.join(self.log_dir, self.log_name), 'w') as f:
json.dump(self.log_, f, indent=4)
def save_lossgraph(self):
epoch = []
gen_loss = []
dis_loss = []
for l in self.log_:
epoch.append(l['epoch'])
gen_loss.append(l['gen/loss'])
dis_loss.append(l['dis/loss'])
epoch = np.asarray(epoch)
gen_loss = np.asarray(gen_loss)
dis_loss = np.asarray(dis_loss)
plt.plot(epoch, gen_loss)
plt.xlabel('epoch')
plt.ylabel('loss_gen')
plt.savefig(os.path.join(self.log_dir, 'lossgraph_gen.pdf'))
plt.close()
plt.plot(epoch, dis_loss)
plt.xlabel('epoch')
plt.ylabel('loss_dis')
plt.savefig(os.path.join(self.log_dir, 'lossgraph_dis.pdf'))
plt.close()
class TestReport():
def __init__(self, log_dir, log_name='log_test'):
self.log_dir = log_dir
self.log_name = log_name
self.log_ = []
def __call__(self, log):
self.log_.append(log)
with open(os.path.join(self.log_dir, self.log_name), 'w') as f:
json.dump(self.log_, f, indent=4)
def save_lossgraph(self):
epoch = []
mse = []
psnr = []
for l in self.log_:
epoch.append(l['epoch'])
mse.append(l['mse'])
psnr.append(l['psnr'])
epoch = np.asarray(epoch)
mse = np.asarray(mse)
psnr = np.asarray(psnr)
plt.plot(epoch, mse)
plt.xlabel('epoch')
plt.ylabel('mse')
plt.savefig(os.path.join(self.log_dir, 'graph_mse.pdf'))
plt.close()
plt.plot(epoch, psnr)
plt.xlabel('epoch')
plt.ylabel('psnr')
plt.savefig(os.path.join(self.log_dir, 'graph_psnr.pdf'))
plt.close()