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


Python training_util._get_or_create_global_step_read方法代碼示例

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


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

示例1: begin

# 需要導入模塊: from tensorflow.python.training import training_util [as 別名]
# 或者: from tensorflow.python.training.training_util import _get_or_create_global_step_read [as 別名]
def begin(self):
        """Called once before graph finalization.

        Is called once before the default graph in the active tensorflow session is
        finalized and the training has starts.
        The hook can modify the graph by adding new operations to it.
        After the begin() call the graph will be finalized and the other callbacks can not modify
        the graph anymore. Second call of begin() on the same graph, should not change the graph.
        """
        # Create a summary writer if possible.
        if self._summary_writer is None and self._output_dir:
            self._summary_writer = summary_io.SummaryWriterCache.get(self._output_dir)

        # Get read access to the global step tensor.
        # pylint: disable=protected-access
        self._global_step_tensor = training_util._get_or_create_global_step_read()
        if self._global_step_tensor is None:
            raise RuntimeError("Global step should be created to use StepCounterHook.") 
開發者ID:mdangschat,項目名稱:ctc-asr,代碼行數:20,代碼來源:hooks.py

示例2: begin

# 需要導入模塊: from tensorflow.python.training import training_util [as 別名]
# 或者: from tensorflow.python.training.training_util import _get_or_create_global_step_read [as 別名]
def begin(self):
    self._summary_writer = SummaryWriterCache.get(self._checkpoint_dir)
    self._global_step_tensor = training_util._get_or_create_global_step_read()  # pylint: disable=protected-access
    if self._global_step_tensor is None:
      raise RuntimeError(
          "Global step should be created to use CheckpointSaverHook.")
    for l in self._listeners:
      l.begin() 
開發者ID:mlperf,項目名稱:training_results_v0.5,代碼行數:10,代碼來源:async_checkpoint.py

示例3: begin

# 需要導入模塊: from tensorflow.python.training import training_util [as 別名]
# 或者: from tensorflow.python.training.training_util import _get_or_create_global_step_read [as 別名]
def begin(self):
    """Build eval graph and restoring op."""
    self._timer.reset()
    self._graph = ops.Graph()
    self._global_step_tensor = training_util._get_or_create_global_step_read()  # pylint: disable=protected-access
    with self._graph.as_default():
      (self._scaffold, self._update_op, self._eval_dict,
       self._all_hooks) = self._estimator._evaluate_build_graph(
           self._input_fn, self._hooks, checkpoint_path=None)

      for h in self._all_hooks:
        if isinstance(h, tpu_estimator.TPUInfeedOutfeedSessionHook):
          h._should_initialize_tpu = False  # pylint: disable=protected-access

      if self._scaffold.saver is not None:
        raise ValueError('InMemoryEval does not support custom saver')
      if self._scaffold.init_fn is not None:
        raise ValueError('InMemoryEval does not support custom init_fn')

      self._var_name_to_eval_var = {
          v.name: v for v in ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)
      }
      self._var_name_to_placeholder = {
          v.name: array_ops.placeholder(v.dtype)
          for v in ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)
      } 
開發者ID:mlperf,項目名稱:training_results_v0.5,代碼行數:28,代碼來源:in_memory_eval.py

示例4: _train_model_default

# 需要導入模塊: from tensorflow.python.training import training_util [as 別名]
# 或者: from tensorflow.python.training.training_util import _get_or_create_global_step_read [as 別名]
def _train_model_default(self, input_fn, hooks, saving_listeners):
    """Initiate training with `input_fn`, without `DistributionStrategies`.

    Args:
      input_fn: A function that provides input data for training as minibatches.
      hooks: List of `tf.train.SessionRunHook` subclass instances. Used for
        callbacks inside the training loop.
      saving_listeners: list of `tf.train.CheckpointSaverListener` objects. Used
        for callbacks that run immediately before or after checkpoint savings.

    Returns:
      Loss from training
    """
    worker_hooks = []
    with tf.Graph().as_default() as g, g.device(self._device_fn):
      tf.compat.v1.random.set_random_seed(self._config.tf_random_seed)
      global_step_tensor = self._create_and_assert_global_step(g)

      # Skip creating a read variable if _create_and_assert_global_step
      # returns None (e.g. tf.contrib.estimator.SavedModelEstimator).
      if global_step_tensor is not None:
        training_util._get_or_create_global_step_read(g)  # pylint: disable=protected-access

      features, labels, input_hooks = (
          self._get_features_and_labels_from_input_fn(input_fn, ModeKeys.TRAIN))
      worker_hooks.extend(input_hooks)
      estimator_spec = self._call_model_fn(features, labels, ModeKeys.TRAIN,
                                           self.config)
      global_step_tensor = tf.compat.v1.train.get_global_step(g)
      return self._train_with_estimator_spec(estimator_spec, worker_hooks,
                                             hooks, global_step_tensor,
                                             saving_listeners) 
開發者ID:tensorflow,項目名稱:estimator,代碼行數:34,代碼來源:estimator.py

示例5: begin

# 需要導入模塊: from tensorflow.python.training import training_util [as 別名]
# 或者: from tensorflow.python.training.training_util import _get_or_create_global_step_read [as 別名]
def begin(self):
    self._global_step_tensor = training_util._get_or_create_global_step_read()  # pylint: disable=protected-access
    if self._global_step_tensor is None:
      raise RuntimeError(
          'Global step should be created to use StopAtCheckpointStepHook.') 
開發者ID:tensorflow,項目名稱:estimator,代碼行數:7,代碼來源:hooks.py

示例6: begin

# 需要導入模塊: from tensorflow.python.training import training_util [as 別名]
# 或者: from tensorflow.python.training.training_util import _get_or_create_global_step_read [as 別名]
def begin(self):
    self._global_step_tensor = training_util._get_or_create_global_step_read()  # pylint: disable=protected-access
    if self._global_step_tensor is None:
      raise RuntimeError("Global step should be created to use StopAtStepHook.") 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:6,代碼來源:basic_session_run_hooks.py


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