class_docstr: EarlyStopping callback to exit the training loop if early_stopping_metric
  does not improve by a certain amount for a certain
  number of epochs.
  
  Parameters
  ---------
  early_stopping_metric : str
      Early stopping metric name
  is_maximize : bool
      Whether to maximize or not early_stopping_metric
  tol : float
      minimum change in monitored value to qualify as improvement.
      This number should be positive.
  patience : integer
      number of epochs to wait for improvement before terminating.
      the counter be reset after each improvement
class_docstr_tok: ["EarlyStopping","callback","to","exit","the","training","loop","if","early_stopping_metric","does","not","improve","by","a","certain","amount","for","a","certain","number","of","epochs",".","Parameters","--","--","--","--","-","early_stopping_metric",":","str","Early","stopping","metric","name","is_maximize",":","bool","Whether","to","maximize","or","not","early_stopping_metric","tol",":","float","minimum","change","in","monitored","value","to","qualify","as","improvement",".","This","number","should","be","positive",".","patience",":","integer","number","of","epochs","to","wait","for","improvement","before","terminating",".","the","counter","be","reset","after","each","improvement"]
code: def on_epoch_end(self, epoch, logs=None):
      current_loss = logs.get(self.early_stopping_metric)
      if current_loss is None:
          return
  
      loss_change = current_loss - self.best_loss
      max_improved = self.is_maximize and loss_change > self.tol
      min_improved = (not self.is_maximize) and (
          -loss_change > self.tol
      )
      if max_improved or min_improved:
          self.best_loss = current_loss
          self.best_epoch = epoch
          self.wait = 1
          self.best_weights = copy.deepcopy(
              self.trainer.network.state_dict()
          )
      else:
          if self.wait >= self.patience:
              self.stopped_epoch = epoch
              self.trainer._stop_training = True
          self.wait += 1
  
imports: import time
  import datetime
  import copy
  import numpy
  from dataclasses import dataclass, field
  from typing import List, Any
  import warnings
label_desc: Use image node_id 2 for calling the EarlyStopping obj's underlying member method code with example usage: obj.on_epoch_end(epoch, logs) without return types