本文整理汇总了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