Line length parlai/core/logs.py
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
"""
-This file provides interface to log any metrics in tensorboard, could be extended to any other tool like visdom
+This file provides interface to log any metrics in tensorboard, could be
+extended to any other tool like visdom
+
Tensorboard:
- If you use tensorboard logging, all event folders will be stored in PARLAI_DATA/tensorboard folder. In order to
- open it with TB, launch tensorboard as : tensorboard --logdir <PARLAI_DATA/tensorboard> --port 8888.
+ If you use tensorboard logging, all event folders will be stored in
+ PARLAI_DATA/tensorboard folder. In order to
+ Open it with TB, launch tensorboard as:
+ tensorboard --logdir <PARLAI_DATA/tensorboard> --port 8888.
"""
+
import os
@@ -23,14 +28,23 @@ class TensorboardLogger(Shared):
@staticmethod
def add_cmdline_args(argparser):
logger = argparser.add_argument_group('Tensorboard Arguments')
- logger.add_argument('-tblog', '--tensorboard-log', type='bool', default=False,
- help="Tensorboard logging of metrics, default is %(default)s")
- logger.add_argument('-tbtag', '--tensorboard-tag', type=str, default=None,
- help='Specify all opt keys which you want to be presented in in TB name')
- logger.add_argument('-tbmetrics', '--tensorboard-metrics', type=str, default=None,
- help="Specify metrics which you want to track, it will be extracrted from report dict.")
- logger.add_argument('-tgcomment', '--tensorboard-comment', type=str, default='',
- help='Add any line here to distinguish your TB event file, optional')
+ logger.add_argument(
+ '-tblog', '--tensorboard-log', type='bool', default=False,
+ help="Tensorboard logging of metrics, default is %(default)s"
+ )
+ logger.add_argument(
+ '-tbtag', '--tensorboard-tag', type=str, default=None,
+ help='Specify all opt keys which you want to be presented in in TB name'
+ )
+ logger.add_argument(
+ '-tbmetrics', '--tensorboard-metrics', type=str, default=None,
+ help='Specify metrics which you want to track, it will be extracted '
+ 'from report dict.'
+ )
+ logger.add_argument(
+ '-tgcomment', '--tensorboard-comment', type=str, default='',
+ help='Add any line here to distinguish your TB event file, optional'
+ )
def __init__(self, opt):
Shared.__init__(self)
@@ -59,15 +73,22 @@ class TensorboardLogger(Shared):
def add_metrics(self, setting, step, report):
"""
- setting - whatever setting is used, train valid or test, it will be just the title of the graph
- step - num of parleys (x axis in graph), in train - parleys, in valid - wall time
- report - from TrainingLoop
- this method adds all metrics from tensorboard_metrics opt key
+ Adds all metrics from tensorboard_metrics opt key
+
+ :param setting: whatever setting is used, train valid or test, it will
+ be just the title of the graph
+ :param step: num of parleys (x axis in graph), in train - parleys, in
+ valid - wall time
+ :param report: from TrainingLoop
:return:
"""
for met in self.tbmetrics:
if met in report.keys():
- self.writer.add_scalar("{}/{}".format(setting, met), report[met], global_step=step)
+ self.writer.add_scalar(
+ "{}/{}".format(setting, met),
+ report[met],
+ global_step=step
+ )
def add_scalar(self, name, y, step=None):
"""
