-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper.py
29 lines (26 loc) · 1.09 KB
/
helper.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
import torch
class Visdom_line(object):
def __init__(self, vis, win, start_step=0, name="Line_1"):
"""
:param vis: (object) visdom.Visdom object
:param win: (str) name of the window
:param start_step: (int) the begin of the step
:param name: (str) the name of the line
"""
self._vis = vis
self._win = win
self._start_step = start_step
self._name = name
def update(self, y):
if self._start_step == 0:
self._vis.line(X=torch.Tensor([self._start_step]),
Y=y if isinstance(y, torch.Tensor) else torch.Tensor([y]),
win=self._win,
name="%s" % self._name,
opts=dict(legend=[self._name]))
else:
self._vis.updateTrace(X=torch.Tensor([self._start_step]),
Y=y if isinstance(y, torch.Tensor) else torch.Tensor([y]),
win=self._win,
name="%s" % self._name)
self._start_step += 1