def on_epoch_end(self, runner: IRunner) -> None: """Epoch end hook. Args: runner (IRunner): current runner """ if runner.stage_name.startswith("infer"): return runner.valid_metrics = { k.replace(f"{runner.valid_loader}_", ""): v for k, v in runner.epoch_metrics.items() if k.startswith(runner.valid_loader) } assert ( runner.main_metric in runner.valid_metrics ), f"{runner.main_metric} value is not available by the epoch end" current_valid_metric = runner.valid_metrics[runner.main_metric] if runner.minimize_metric: best_valid_metric = runner.best_valid_metrics.get( runner.main_metric, float("+inf")) is_best = current_valid_metric < best_valid_metric else: best_valid_metric = runner.best_valid_metrics.get( runner.main_metric, float("-inf")) is_best = current_valid_metric > best_valid_metric if is_best: runner.is_best_valid = True runner.best_valid_metrics = runner.valid_metrics.copy()
def on_epoch_start(self, runner: IRunner) -> None: """Epoch start hook. Args: runner (IRunner): current runner """ runner.valid_metrics = defaultdict(None) runner.is_best_valid = False
def on_epoch_end(self, runner: IRunner) -> None: """Store validation metrics and use latest validation score when validation loader is not required. Args: runner (IRunner): current runner """ if self.valid_loader in runner.loaders: self.valid_metrics = runner.valid_metrics.copy() elif self.valid_metrics is not None: # use previous score on validation runner.valid_metrics = self.valid_metrics runner.is_best_valid = False
def on_epoch_end(self, runner: IRunner) -> None: """Store validation metrics and use latest validation score when validation loader is not required. Arguments: runner (IRunner): current runner """ if self.valid_loader in runner.loaders: self.valid_metrics = { runner.main_metric: runner.valid_metrics[runner.main_metric] } elif self.valid_metrics is not None: # use previous score on validation runner.valid_metrics = self.valid_metrics