-
Notifications
You must be signed in to change notification settings - Fork 9
/
plot_loss.py
49 lines (41 loc) · 1.32 KB
/
plot_loss.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 argparse
import matplotlib.pyplot as plt
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument("--input", type=str, help="path to the log")
arg_parser.add_argument("--output", type=str, help="directory to save loss curves")
args = arg_parser.parse_args()
if not os.path.exists(args.output):
os.makedirs(args.output)
def main():
loss_dict = dict()
for line in open(args.input):
if "Epoch:" in line:
continue
else:
info = line.rstrip().split(" ")
prefix = info[0][1:-1]
for i in range(1, len(info)):
try:
value = float(info[i])
except ValueError:
continue
key = prefix + "_" + info[i-1].replace(":", "")
if not key in loss_dict:
loss_dict[key] = list()
loss_dict[key].append(value)
for k, v in loss_dict.items():
curve_path = os.path.join(args.output, k + ".png")
"""
new_v = list()
l = 10
for i in range(l, len(v) - l):
new_v.append(sum(v[i-l:i+l]) / (2 * l))
"""
new_v = v
plt.plot(list(range(len(new_v))), new_v)
plt.title(k)
plt.savefig(curve_path)
plt.clf()
if __name__ == '__main__':
main()