class PlotLosses: """ Class collect metrics from the training engine and send it to plugins, when send is called """ def __init__(self, outputs: Optional[List[Type[BO]]] = None, mode: str = 'notebook', **kwargs): """ :param outputs: list of callbacks (outputs) which are called with send method :param mode: Options: 'notebook' or 'script' - some of outputs need to change some behaviors, depending on the working environment :param kwargs: key-arguments which are passed to MainLogger """ self.logger = MainLogger(**kwargs) self.outputs = outputs if outputs is not None else [MatplotlibPlot(), ExtremaPrinter()] for out in self.outputs: out.set_output_mode(mode) def update(self, *args, **kwargs): """update logs with arguments that will be passed to main logger""" self.logger.update(*args, **kwargs) def send(self): """Method will send logs to every output class""" for output in self.outputs: output.send(self.logger) def draw(self): """Send method substitute from old livelossplot api""" warnings.warn('draw will be deprecated, please use send method', PendingDeprecationWarning) self.send()
def __init__(self, outputs: Optional[List[Type[BO]]] = None, mode: str = 'notebook', **kwargs): """ :param outputs: list of callbacks (outputs) which are called with send method :param mode: Options: 'notebook' or 'script' - some of outputs need to change some behaviors, depending on the working environment :param kwargs: key-arguments which are passed to MainLogger """ self.logger = MainLogger(**kwargs) self.outputs = outputs if outputs is not None else [MatplotlibPlot(), ExtremaPrinter()] for out in self.outputs: out.set_output_mode(mode)
def send(self, logger: MainLogger): """Draw figures with metrics and show""" log_groups = logger.grouped_log_history() figsize_x = self.max_cols * self.cell_size[0] figsize_y = ( (len(log_groups) + 1) // self.max_cols + 1) * self.cell_size[1] max_rows = (len(log_groups) + len(self.extra_plots) + 1) // self.max_cols + 1 clear_output(wait=True) plt.figure(figsize=(figsize_x, figsize_y)) for group_id, (group_name, group_logs) in enumerate(log_groups.items()): plt.subplot(max_rows, self.max_cols, group_id + 1) self._draw_metric_subplot(group_logs, group_name=group_name) for i, extra_plot in enumerate(self.extra_plots): plt.subplot(max_rows, self.max_cols, i + len(log_groups) + 1) extra_plot(logger) plt.tight_layout() if self.figpath is not None: plt.savefig(self.figpath.format(i=self.file_idx)) self.file_idx += 1 plt.show()
def send(self, logger: MainLogger): """Draw figures with metrics and show""" log_groups = logger.grouped_log_history() max_rows = math.ceil( (len(log_groups) + len(self.extra_plots)) / self.max_cols) fig, axes = plt.subplots(max_rows, self.max_cols) axes = axes.reshape(-1, self.max_cols) self._before_plots(fig, axes, len(log_groups)) for group_idx, (group_name, group_logs) in enumerate(log_groups.items()): ax = axes[group_idx // self.max_cols, group_idx % self.max_cols] self._draw_metric_subplot(ax, group_logs, group_name=group_name, x_label=logger.step_names[group_name]) for idx, extra_plot in enumerate(self.extra_plots): ax = axes[(len(log_groups) + idx) // self.max_cols, (len(log_groups) + idx) % self.max_cols] extra_plot(ax, logger) self._after_plots(fig)
def __init__( self, outputs: List[Union[Type[BO], str]] = ['MatplotlibPlot', 'ExtremaPrinter'], mode: str = 'notebook', **kwargs ): """ Args: outputs: list of output modules: objects inheriting from BaseOutput or strings for livelossplot built-in output methods with default parameters mode: Options: 'notebook' or 'script' - some of outputs need to change some behaviors, depending on the working environment **kwargs: key-arguments which are passed to MainLogger constructor """ self.logger = MainLogger(**kwargs) self.outputs = [getattr(livelossplot.outputs, out)() if isinstance(out, str) else out for out in outputs] for out in self.outputs: out.set_output_mode(mode)
def send(self, logger: MainLogger) -> None: """Draw figures with metrics and show""" log_groups = logger.grouped_log_history() new_grid_plot = False for idx, (group_name, group_logs) in enumerate(log_groups.items(), start=1): fig = self.figures.get(group_name) if not fig: fig = self.plotting.figure(title=group_name) new_grid_plot = True self.figures[group_name] = self._draw_metric_subplot(fig, group_logs) if new_grid_plot: self._create_grid_plot() if self.is_notebook: self.io.push_notebook(handle=self.target) else: self.plotting.save(self.grid)
class PlotLosses: """ Class collect metrics from the training engine and send it to plugins, when send is called """ def __init__( self, outputs: List[Union[Type[BO], str]] = ['MatplotlibPlot', 'ExtremaPrinter'], mode: str = 'notebook', **kwargs ): """ Args: outputs: list of output modules: objects inheriting from BaseOutput or strings for livelossplot built-in output methods with default parameters mode: Options: 'notebook' or 'script' - some of outputs need to change some behaviors, depending on the working environment **kwargs: key-arguments which are passed to MainLogger constructor """ self.logger = MainLogger(**kwargs) self.outputs = [getattr(livelossplot.outputs, out)() if isinstance(out, str) else out for out in outputs] for out in self.outputs: out.set_output_mode(mode) def update(self, *args, **kwargs): """update logs with arguments that will be passed to main logger""" self.logger.update(*args, **kwargs) def send(self): """Method will send logs to every output class""" for output in self.outputs: output.send(self.logger) def draw(self): """Send method substitute from old livelossplot api""" warnings.warn('draw will be deprecated, please use send method', PendingDeprecationWarning) self.send() def reset_outputs(self) -> 'PlotLosses': """Resets all outputs. Returns: Plotlosses object (so it works for chaining) """ self.outputs = [] return self def to_matplotlib(self, **kwargs) -> 'PlotLosses': """Appends outputs.MatplotlibPlot output, with specified parameters. Args: **kwargs: keyword arguments for MatplotlibPlot Returns: Plotlosses object (so it works for chaining) """ self.outputs.append(outputs.MatplotlibPlot(**kwargs)) return self def to_extrema_printer(self, **kwargs) -> 'PlotLosses': """Appends outputs.ExtremaPrinter output, with specified parameters. Args: **kwargs: keyword arguments for ExtremaPrinter Returns: Plotlosses object (so it works for chaining) """ self.outputs.append(outputs.ExtremaPrinter(**kwargs)) return self def to_bokeh(self, **kwargs) -> 'PlotLosses': """Appends outputs.BokehPlot output, with specified parameters. Args: **kwargs: keyword arguments for BokehPlot Returns: Plotlosses object (so it works for chaining) """ self.outputs.append(outputs.BokehPlot(**kwargs)) return self def to_neptune(self, **kwargs) -> 'PlotLosses': """Appends outputs.NeptuneLogger output, with specified parameters. Args: **kwargs: keyword arguments for NeptuneLogger Returns: Plotlosses object (so it works for chaining) """ self.outputs.append(outputs.NeptuneLogger(**kwargs)) return self def to_tensorboard(self, **kwargs) -> 'PlotLosses': """Appends outputs.TensorboardLogger output, with specified parameters. Args: **kwargs: keyword arguments for TensorboardLogger Returns: Plotlosses object (so it works for chaining) """ self.outputs.append(outputs.TensorboardLogger(**kwargs)) return self def to_tensorboard_tf(self, **kwargs) -> 'PlotLosses': """Appends outputs.TensorboardTFLogger output, with specified parameters. Args: **kwargs: keyword arguments for TensorboardTFLogger Returns: Plotlosses object (so it works for chaining) """ self.outputs.append(outputs.TensorboardTFLogger(**kwargs)) return self
def send(self, logger: MainLogger): """Create massages with log_history and massage template""" log_groups = logger.grouped_log_history() massages = self._create_massages(log_groups) print('\n'.join(massages))