當前位置: 首頁>>代碼示例>>Python>>正文


Python basic_session_run_hooks.SecondOrStepTimer方法代碼示例

本文整理匯總了Python中tensorflow.python.training.basic_session_run_hooks.SecondOrStepTimer方法的典型用法代碼示例。如果您正苦於以下問題:Python basic_session_run_hooks.SecondOrStepTimer方法的具體用法?Python basic_session_run_hooks.SecondOrStepTimer怎麽用?Python basic_session_run_hooks.SecondOrStepTimer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.python.training.basic_session_run_hooks的用法示例。


在下文中一共展示了basic_session_run_hooks.SecondOrStepTimer方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from tensorflow.python.training import basic_session_run_hooks [as 別名]
# 或者: from tensorflow.python.training.basic_session_run_hooks import SecondOrStepTimer [as 別名]
def __init__(self,
               save_steps=None,
               save_secs=None,
               output_dir="",
               show_dataflow=True,
               show_memory=False):
    """Initializes a hook that takes periodic profiling snapshots.

    Args:
      save_steps: `int`, save profile traces every N steps. Exactly one of
          `save_secs` and `save_steps` should be set.
      save_secs: `int`, save profile traces every N seconds.
      output_dir: `string`, the directory to save the profile traces to.
          Defaults to the current directory.
      show_dataflow: `bool`, if True, add flow events to the trace connecting
          producers and consumers of tensors.
      show_memory: `bool`, if True, add object snapshot events to the trace
          showing the sizes and lifetimes of tensors.
    """
    self._output_file = os.path.join(output_dir, "timeline-{}.json")
    self._show_dataflow = show_dataflow
    self._show_memory = show_memory
    self._timer = SecondOrStepTimer(every_secs=save_secs,
                                    every_steps=save_steps) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:26,代碼來源:profiler_hook.py

示例2: __init__

# 需要導入模塊: from tensorflow.python.training import basic_session_run_hooks [as 別名]
# 或者: from tensorflow.python.training.basic_session_run_hooks import SecondOrStepTimer [as 別名]
def __init__(
      self,
      batch_size,
      every_n_steps=100,
      every_n_secs=None,):
    """Initializer for ExamplesPerSecondHook.

      Args:
      batch_size: Total batch size used to calculate examples/second from
      global time.
      every_n_steps: Log stats every n steps.
      every_n_secs: Log stats every n seconds.
    """
    if (every_n_steps is None) == (every_n_secs is None):
      raise ValueError('exactly one of every_n_steps'
                       ' and every_n_secs should be provided.')
    self._timer = basic_session_run_hooks.SecondOrStepTimer(
        every_steps=every_n_steps, every_secs=every_n_secs)

    self._step_train_time = 0
    self._total_steps = 0
    self._batch_size = batch_size 
開發者ID:rky0930,項目名稱:yolo_v2,代碼行數:24,代碼來源:cifar10_utils.py

示例3: __init__

# 需要導入模塊: from tensorflow.python.training import basic_session_run_hooks [as 別名]
# 或者: from tensorflow.python.training.basic_session_run_hooks import SecondOrStepTimer [as 別名]
def __init__(self, input_fn, estimator, metrics,
                 metric_name='loss', every_steps=100,
                 max_patience=100, minimize=True):
        self._input_fn = input_fn
        self._estimator = estimator
        self._metrics = metrics

        self._metric_name = metric_name
        self._every_steps = every_steps
        self._max_patience = max_patience
        self._minimize = minimize

        self._timer = basic_session_run_hooks.SecondOrStepTimer(
            every_steps=every_steps,
            every_secs=None)

        self._global_step = None
        self._best_value = None
        self._best_step = None 
開發者ID:jimfleming,項目名稱:recurrent-entity-networks,代碼行數:21,代碼來源:hooks.py

示例4: __init__

# 需要導入模塊: from tensorflow.python.training import basic_session_run_hooks [as 別名]
# 或者: from tensorflow.python.training.basic_session_run_hooks import SecondOrStepTimer [as 別名]
def __init__(self, batch_size, every_n_steps=100, every_n_secs=None):
        """Initializer for ExamplesPerSecondHook.
      Args:
          batch_size: Total batch size used to calculate examples/second from
          global time.
          every_n_steps: Log stats every n steps.
          every_n_secs: Log stats every n seconds.
    """
        if (every_n_steps is None) == (every_n_secs is None):
            raise ValueError(
                "exactly one of every_n_steps" " and every_n_secs should be provided."
            )
        self._timer = basic_session_run_hooks.SecondOrStepTimer(
            every_steps=every_n_steps, every_secs=every_n_secs
        )

        self._step_train_time = 0
        self._total_steps = 0
        self._batch_size = batch_size 
開發者ID:microsoft,項目名稱:DistributedDeepLearning,代碼行數:21,代碼來源:utils.py

示例5: __init__

# 需要導入模塊: from tensorflow.python.training import basic_session_run_hooks [as 別名]
# 或者: from tensorflow.python.training.basic_session_run_hooks import SecondOrStepTimer [as 別名]
def __init__(
          self,
          batch_size,
          every_n_steps=100,
          every_n_secs=None,):
    """Initializer for ExamplesPerSecondHook.

      Args:
      batch_size: Total batch size used to calculate examples/second from
      global time.
      every_n_steps: Log stats every n steps.
      every_n_secs: Log stats every n seconds.
    """
    if (every_n_steps is None) == (every_n_secs is None):
      raise ValueError('exactly one of every_n_steps'
                       ' and every_n_secs should be provided.')
    self._timer = basic_session_run_hooks.SecondOrStepTimer(
        every_steps=every_n_steps, every_secs=every_n_secs)

    self._step_train_time = 0
    self._total_steps = 0
    self._batch_size = batch_size 
開發者ID:richardaecn,項目名稱:class-balanced-loss,代碼行數:24,代碼來源:cifar_utils.py

示例6: __init__

# 需要導入模塊: from tensorflow.python.training import basic_session_run_hooks [as 別名]
# 或者: from tensorflow.python.training.basic_session_run_hooks import SecondOrStepTimer [as 別名]
def __init__(self,
               checkpoint_dir,
               save_secs=None,
               save_steps=None,
               saver=None,
               checkpoint_basename="model.ckpt",
               scaffold=None,
               listeners=None):
    """Initializes a `CheckpointSaverHook`.

    Args:
      checkpoint_dir: `str`, base directory for the checkpoint files.
      save_secs: `int`, save every N secs.
      save_steps: `int`, save every N steps.
      saver: `Saver` object, used for saving.
      checkpoint_basename: `str`, base name for the checkpoint files.
      scaffold: `Scaffold`, use to get saver object.
      listeners: List of `CheckpointSaverListener` subclass instances. Used for
        callbacks that run immediately before or after this hook saves the
        checkpoint.

    Raises:
      ValueError: One of `save_steps` or `save_secs` should be set.
      ValueError: At most one of `saver` or `scaffold` should be set.
    """
    logging.info("Create AsyncCheckpointSaverHook.")
    if saver is not None and scaffold is not None:
      raise ValueError("You cannot provide both saver and scaffold.")
    self._saver = saver
    self._save_thread = None
    self._write_graph_thread = None
    self._checkpoint_dir = checkpoint_dir
    self._save_path = os.path.join(checkpoint_dir, checkpoint_basename)
    self._scaffold = scaffold
    self._timer = basic_session_run_hooks.SecondOrStepTimer(
        every_secs=save_secs, every_steps=save_steps)
    self._listeners = listeners or []
    self._steps_per_run = 1
    self._summary_writer = None
    self._global_step_tensor = None 
開發者ID:mlperf,項目名稱:training_results_v0.5,代碼行數:42,代碼來源:async_checkpoint.py

示例7: __init__

# 需要導入模塊: from tensorflow.python.training import basic_session_run_hooks [as 別名]
# 或者: from tensorflow.python.training.basic_session_run_hooks import SecondOrStepTimer [as 別名]
def __init__(self, timeline_dir, every_n_iter=None, every_n_secs=None):
        if (every_n_iter is None and every_n_secs is None) or (
            every_n_iter is not None and every_n_secs is not None):
            raise ValueError(
                "Either every_n_iter or every_n_secs should be used.")
        self._timeline_dir = timeline_dir
        self._timer = basic_session_run_hooks.SecondOrStepTimer(
            every_secs=every_n_secs, every_steps=every_n_iter)
        self._iter_count = 0 
開發者ID:ilblackdragon,項目名稱:tf_examples,代碼行數:11,代碼來源:timeline.py

示例8: __init__

# 需要導入模塊: from tensorflow.python.training import basic_session_run_hooks [as 別名]
# 或者: from tensorflow.python.training.basic_session_run_hooks import SecondOrStepTimer [as 別名]
def __init__(self, should_stop_fn, run_every_secs=60, run_every_steps=None):
    if not callable(should_stop_fn):
      raise TypeError('`should_stop_fn` must be callable.')

    self._should_stop_fn = should_stop_fn
    self._timer = tf.compat.v1.train.SecondOrStepTimer(
        every_secs=run_every_secs, every_steps=run_every_steps)
    self._global_step_tensor = None
    self._stop_var = None
    self._stop_op = None 
開發者ID:tensorflow,項目名稱:estimator,代碼行數:12,代碼來源:early_stopping.py

示例9: begin

# 需要導入模塊: from tensorflow.python.training import basic_session_run_hooks [as 別名]
# 或者: from tensorflow.python.training.basic_session_run_hooks import SecondOrStepTimer [as 別名]
def begin(self):
    self._timer = basic_session_run_hooks.SecondOrStepTimer(
        every_secs=self._eval_throttle_secs)
    self._is_first_run = True 
開發者ID:tensorflow,項目名稱:estimator,代碼行數:6,代碼來源:training.py

示例10: run_master

# 需要導入模塊: from tensorflow.python.training import basic_session_run_hooks [as 別名]
# 或者: from tensorflow.python.training.basic_session_run_hooks import SecondOrStepTimer [as 別名]
def run_master(self):
    """Runs task master."""

    class NewCheckpointListener(
        basic_session_run_hooks.CheckpointSaverListener):

      def __init__(self, evaluator, eval_throttle_secs):
        self._evaluator = evaluator
        self._eval_throttle_secs = eval_throttle_secs

      def begin(self):
        self._timer = basic_session_run_hooks.SecondOrStepTimer(
            every_secs=self._eval_throttle_secs)

      def after_save(self, session, global_step_value):
        del session  # unused; required by signature.

        if self._timer.should_trigger_for_step(global_step_value):
          self._timer.update_last_triggered_step(global_step_value)
          self._evaluator.evaluate_and_export()
        else:
          logging.info(
              'Skip the current checkpoint eval due to throttle secs '
              '({} secs).'.format(self._eval_throttle_secs))

    # Final export signal: For any eval result with global_step >= train
    # max_steps, the evaluator will send the final export signal. There is a
    # small chance that the Estimator.train stopping logic sees a different
    # global_step value (due to global step race condition and the fact the
    # saver sees a larger value for checkpoing saving), which does not end
    # the training. When the training ends, a new checkpoint is generated, which
    # triggers the listener again. So, it could be the case the final export is
    # triggered twice.
    #
    # But here, throttle_secs will skip the next intermediate checkpoint and,
    # so, the double final export chance is very small.
    evaluator = _TrainingExecutor._Evaluator(
        self._estimator, self._eval_spec, self._train_spec.max_steps)

    # When the underlying `Estimator` object saves a new checkpoint, we would
    # like this callback to be called so that evaluation and export can trigger.
    saving_listeners = [
        NewCheckpointListener(evaluator, self._eval_spec.throttle_secs)
    ]
    self._start_distributed_training(saving_listeners=saving_listeners)

    if not evaluator.is_final_export_triggered:
      logging.info('Training has already ended. But the last eval is skipped '
                   'due to eval throttle_secs. Now evaluating the final '
                   'checkpoint.')
      evaluator.evaluate_and_export() 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:53,代碼來源:training.py


注:本文中的tensorflow.python.training.basic_session_run_hooks.SecondOrStepTimer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。