-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvis.py
More file actions
59 lines (48 loc) · 1.37 KB
/
Copy pathvis.py
File metadata and controls
59 lines (48 loc) · 1.37 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
#import imageio
import os
import numpy as np
import matplotlib.pyplot as plt
save_path = 'vis'
with open('progress.txt', 'r') as f:
lines = f.read().splitlines()
for i,l in enumerate(lines):
lines[i] = l.split('\t')
if not os.path.exists(save_path):
os.mkdir(save_path)
i_x = lines[0].index('Epoch')
lines = np.array(lines)
x = lines[1:, i_x].astype(np.int)
#print(x)
for i in range(0, lines.shape[1]):
yname = lines[0,i]
xname = 'steps * 1000'
plt.xlabel(xname)
plt.ylabel(yname)
y = lines[1:, i]
if y[1] == '':
for j in range(1, len(y)):
if y[j] == '':
y[j] = y[j-1]
plt.plot(x, y.astype(np.float))
plt.savefig(os.path.join(save_path, yname+'.png'))
plt.cla()
# smooth the curves
def smooth(arr, weight=0.9): #weight是平滑度,tensorboard 默认0.6
last = arr[0]
smoothed = []
for point in arr:
smoothed_val = last * weight + (1 - weight) * point
smoothed.append(smoothed_val)
last = smoothed_val
return np.array(smoothed)
save_path = 'vis_smooth'
if not os.path.exists(save_path):
os.mkdir(save_path)
for i in range(0, lines.shape[1]):
yname = lines[0,i]
xname = 'steps * 1000'
plt.xlabel(xname)
plt.ylabel(yname)
plt.plot(x, smooth(lines[1:, i].astype(np.float)))
plt.savefig(os.path.join(save_path, yname+'.png'))
plt.cla()