forked from abeardear/pytorch-YOLO-v1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualize.py
69 lines (62 loc) · 2.1 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
62
63
64
65
66
67
68
69
import visdom
import numpy as np
class Visualizer():
def __init__(self, env='main', **kwargs):
'''
**kwargs, dict option
'''
self.vis = visdom.Visdom(env=env)
self.index = {} # x, dict
self.log_text = ''
self.env = env
def plot_train_val(self, loss_train=None, loss_val=None):
'''
plot val loss and train loss in one figure
'''
x = self.index.get('train_val', 0)
if x == 0:
loss = loss_train if loss_train else loss_val
win_y = np.column_stack((loss, loss))
win_x = np.column_stack((x, x))
self.win = self.vis.line(Y=win_y, X=win_x,
env=self.env)
# opts=dict(
# title='train_test_loss',
# ))
self.index['train_val'] = x + 1
return
if loss_train != None:
self.vis.line(Y=np.array([loss_train]), X=np.array([x]),
win=self.win,
name='1',
update='append',
env=self.env)
self.index['train_val'] = x + 5
else:
self.vis.line(Y=np.array([loss_val]), X=np.array([x]),
win=self.win,
name='2',
update='append',
env=self.env)
def plot_many(self, d):
'''
d: dict {name, value}
'''
for k, v in d.iteritems():
self.plot(k, v)
def plot(self, name, y, **kwargs):
'''
plot('loss', 1.00)
'''
x = self.index.get(name, 0) # if none, return 0
self.vis.line(Y=np.array([y]), X=np.array([x]),
win=name,
opts=dict(title=name),
update=None if x== 0 else 'append',
**kwargs)
self.index[name] = x + 1
def log(self, info, win='log_text'):
'''
show text in box not write into txt?
'''
pass