class_docstr: Callback that evaluates whether there is improvement in the loss function.
  
  The module track the losses and in case of finish patience sends a termination signal to the trainer.
  
  Args:
      monitor: the name of the value to track.
      min_delta: the minimum difference between losses to increase the patience counter.
      patience: the number of times to wait until the trainer does not terminate.
  
  **Usage example:**
  
  .. code:: python
  
      early_stop = EarlyStopping(
          monitor="top5", filepath="early_stop_model.pt"
      )
  
      trainer = ImageClassifierTrainer(...,
          callbacks={"on_checkpoint", early_stop}
      )
class_docstr_tok: ["Callback","that","evaluates","whether","there","is","improvement","in","the","loss","function",".","The","module","track","the","losses","and","in","case","of","finish","patience","sends","a","termination","signal","to","the","trainer",".","Args",":","monitor",":","the","name","of","the","value","to","track",".","min_delta",":","the","minimum","difference","between","losses","to","increase","the","patience","counter",".","patience",":","the","number","of","times","to","wait","until","the","trainer","does","not","terminate",".","*","*","Usage","example",":","*","*","..","code",":",":","python","early_stop","=","EarlyStopping","(","monitor=","''","top5","''",",","filepath=","''","early_stop_model.pt","''",")","trainer","=","ImageClassifierTrainer","(","...",",","callbacks=","{","``","on_checkpoint","''",",","early_stop","}",")"]
code: def __call__(
      self,
      model: Module,
      epoch: int,
      valid_metric: Dict[str, AverageMeter],
  ) -> TrainerState:
      score: float = valid_metric[self.monitor].avg
  
      if self.best_score is None:
          self.best_score = score
      elif score < self.best_score + self.min_delta:
          self.counter += 1
          if self.counter >= self.patience:
              self.early_stop = True
      else:
          self.best_score = score
          self.counter = 0
  
      if self.early_stop:
          print(
              f"[INFO] Early-Stopping the training process. Epoch: {epoch}."
          )
          return TrainerState.TERMINATE
  
      return TrainerState.TRAINING
  
file_path: kornia/kornia/x/callbacks.py
imports: from pathlib import Path
  from typing import Callable, Dict, Optional, Union
  import torch
  from kornia.core import Module
  from kornia.metrics import AverageMeter
  from .utils import TrainerState
label_desc: Use image node_id 2 for calling the EarlyStopping obj's underlying member method code with example usage: obj.__call__(model, epoch, valid_metric) and returns: TrainerState, TrainerState