MCPcopy Create free account
hub / github.com/294coder/Dif-PAN / __init__

Method __init__

utils/logger.py:24–63  ·  view source on GitHub ↗

tensorboard logger Args: place (str, optional): place to save tb logging. Defaults to './tb_runs/'. file_logger_name (str, optional): name of file logger. Defaults to None. random_id: (bool, optional): append id after tensorboard dir. Defaults to True

(self, place="./runs/", file_dir='./logs/', file_logger_name=None, random_id=True, tb_comment=None,
                 **tb_kwargs)

Source from the content-addressed store, hash-verified

22
23class TensorboardLogger:
24 def __init__(self, place="./runs/", file_dir='./logs/', file_logger_name=None, random_id=True, tb_comment=None,
25 **tb_kwargs) -> None:
26 """tensorboard logger
27
28 Args:
29 place (str, optional): place to save tb logging. Defaults to './tb_runs/'.
30 file_logger_name (str, optional): name of file logger. Defaults to None.
31 random_id: (bool, optional): append id after tensorboard dir. Defaults to True
32 tb_kwargs: kwargs for tensorboardX.writer.SummaryWriter
33 comment: Optional[str] = "",
34 purge_step: Optional[int] = None,
35 max_queue: Optional[int] = 10,
36 flush_secs: Optional[int] = 120,
37 filename_suffix: Optional[str] = '',
38 write_to_disk: Optional[bool] = True,
39 log_dir: Optional[str] = None,
40 comet_config: Optional[dict] = {"disabled": True},
41 """
42 if not place_exists(place):
43 os.mkdir(place)
44 print("Created directory: ", place)
45
46 if random_id:
47 # use random id as dir name
48 id = generate_id(8) + '' if tb_comment is None else '_{}'.format(tb_comment)
49 place = os.path.join(place, id)
50 os.mkdir(place)
51 else:
52 # use time as dir name
53 stf_time = time.strftime("%m-%d %H:%M", time.localtime())
54 name = stf_time + '' if tb_comment is None else '_{}'.format(tb_comment)
55 place = os.path.join(place, name)
56 os.mkdir(place)
57
58 self.writer = writer.SummaryWriter(place, **tb_kwargs)
59
60 assert file_logger_name is not None, '@file_logger_name should be set'
61 self.file_writer = PrintLogger(os.path.join(file_dir, file_logger_name + '.log'))
62
63 self._tb_print = partial(self.file_writer.log, level=logging.DEBUG)
64
65 def print(self, msg: str, level=logging.INFO):
66 self.file_writer.log(msg, level)

Callers

nothing calls this directly

Calls 3

place_existsFunction · 0.85
generate_idFunction · 0.85
PrintLoggerClass · 0.85

Tested by

no test coverage detected