code: def __init__(
      self,
      monitor,
      model_path,
      patience=5,
      mode="min",
      delta=0.001,
      save_weights_only=False,
  ):
      self.monitor = monitor
      self.patience = patience
      self.counter = 0
      self.mode = mode
      self.best_score = None
      self.early_stop = False
      self.delta = delta
      self.save_weights_only = save_weights_only
      self.model_path = model_path
      self.history = []
      if self.mode == "min":
          self.val_score = np.Inf
      else:
          self.val_score = -np.Inf
  
      if self.monitor.startswith("train_"):
          self.model_state = "train"
          self.monitor_value = self.monitor[len("train_") :]
      elif self.monitor.startswith("valid_"):
          self.model_state = "valid"
          self.monitor_value = self.monitor[len("valid_") :]
      else:
          raise Exception("monitor must start with train_ or valid_")
  
file_path: tez/tez/callbacks/early_stopping.py
imports: import numpy
  from accelerate.logging import get_logger
  from tez import enums
  from tez.callbacks import Callback
  from tez.logger import logger
label_desc: Use image node_id 1 to create a new EarlyStopping object from inherited base classes: Callback with example: obj = EarlyStopping(monitor, model_path, patience, mode, delta, save_weights_only)