forked from Navigation-Team-AMP/model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
80 lines (63 loc) · 1.91 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os.path
import time
import json
import sys
import plotly as py
import plotly.graph_objs as go
def plot(data=None, out_path=None):
# Set loading flag
load_flag = False
if data == None:
load_flag = True
# Set output path
if out_path == None:
out_path = './plot.png'
# Load data from json if necessary
path = 'log.json'
if load_flag:
print("--- Loading: " + path + " ---")
if os.path.isfile(path) and os.stat(path).st_size != 0:
jsonFile = open(path, "r+")
data = json.load(jsonFile)
jsonFile.close()
else:
raise ValueError("%s isn't a file!" % path)
plotData = []
# Loop over different configurations
for i in range(len(data)):
x_loss, y_loss = [], []
for val in data[i]["loss"]:
x_loss.append(val[0])
y_loss.append(val[1])
# Plot loss
plotData.append(go.Scatter(
x = x_loss,
y = y_loss,
# mode = 'lines',
mode = 'lines+markers',
# mode = 'markers',
name = data[i]["cfg"] + " - Train"
))
x_test, y_test = [], []
for val in data[i]["test"]:
x_test.append(val[0])
y_test.append(val[1])
# Plot test
plotData.append(go.Scatter(
x = x_test,
y = y_test,
# mode = 'lines',
mode = 'lines+markers',
# mode = 'markers',
name = data[i]["cfg"] + " - Test"
))
# py.offline.plot(plotData, auto_open=False)
# py.offline.plot(plotData, image='png', auto_open=False, filename='./plot.html')
py.offline.plot(plotData, auto_open=False, filename='./plot.html')
if load_flag:
print("--- Saved: plot.html ---")
else:
sys.stdout.write("Updated plot.html \r")
sys.stdout.flush()
if __name__ =='__main__':
plot()