2019-08-23 23:27:45 +08:00
|
|
|
from visdom import Visdom
|
|
|
|
import random
|
|
|
|
import numpy as np
|
2019-09-17 23:20:24 +08:00
|
|
|
import os
|
|
|
|
import time
|
2019-08-23 23:27:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
def InitVisdom():
|
2019-09-17 23:20:24 +08:00
|
|
|
# nohub python3 -m visdom.server > visdom.server.log 2 > &1
|
|
|
|
# subprocess.Popen("python3 -m visdom.server > visdom.server.log 2>&1", shell=True)
|
|
|
|
|
|
|
|
os.popen("python3 -m visdom.server > visdom.server.log 2>&1")
|
|
|
|
time.sleep(3) # to wait vindom.server started
|
|
|
|
# viz = Visdom()
|
|
|
|
# assert viz.check_connection()
|
|
|
|
# viz.close()
|
|
|
|
print("Connect http://localhost:8097")
|
|
|
|
|
2019-08-23 23:27:45 +08:00
|
|
|
|
|
|
|
class Line():
|
2019-09-17 23:20:24 +08:00
|
|
|
def __init__(self, windows, name, size):
|
2019-08-23 23:27:45 +08:00
|
|
|
super(Line, self).__init__()
|
2019-09-17 23:20:24 +08:00
|
|
|
self.name = name
|
|
|
|
self.size = size
|
|
|
|
self.win = windows
|
|
|
|
|
|
|
|
def __init__(self, windows):
|
2019-08-23 23:27:45 +08:00
|
|
|
super(Line, self).__init__()
|
2019-09-17 23:20:24 +08:00
|
|
|
self.name = str(random.random())
|
|
|
|
self.size = 0
|
|
|
|
self.win = windows
|
|
|
|
|
|
|
|
def __init__(self, windows, name):
|
2019-08-23 23:27:45 +08:00
|
|
|
super(Line, self).__init__()
|
2019-09-17 23:20:24 +08:00
|
|
|
self.name = name
|
|
|
|
self.size = 0
|
|
|
|
self.win = windows
|
|
|
|
|
|
|
|
def AppendData(self, y):
|
|
|
|
self.win.AppendData(self, y)
|
2019-08-23 23:27:45 +08:00
|
|
|
|
|
|
|
class LineWin():
|
|
|
|
def __init__(self):
|
|
|
|
super(LineWin, self).__init__()
|
|
|
|
self.viz = Visdom()
|
|
|
|
self.name = str(random.random())
|
|
|
|
self.win = self.viz.line(
|
|
|
|
X=np.array([0]),
|
|
|
|
Y=np.array([0]),
|
|
|
|
name=self.name
|
|
|
|
)
|
|
|
|
self.data = np.array([])
|
2019-09-17 23:20:24 +08:00
|
|
|
|
|
|
|
def AppendLine(self, y):
|
|
|
|
if not isinstance(y, list):
|
2019-08-23 23:27:45 +08:00
|
|
|
y = [y]
|
|
|
|
linename = str(random.random())
|
|
|
|
self.viz.line(
|
|
|
|
X=np.array(range(len(y))),
|
|
|
|
Y=np.array(y),
|
|
|
|
opts=dict(markercolor=np.array([50]),
|
2019-09-17 23:20:24 +08:00
|
|
|
markersymbol='dot',),
|
2019-08-23 23:27:45 +08:00
|
|
|
win=self.win,
|
|
|
|
update="new",
|
|
|
|
name=linename,
|
|
|
|
)
|
2019-09-17 23:20:24 +08:00
|
|
|
return Line(linename, len(y))
|
2019-08-23 23:27:45 +08:00
|
|
|
|
2019-09-17 23:20:24 +08:00
|
|
|
def AppendData(self, line, y):
|
|
|
|
if not isinstance(y, list):
|
2019-08-23 23:27:45 +08:00
|
|
|
y = [y]
|
|
|
|
self.viz.line(
|
|
|
|
X=np.array(range(line.size, line.size+len(y))),
|
|
|
|
Y=np.array(y),
|
|
|
|
win=self.win,
|
|
|
|
update="append",
|
|
|
|
name=line.name
|
|
|
|
)
|
|
|
|
line.size = line.size + len(y)
|