-
Notifications
You must be signed in to change notification settings - Fork 2
/
plotting.py
33 lines (28 loc) · 1.23 KB
/
plotting.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
from visdom import Visdom
import numpy as np
class VisdomLinePlotter(object):
"""Plots to Visdom"""
def __init__(self, env_name='main', port=8050):
try:
self.viz = Visdom(port=port)
except (ConnectionError, ConnectionRefusedError) as e:
raise ConnectionError("Visdom Server not running, please launch it with `visdom` in the terminal")
self.env = env_name
self.plots = {}
def clear(self):
self.plots = {}
def imshow(self, var_name, images):
if var_name not in self.plots:
self.plots[var_name] = self.viz.images(images)
else:
self.viz.images(images, win=self.plots[var_name], env=self.env)
def plot(self, var_name, split_name, title_name, x, y, xlabel='epochs'):
if var_name not in self.plots:
self.plots[var_name] = self.viz.line(X=np.array([x,x]), Y=np.array([y,y]), env=self.env, opts=dict(
legend=[split_name],
title=title_name,
xlabel=xlabel,
ylabel=var_name
))
else:
self.viz.line(X=np.array([x]), Y=np.array([y]), env=self.env, win=self.plots[var_name], name=split_name, update = 'append')