class_docstr: Plugin for annealing logic in Flair.
class_docstr_tok: ["Plugin","for","annealing","logic","in","Flair","."]
docstr: Scheduler step of AnnealOnPlateau.
docstr_tok: ["Scheduler","step","of","AnnealOnPlateau","."]
code: def after_evaluation(
      self, current_model_is_best, validation_scores, **kw
  ):
      """Scheduler step of AnnealOnPlateau."""
      reduced_learning_rate: bool = self.scheduler.step(
          *validation_scores
      )
  
      self.store_learning_rate()
  
      bad_epochs = self.scheduler.num_bad_epochs
      if reduced_learning_rate:
          bad_epochs = self.patience + 1
          log.info(
              f" - {bad_epochs} epochs without improvement (above 'patience')"
              f"-> annealing learning_rate to {self.current_learning_rate}"
          )
      else:
          log.info(f" - {bad_epochs} epochs without improvement")
  
      self.trainer.dispatch(
          "metric_recorded",
          MetricRecord.scalar(
              name="bad_epochs",
              value=bad_epochs,
              global_step=self.scheduler.last_epoch + 1,
          ),
      )
  
      # stop training if learning rate becomes too small
      for lr in self.current_learning_rate:
          if lr < self.min_learning_rate:
              raise TrainingInterrupt(
                  "learning rate too small - quitting training!"
              )
  
      # reload last best model if annealing with restarts is enabled
      if (
          self.anneal_with_restarts
          and reduced_learning_rate
          and os.path.exists(self.base_path / "best-model.pt")
      ):
          log.info("resetting to best model")
          self.model.load_state_dict(
              self.model.load(
                  self.base_path / "best-model.pt"
              ).state_dict()
          )
  
file_path: flair/flair/trainers/plugins/functional/anneal_on_plateau.py
imports: import logging
  import os
  from typing import Any, Dict
  from flair.trainers.plugins.base import TrainerPlugin, TrainingInterrupt
  from flair.trainers.plugins.metric_records import MetricRecord
  from flair.training_utils import AnnealOnPlateau
label_desc: Use image node_id 4 for calling the AnnealingPlugin obj's underlying member method code with example usage: obj.after_evaluation(current_model_is_best, validation_scores) without return types