def on_epoch_end(self, runner: "IRunner"): """ Logs metrics here Args: runner: runner for experiment """ if runner.logdir is None: return per_loader_metrics = split_dict_to_subdicts( dct=runner.epoch_metrics, prefixes=list(runner.loaders.keys()), extra_key="_base", ) for loader_key, per_loader_metrics in per_loader_metrics.items(): if "base" in loader_key: continue if not self.header_created[loader_key]: self._make_header( metrics=per_loader_metrics, loader_key=loader_key ) self.header_created[loader_key] = True self._log_metrics( metrics=per_loader_metrics, step=runner.global_epoch, loader_key=loader_key, )
def _format_message(self, runner: "IRunner"): message = [""] mode_metrics = split_dict_to_subdicts( dct=runner.epoch_metrics, prefixes=list(runner.loaders.keys()), extra_key="_base", ) metrics = self._format_metrics(mode_metrics) for key, value in metrics.items(): message.append(f"{runner.epoch}/{runner.num_epochs} " f"* Epoch {runner.global_epoch} ({key}): {value}") message = "\n".join(message) return message
def on_epoch_end(self, runner: "IRunner"): """Translate epoch metrics to Weights & Biases.""" extra_mode = "_base" splitted_epoch_metrics = split_dict_to_subdicts( dct=runner.epoch_metrics, prefixes=list(runner.loaders.keys()), extra_key=extra_mode, ) if self.log_on_epoch_end: if extra_mode in splitted_epoch_metrics.keys(): # if we are using OptimizerCallback self._log_metrics( metrics=splitted_epoch_metrics[extra_mode], step=runner.global_epoch, mode=extra_mode, suffix=self.epoch_log_suffix, commit=True, )
def on_epoch_end(self, runner: "IRunner"): """Translate epoch metrics to tensorboard.""" if runner.logdir is None: return if self.log_on_epoch_end: per_mode_metrics = split_dict_to_subdicts( dct=runner.epoch_metrics, prefixes=list(runner.loaders.keys()), extra_key="_base", ) for mode, metrics in per_mode_metrics.items(): # suffix = "" if mode == "_base" else "/epoch" self._log_metrics( metrics=metrics, step=runner.global_epoch, mode=mode, suffix="/epoch", ) for logger in self.loggers.values(): logger.flush()