-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlive_plot.py
63 lines (45 loc) · 1.83 KB
/
live_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
matplotlib.use('TKAgg')
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style
import json
import os
import pandas as pd
style.use('dark_background')
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
def load_params():
with open("SGSC_params.json", "r") as f:
return json.load(f)
def animate(i):
params = load_params()
output_results_to_track = f"output/{params['output_dir']}/train_output.csv"
ax1.clear()
try:
df = pd.read_csv(output_results_to_track)
ax1.plot([0] + df.get("accuracy").tolist())
#ax1.annotate("high point", (max([0] + df.get("accuracy").tolist()), 1))
ax1.annotate('Local Max', xy =(3.3, 1),
xytext =(3, 1.8),
arrowprops = dict(facecolor ='blue',
shrink = 0.05),)
ax1.annotate(f"Highest Accuracy of {round(max([0] + df.get('accuracy').tolist()), 3) * 100}%",
(df.get("accuracy").tolist().index(max(df.get("accuracy").tolist())) + 1,
max([0] + df.get("accuracy").tolist())),
xytext=(len(df.get("accuracy").tolist())/2, 0.1),
arrowprops=dict(arrowstyle='-|>'))
print(max([0] + df.get("accuracy").tolist()), df.get("accuracy").tolist().index(max(df.get("accuracy").tolist())))
except:
print("csv empty, will try again in 5 seconds!")
ax1.set_title(f"accuracy of model run: {params['output_dir']}")
ax1.set_ylabel("accuracy (%)")
ax1.set_xlabel(f"epoch 0 - {params['NUM_EPOCH']}")
ani = animation.FuncAnimation(fig, animate, interval=20000)
#plt.tight_layout()
plt.show()
"""
df = pd.read_csv(output_results_to_track)
plt.plot(df.get("accuracy").tolist())
plt.show()
"""