本文整理匯總了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.")
示例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()
示例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)
}
示例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)
示例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.')
示例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