-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_loss_1.py
44 lines (40 loc) · 1.45 KB
/
draw_loss_1.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
import re
import matplotlib.pyplot as plt
import os.path as osp
fullpath = osp.abspath('/home/datasets/Pancreas82NIH/logs/FD0:X3_1_20211101_191714.txt')
# mode = {'Loss'}
mode = {'Coarse', 'Fine', 'Avg'}
#ipdb.set_trace()
filedir, filename = osp.split(fullpath)
count = 0
Coarse, Fine, Avg, x = [], [], [], []
with open(fullpath, 'r') as f:
rbsh = f.readline()
while True:
line = f.readline()
if line == '':
break
if not line.startswith('0X'):
continue
count += 1
ipdb.set_trace()
line = line.replace(' ', '').replace('\t', '')
pattern = re.compile(r'\w*.\w+')
find_list = pattern.findall(line)
if mode == {'Loss'}:
Loss.append(float(find_list[0]))
elif mode == {'Coarse', 'Fine', 'Avg'}:
Coarse.append(float(find_list[0]))
Fine.append(float(find_list[1]))
Avg.append(float(find_list[2]))
x.append(count)
pngName = filename.split('.')[0]
if mode == {'Loss'}:
plt.plot(x, Loss)
elif mode == {'Coarse', 'Fine', 'Avg'}:
plt.plot(x, Coarse, color='red', marker='o', linestyle='dashed', linewidth=2, markersize=1)
plt.plot(x, Fine, color='green', marker='o', linestyle='dashed', linewidth=2, markersize=1)
plt.plot(x, Avg, color='blue', marker='o', linestyle='dashed', linewidth=2, markersize=1)
plt.legend(labels=('Coarse', 'Fine', 'Avg'))
plt.savefig(osp.join(filedir, pngName))
plt.show()