-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.py
34 lines (24 loc) · 874 Bytes
/
logger.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
import logging
class Logger:
def __init__(self):
self.logger = logging.getLogger()
def logs(self, s, step, tag='log'):
self.logger.info("{}/Step {}: {}".format(tag, step, s))
def logkv(self, d, step, tag='log'):
for k,v in d.items():
self.logger.info("{}/Step {} {}: {}".format(tag, step, k, v))
class TensorboardLogger(Logger):
def __init__(self, writer):
super().__init__()
self.writer = writer
def logs(self, s, step, tag='log'):
self.writer.add_text(tag, s, global_step=step)
def logkv(self, d, step, tag='log'):
for k,v in d.items():
self.writer.add_scalar(tag+"/"+k, v, global_step=step)
def logm(self, m, m_in):
"""log model
:param m: model (nn)
:param m_in: input to model
"""
self.writer.add_graph(m, m_in)