-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
50 lines (37 loc) · 1.2 KB
/
utils.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
import os
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
# make file
def test_mkdir(path):
if not os.path.isdir(path):
os.mkdir(path)
# keep a record to training procedure
def record_train(writer, L, loss, train_acc, acc, T, t):
writer.add_scalar('training loss', loss, t)
writer.add_scalar('training accuracy', acc, t)
L.append(loss)
train_acc.append(acc)
T.append(t)
def record_test(writer, test_acc, acc, T, t):
writer.add_scalar('test accuracy', acc, t)
test_acc.append(acc)
T.append(t)
def make_curve(train_loss, train_acc, test_acc, train_t, test_t, save_path):
plt.title('train accuracy')
plt.xlabel('iters')
plt.ylabel('accuracy')
plt.plot(train_t, train_acc, color='green')
plt.savefig(os.path.join(save_path, 'train_acc.png'))
plt.cla()
plt.title('train loss')
plt.xlabel('iters')
plt.ylabel('loss')
plt.plot(train_t, train_loss, color='red')
plt.savefig(os.path.join(save_path, 'train_loss.png'))
plt.cla()
plt.title('test accuracy')
plt.xlabel('iters')
plt.ylabel('accuracy')
plt.plot(test_t, test_acc, color='green')
plt.savefig(os.path.join(save_path, 'test_acc.png'))