-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathplot.py
63 lines (54 loc) · 1.9 KB
/
plot.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
import matplotlib.pyplot as plt
import numpy as np
def saveplot(collection, title, savename, moving_alpha = 0.9):
x = np.arange(0, len(collection)-1)
collection = [collection[i]*moving_alpha+collection[i+1]*(1-moving_alpha) for i in range(len(collection)-1)]
plt.plot(x, collection)
plt.title('%s - iteration curve'%title)
plt.xlabel('iteration')
plt.ylabel(title)
plt.savefig(savename)
plt.close('all')
return
def plot(collection, title, moving_alpha = 0.9):
x = np.arange(0, len(collection)-1)
collection = [collection[i]*moving_alpha+collection[i+1]*(1-moving_alpha) for i in range(len(collection)-1)]
plt.plot(x, collection)
plt.title('%s - iteration curve'%title)
plt.xlabel('iteration')
plt.ylim(0,1)
plt.ylabel(title)
plt.show()
if __name__ == "__main__":
from glob import glob
filelist = glob('logs/*.txt')
print filelist
moving_alpha = 0.9
plt.figure(figsize=(4,3))
for file in filelist:
name = file.split('/')[-1].split('.')[0]
print name
f = open(file).readlines()
acc = []
loss = []
for line in f:
try:
acc.append(float(line.split(',')[2].split(' ')[2]))
loss.append(float(line.split(',')[2].split(' ')[5]))
except:
pass
loss = loss[0:101]
loss = [loss[i] * moving_alpha + loss[i + 1] * (1 - moving_alpha) for i in
range(len(loss) - 1)]
acc = acc[0:101]
acc = [acc[i] * moving_alpha + acc[i + 1] * (1 - moving_alpha) for i in
range(len(acc) - 1)]
x = range(0,len(acc))
plt.plot(x,acc,label=name.split('_')[1])
plt.xlabel('iteration(50batch)')
plt.ylabel('acc')
# plt.ylim(0,1)
plt.title('acc-iteration curve')
plt.legend(loc='lower right')
plt.savefig('fig/method-acc.jpg',dpi=100)
plt.show()