class_docstr: Write a file (or checkpoint) after every epoch. ``filename`` can contain named formatting options,
  which will be filled the value of ``epoch`` and keys in ``logs`` (passed in ``on_epoch_end``). For
  example: if ``filename`` is ``weights.{epoch:02d}-{val_loss:.2f}.txt``, then ``save_file()`` will be
  called with a file descriptor for a file with the epoch number and the validation loss in the
  filename.
  
  By default, the file is written atomically to the specified filename so that the training can
  be killed and restarted later using the same filename for periodic file saving. To do so, a
  temporary file is created with the name of ``filename + '.tmp'`` and is then moved to the final
  destination after the checkpoint is done. The ``temporary_filename`` argument allows to change the
  path of this temporary file.
  
  Args:
      filename (str): Path to save the model file.
      monitor (str): Quantity to monitor.
          (Default value = 'val_loss')
      verbose (bool): Whether to display a message when saving and restoring a checkpoint.
          (Default value = False)
      save_best_only (bool): If `save_best_only` is true, the latest best model according to the
          quantity monitored will not be overwritten.
          (Default value = False)
      keep_only_last_best (bool): Whether only the last saved best checkpoint is kept. Applies only when
           `save_best_only` is true.
           (Default value = False)
      restore_best (bool): If `restore_best` is true, the model will be reset to the last best checkpoint done.
          This option only works when `save_best_only` is also true. (Default value = False)
      mode (str): One of {'min', 'max'}.
          If `save_best_only` is true, the decision to overwrite the current save file is made based
          on either the maximization or the minimization of the monitored quantity. For
          `val_accuracy`, this should be `max`, for `val_loss` this should be `min`, etc.
          (Default value = 'min')
      period (int): Interval (number of epochs) between checkpoints.
          (Default value = 1)
      temporary_filename (str, optional): Temporary filename for the checkpoint so that the
          last checkpoint can be written atomically. See the ``atomic_write`` argument.
      atomic_write (bool): Whether to write atomically the checkpoint. See the description above
          for details.
          (Default value = True)
      open_mode (str): ``mode`` option passed to :func:`open()`.
          (Default value = 'wb')
class_docstr_tok: ["Write","a","file","(","or","checkpoint",")","after","every","epoch",".","``","filename","``","can","contain","named","formatting","options",",","which","will","be","filled","the","value","of","``","epoch","``","and","keys","in","``","logs","``","(","passed","in","``","on_epoch_end","``",")",".","For","example",":","if","``","filename","``","is","``","weights",".","{","epoch:02d","}","-","{","val_loss",":",".2f","}",".txt","``",",","then","``","save_file","(",")","``","will","be","called","with","a","file","descriptor","for","a","file","with","the","epoch","number","and","the","validation","loss","in","the","filename",".","By","default",",","the","file","is","written","atomically","to","the","specified","filename","so","that","the","training","can","be","killed","and","restarted","later","using","the","same","filename","for","periodic","file","saving",".","To","do","so",",","a","temporary","file","is","created","with","the","name","of","``","filename","+","'.tmp","'","``","and","is","then","moved","to","the","final","destination","after","the","checkpoint","is","done",".","The","``","temporary_filename","``","argument","allows","to","change","the","path","of","this","temporary","file",".","Args",":","filename","(","str",")",":","Path","to","save","the","model","file",".","monitor","(","str",")",":","Quantity","to","monitor",".","(","Default","value","=","'val_loss","'",")","verbose","(","bool",")",":","Whether","to","display","a","message","when","saving","and","restoring","a","checkpoint",".","(","Default","value","=","False",")","save_best_only","(","bool",")",":","If","`","save_best_only","`","is","true",",","the","latest","best","model","according","to","the","quantity","monitored","will","not","be","overwritten",".","(","Default","value","=","False",")","keep_only_last_best","(","bool",")",":","Whether","only","the","last","saved","best","checkpoint","is","kept",".","Applies","only","when","`","save_best_only","`","is","true",".","(","Default","value","=","False",")","restore_best","(","bool",")",":","If","`","restore_best","`","is","true",",","the","model","will","be","reset","to","the","last","best","checkpoint","done",".","This","option","only","works","when","`","save_best_only","`","is","also","true",".","(","Default","value","=","False",")","mode","(","str",")",":","One","of","{","'min","'",",","'max","'","}",".","If","`","save_best_only","`","is","true",",","the","decision","to","overwrite","the","current","save","file","is","made","based","on","either","the","maximization","or","the","minimization","of","the","monitored","quantity",".","For","`","val_accuracy","`",",","this","should","be","`","max","`",",","for","`","val_loss","`","this","should","be","`","min","`",",","etc",".","(","Default","value","=","'min","'",")","period","(","int",")",":","Interval","(","number","of","epochs",")","between","checkpoints",".","(","Default","value","=","1",")","temporary_filename","(","str",",","optional",")",":","Temporary","filename","for","the","checkpoint","so","that","the","last","checkpoint","can","be","written","atomically",".","See","the","``","atomic_write","``","argument",".","atomic_write","(","bool",")",":","Whether","to","write","atomically","the","checkpoint",".","See","the","description","above","for","details",".","(","Default","value","=","True",")","open_mode","(","str",")",":","``","mode","``","option","passed","to",":","func",":","`","open","(",")","`",".","(","Default","value","=","'wb","'",")"]
code: def __init__(
      self,
      filename: str,
      *,
      monitor: str = "val_loss",
      mode: str = "min",
      save_best_only: bool = False,
      keep_only_last_best: bool = False,
      restore_best: bool = False,
      period: int = 1,
      verbose: bool = False,
      temporary_filename: Optional[str] = None,
      atomic_write: bool = True,
      open_mode: str = "wb",
      read_mode: str = "rb",
  ) -> None:
      super().__init__()
      self.filename = filename
      self.monitor = monitor
      self.verbose = verbose
      self.save_best_only = save_best_only
      self.keep_only_last_best = keep_only_last_best
      self.restore_best = restore_best
      self.temporary_filename = temporary_filename
      self.atomic_write = atomic_write
      self.open_mode = open_mode
      self.read_mode = read_mode
      self.best_filename = None
  
      if self.keep_only_last_best and not self.save_best_only:
          raise ValueError(
              "The 'keep_only_last_best' argument only works when 'save_best_only' is also true."
          )
      if self.restore_best and not self.save_best_only:
          raise ValueError(
              "The 'restore_best' argument only works when 'save_best_only' is also true."
          )
  
      if self.save_best_only:
          if mode not in ["min", "max"]:
              raise ValueError(f"Invalid mode '{mode}'")
          if mode == "min":
              self.monitor_op = lambda x, y: x < y
              self.current_best = float("Inf")
          elif mode == "max":
              self.monitor_op = lambda x, y: x > y
              self.current_best = -float("Inf")
  
      self.period = period
  
file_path: poutyne/poutyne/framework/callbacks/periodic.py
imports: import os
  import warnings
  from abc import ABC, abstractmethod
  from typing import IO, Callable, Dict, Optional
  from poutyne.framework.callbacks._utils import atomic_lambda_save
  from poutyne.framework.callbacks.callbacks import Callback
label_desc: Use image node_id 1 to create a new PeriodicSaveCallback object from inherited base classes: ABC, Callback with example: obj = PeriodicSaveCallback(filename)