-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot.py
More file actions
68 lines (61 loc) · 1.83 KB
/
plot.py
File metadata and controls
68 lines (61 loc) · 1.83 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
#!/usr/bin/env python3
import os
import re
from collections import deque
import numpy as np
import matplotlib.pyplot as plt
def moving_average(x, w):
return np.convolve(x, np.ones(w), 'valid') / w
ion = os.getenv("ION", 1) != '0'
if ion:
plt.ion()
plt.style.use('dark_background')
plt.gca().set_axis_off()
plt.subplots_adjust(top = 1, bottom = 0, right = 1, left = 0, hspace = 0, wspace = 0)
plt.margins(0,0)
plt.gca().xaxis.set_major_locator(plt.NullLocator())
plt.gca().yaxis.set_major_locator(plt.NullLocator())
y = deque([], int(os.getenv("SIZE", 1_000)))
G = L = None
read = int(os.getenv("READ", 0))
while True:
y_bef = len(y)
with open('train.log', 'r') as f:
buff = ''
for i,line in enumerate(f):
if i < read:
continue
read += 1
buff += line.replace("\n",'')
fa = re.findall('{.+?}', buff)
if len(fa) > 0:
for fa1 in fa:
if 'classifier' not in fa1:
continue
l = re.sub("device.+?',", '', fa1)
print('plt', l)
if read % int(os.getenv("STEP", 2)) == 0:
y.append(l)
buff = ''
if y_bef == len(y):
continue
if len(y) < 1:
continue
z = [[float(n) for n in re.sub("[^0-9.]+", ",", y1).replace(",0,", ",")[1:-1].split(",")] for y1 in y]
zt = np.transpose(z)
labels = [f"{v} {k}" for k,v in zip(re.findall("'(.*?)'", y[-1]), z[-1])]
if G is None:
G = [None] * len(labels)
colors = ['magenta', 'yellow', 'cyan', 'lime', 'red', 'orange', 'blue', 'green'][:len(labels)]
for i,l in enumerate(labels):
if G[i] is not None:
G[i][0].remove()
G[i] = plt.plot(moving_average(zt[i], max([int(len(y)*(float(os.getenv("MA", .025)))), 1])), label=l, color=colors[i])
if L is not None:
L.remove()
L = plt.legend([g for g, in G], labels)
if ion:
plt.pause(2)
else:
plt.show()
break