-
Notifications
You must be signed in to change notification settings - Fork 2
/
visualize.py
61 lines (51 loc) · 1.75 KB
/
visualize.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
#!/usr/bin/env python
#encoding=utf-8
import visdom
import numpy as np
import torch
class display(object):
def __init__(self):
self.vis = visdom.Visdom()
def draw(self, X, Y):
self.vis.line(X=X, \
Y=Y, \
win=self.lot, \
update='append')
class display_lr(display):
def __init__(self):
super(display_lr, self).__init__()
self.lot = self.vis.line( \
X=torch.zeros((1,)).cpu(), \
Y=torch.zeros((1,)).cpu(), \
opts=dict( \
xlabel="iteration", \
ylabel="learning rate", \
title="learning rate", \
legend=["learning rate"]))
def cal(self, optims):
lr = 0.0
for param_group in optims.param_groups:
lr += param_group['lr']
return lr / len(optims.param_groups)
class display_loss(display):
def __init__(self):
super(display_loss, self).__init__()
self.lot = self.vis.line( \
X=torch.zeros((1,)).cpu(), \
Y=torch.zeros((1,)).cpu(), \
opts=dict( \
xlabel="iteration", \
ylabel="loss", \
title="loss", \
legend=["train loss"]))
class display_accuracy(display):
def __init__(self):
super(display_accuracy, self).__init__()
self.lot = self.vis.line( \
X=torch.zeros((1,)).cpu(), \
Y=torch.zeros((1,2)).cpu(), \
opts=dict( \
xlabel="iteration", \
ylabel="accuracy", \
title="accuracy", \
legend=['train accuracy', 'validate accuracy']))