Example #1
0
    def on_batch_end(self, runner: IRunner):
        """Check if iterated specified number of batches.

        Args:
            runner: current runner
        """
        if runner.loader_batch_step >= self.num_batch_steps:
            runner.need_early_stop = True
Example #2
0
    def on_epoch_end(self, runner: IRunner):
        """Check if iterated specified number of epochs.

        Args:
            runner: current runner
        """
        if runner.epoch >= self.num_epoch_steps:
            runner.need_early_stop = True
Example #3
0
    def on_epoch_end(self, runner: IRunner) -> None:
        """@TODO: Docs. Contribution is welcome."""
        if runner.stage_name.startswith("infer"):
            return

        score = runner.valid_metrics[self.metric]
        if self.best_score is None or self.is_better(score, self.best_score):
            self.num_bad_epochs = 0
            self.best_score = score
        else:
            self.num_bad_epochs += 1

        if self.num_bad_epochs >= self.patience:
            print(f"Early stop at {runner.epoch} epoch")
            runner.need_early_stop = True
Example #4
0
    def on_epoch_end(self, runner: IRunner) -> None:
        """Check if should be performed early stopping.

        Args:
            runner: current runner
        """
        if runner.stage_name.startswith("infer"):
            return

        score = runner.valid_metrics[self.metric]
        if self.best_score is None or self.is_better(score, self.best_score):
            self.num_bad_epochs = 0
            self.best_score = score
        else:
            self.num_bad_epochs += 1

        if self.num_bad_epochs >= self.patience:
            print(f"Early stop at {runner.epoch} epoch")
            runner.need_early_stop = True
Example #5
0
 def on_batch_end(self, runner: IRunner):
     """@TODO: Docs. Contribution is welcome."""
     if runner.loader_batch_step >= self.num_batch_steps:
         runner.need_early_stop = True