-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
74 lines (66 loc) · 1.62 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
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
import matplotlib
import matplotlib.pyplot as plt
import glob as glob
import os
matplotlib.style.use('ggplot')
def save_plots(
train_acc, valid_acc, train_loss, valid_loss,
acc_PLOT_DIR, loss_PLOT_DIR
):
"""
Function to save the loss and accuracy plots to disk.
"""
# Accuracy plot
plt.figure(figsize=(10, 7))
plt.plot(
train_acc, color='green', linestyle='-',
label='train accuracy'
)
plt.plot(
valid_acc, color='blue', linestyle='-',
label='validation accuracy'
)
plt.xlabel('Epochs')
plt.ylabel('Accuracy')
plt.legend()
plt.savefig(acc_PLOT_DIR)
# Loss plots.
plt.figure(figsize=(10, 7))
plt.plot(
train_loss, color='orange', linestyle='-',
label='train loss'
)
plt.plot(
valid_loss, color='red', linestyle='-',
label='validation loss'
)
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
plt.savefig(loss_PLOT_DIR)
def save_plots_kfold(
train_acc, train_loss, acc_PLOT_DIR, loss_PLOT_DIR
):
"""
Function to save the loss and accuracy plots to disk.
"""
# Accuracy plot
plt.figure(figsize=(10, 7))
plt.plot(
train_acc, color='green', linestyle='-',
label='train accuracy'
)
plt.xlabel('Epochs')
plt.ylabel('Accuracy')
plt.legend()
plt.savefig(acc_PLOT_DIR)
# Loss plot
plt.figure(figsize=(10, 7))
plt.plot(
train_loss, color='orange', linestyle='-',
label='train loss'
)
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
plt.savefig(loss_PLOT_DIR)