class_docstr: Save the model once triggered.
class_docstr_tok: ["Save","the","model","once","triggered","."]
docstr: Args:
      max_to_keep (int): the same as in ``tf.train.Saver``.
      keep_checkpoint_every_n_hours (float): the same as in ``tf.train.Saver``.
          Note that "keep" does not mean "create", but means "don't delete".
      checkpoint_dir (str): Defaults to ``logger.get_logger_dir()``.
      var_collections (str or list of str): collection of the variables (or list of collections) to save.
docstr_tok: ["Args",":","max_to_keep","(","int",")",":","the","same","as","in","``","tf.train.Saver","``",".","keep_checkpoint_every_n_hours","(","float",")",":","the","same","as","in","``","tf.train.Saver","``",".","Note","that","``","keep","''","does","not","mean","``","create","''",",","but","means","``","do","n't","delete","''",".","checkpoint_dir","(","str",")",":","Defaults","to","``","logger.get_logger_dir","(",")","``",".","var_collections","(","str","or","list","of","str",")",":","collection","of","the","variables","(","or","list","of","collections",")","to","save","."]
code: def __init__(
      self,
      max_to_keep=10,
      keep_checkpoint_every_n_hours=0.5,
      checkpoint_dir=None,
      var_collections=None,
  ):
      """
      Args:
          max_to_keep (int): the same as in ``tf.train.Saver``.
          keep_checkpoint_every_n_hours (float): the same as in ``tf.train.Saver``.
              Note that "keep" does not mean "create", but means "don't delete".
          checkpoint_dir (str): Defaults to ``logger.get_logger_dir()``.
          var_collections (str or list of str): collection of the variables (or list of collections) to save.
      """
      if var_collections is None:
          var_collections = [tf.GraphKeys.GLOBAL_VARIABLES]
      self._max_to_keep = max_to_keep
      self._keep_every_n_hours = keep_checkpoint_every_n_hours
  
      if not isinstance(var_collections, list):
          var_collections = [var_collections]
      self.var_collections = var_collections
      if checkpoint_dir is None:
          checkpoint_dir = logger.get_logger_dir()
      if checkpoint_dir is not None:
          if not tf.gfile.IsDirectory(
              checkpoint_dir
          ):  # v2: tf.io.gfile.isdir
              tf.gfile.MakeDirs(
                  checkpoint_dir
              )  # v2: tf.io.gfile.makedirs
      # If None, allow it to be init, but fail later if used
      # For example, if chief_only=True, it can still be safely initialized
      # in non-chief workers which don't have logger dir
      self.checkpoint_dir = (
          fs.normpath(checkpoint_dir)
          if checkpoint_dir is not None
          else checkpoint_dir
      )
  
file_path: tensorpack/tensorpack/callbacks/saver.py
imports: import os
  from datetime import datetime
  from ..compat import tfv1
  from ..utils import fs, logger
  from .base import Callback
label_desc: Use image node_id 1 to create a new ModelSaver object from inherited base classes: Callback with example: obj = ModelSaver(max_to_keep, keep_checkpoint_every_n_hours, checkpoint_dir, var_collections)