MCPcopy Create free account
hub / github.com/TPCD/DCCL / BaseVisdomLogger

Class BaseVisdomLogger

project_utils/visualization_utils.py:843–894  ·  view source on GitHub ↗

The base class for logging output to Visdom. ***THIS CLASS IS ABSTRACT AND MUST BE SUBCLASSED*** Note that the Visdom server is designed to also handle a server architecture, and therefore the Visdom server must be running at all times. The server can be st

Source from the content-addressed store, hash-verified

841
842
843class BaseVisdomLogger(Logger):
844 '''
845 The base class for logging output to Visdom.
846
847 ***THIS CLASS IS ABSTRACT AND MUST BE SUBCLASSED***
848
849 Note that the Visdom server is designed to also handle a server architecture,
850 and therefore the Visdom server must be running at all times. The server can
851 be started with
852 $ python -m visdom.server
853 and you probably want to run it from screen or tmux.
854 '''
855
856 @property
857 def viz(self):
858 return self._viz
859
860 def __init__(self, fields=None, win=None, env=None, opts={}, port=8097, server="localhost"):
861 super(BaseVisdomLogger, self).__init__(fields)
862 self.win = win
863 self.env = env
864 self.opts = opts
865 self._viz = visdom.Visdom(server="http://" + server, port=port)
866
867 def log(self, *args, **kwargs):
868 raise NotImplementedError(
869 "log not implemented for BaseVisdomLogger, which is an abstract class.")
870
871 def _viz_prototype(self, vis_fn):
872 ''' Outputs a function which will log the arguments to Visdom in an appropriate way.
873
874 Args:
875 vis_fn: A function, such as self.vis.image
876 '''
877 def _viz_logger(*args, **kwargs):
878 self.win = vis_fn(*args,
879 win=self.win,
880 env=self.env,
881 opts=self.opts,
882 **kwargs)
883 return _viz_logger
884
885 def log_state(self, state):
886 """ Gathers the stats from self.trainer.stats and passes them into
887 self.log, as a list """
888 results = []
889 for field_idx, field in enumerate(self.fields):
890 parent, stat = None, state
891 for f in field:
892 parent, stat = stat, stat[f]
893 results.append(stat)
894 self.log(*results)
895
896
897class VisdomSaver(object):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected