-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
67 lines (53 loc) · 1.64 KB
/
Copy pathplot.py
File metadata and controls
67 lines (53 loc) · 1.64 KB
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
import os
import matplotlib.pyplot as plt
def isplit_by_n(ls, n):
for i in range(0, len(ls), n):
if i + n >= len(ls):
yield sum(ls[i:-1]) / (len(ls) - i)
else:
yield sum(ls[i:i + n]) / n
def split_by_n(ls, n):
return list(isplit_by_n(ls, n))
def plot_bs():
path = 'logs/agnews/bs/'
file_list = os.listdir(path)
for file in file_list:
if file.endswith('.out'):
f = open(path + file, 'r')
data = [float(line.rstrip()) for line in f]
f.close()
avg_data = split_by_n(data, 50)
n = len(avg_data)
y = avg_data
x = [i / n * 100 for i in range(1, n + 1)]
plt.plot(x, y, label=file[-6:-4])
plt.title('Training Loss vs Step by different Batch Size')
plt.ylabel('Loss')
plt.xlabel('Step (%)')
plt.legend()
plt.ylim(0.20, 0.5)
plt.show()
def plot_lr():
path = 'logs/agnews/lr/'
file_list = os.listdir(path)
for file in file_list:
if file.endswith('.out'):
f = open(path + file, 'r')
data = [float(line.rstrip()) for line in f]
f.close()
avg_data = split_by_n(data, 50)
n = len(avg_data)
y = avg_data
x = [i / n * 100 for i in range(1, n + 1)]
label = file[-7:-4]
label = label[:2] + '-' + label[2:]
plt.plot(x, y, label=label)
plt.title('Training Loss vs Step by different Learning Rate')
plt.ylabel('Loss')
plt.xlabel('Step (%)')
plt.legend()
plt.ylim(0.2, 1)
plt.show()
if __name__ == '__main__':
plot_bs()
plot_lr()