本文整理汇总了Python中tensorflow.python.training.session_run_hook.SessionRunArgs方法的典型用法代码示例。如果您正苦于以下问题:Python session_run_hook.SessionRunArgs方法的具体用法?Python session_run_hook.SessionRunArgs怎么用?Python session_run_hook.SessionRunArgs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.training.session_run_hook
的用法示例。
在下文中一共展示了session_run_hook.SessionRunArgs方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: before_run
# 需要导入模块: from tensorflow.python.training import session_run_hook [as 别名]
# 或者: from tensorflow.python.training.session_run_hook import SessionRunArgs [as 别名]
def before_run(self, run_context): # pylint: disable=unused-argument
if self._timer.last_triggered_step() is None:
# We do write graph and saver_def at the first call of before_run.
# We cannot do this in begin, since we let other hooks to change graph and
# add variables in begin. Graph is finalized after all begin calls.
training_util.write_graph(
ops.get_default_graph().as_graph_def(add_shapes=True),
self._checkpoint_dir,
"graph.pbtxt")
saver_def = self._get_saver().saver_def if self._get_saver() else None
graph = ops.get_default_graph()
meta_graph_def = meta_graph.create_meta_graph_def(
graph_def=graph.as_graph_def(add_shapes=True),
saver_def=saver_def)
self._summary_writer.add_graph(graph)
self._summary_writer.add_meta_graph(meta_graph_def)
return SessionRunArgs(self._global_step_tensor)
示例2: before_run
# 需要导入模块: from tensorflow.python.training import session_run_hook [as 别名]
# 或者: from tensorflow.python.training.session_run_hook import SessionRunArgs [as 别名]
def before_run(self, run_context): # pylint: disable=unused-argument
if self._timer.last_triggered_step() is None:
# Write graph in the first call.
training_util.write_graph(
ops.get_default_graph().as_graph_def(add_shapes=True),
self._checkpoint_dir,
"graph.pbtxt")
saver_def = self._saver.saver_def if self._saver else None
graph = ops.get_default_graph()
meta_graph_def = meta_graph.create_meta_graph_def(
graph_def=graph.as_graph_def(add_shapes=True),
saver_def=saver_def)
self._summary_writer.add_graph(graph)
self._summary_writer.add_meta_graph(meta_graph_def)
return SessionRunArgs(self._global_step_tensor)
示例3: before_run
# 需要导入模块: from tensorflow.python.training import session_run_hook [as 别名]
# 或者: from tensorflow.python.training.session_run_hook import SessionRunArgs [as 别名]
def before_run(self, run_context):
if not self._wrapper_initialized:
# TODO(cais): Make this hook have a DumpingDebugWrapperSession property
# instead of subclassing DumpingDebugWrapperSession.
dumping_wrapper.DumpingDebugWrapperSession.__init__(
self,
run_context.session,
self._session_root,
watch_fn=self._watch_fn,
thread_name_filter=self._thread_name_filter,
log_usage=self._log_usage)
self._wrapper_initialized = True
self._run_call_count += 1
debug_urls, watch_options = self._prepare_run_watch_config(
run_context.original_args.fetches, run_context.original_args.feed_dict)
run_options = config_pb2.RunOptions()
debug_utils.watch_graph(
run_options,
run_context.session.graph,
debug_urls=debug_urls,
debug_ops=watch_options.debug_ops,
node_name_regex_whitelist=watch_options.node_name_regex_whitelist,
op_type_regex_whitelist=watch_options.op_type_regex_whitelist,
tensor_dtype_regex_whitelist=watch_options.tensor_dtype_regex_whitelist,
tolerate_debug_op_creation_failures=(
watch_options.tolerate_debug_op_creation_failures))
run_args = session_run_hook.SessionRunArgs(
None, feed_dict=None, options=run_options)
return run_args
示例4: before_run
# 需要导入模块: from tensorflow.python.training import session_run_hook [as 别名]
# 或者: from tensorflow.python.training.session_run_hook import SessionRunArgs [as 别名]
def before_run(self, run_context):
return session_run_hook.SessionRunArgs({
'evals_completed': self._evals_completed
})
示例5: run
# 需要导入模块: from tensorflow.python.training import session_run_hook [as 别名]
# 或者: from tensorflow.python.training.session_run_hook import SessionRunArgs [as 别名]
def run(self, fetches, feed_dict=None, options=None, run_metadata=None):
"""See base class."""
if self.should_stop():
raise RuntimeError('Run called even after should_stop requested.')
actual_fetches = {'caller': fetches}
run_context = session_run_hook.SessionRunContext(
original_args=session_run_hook.SessionRunArgs(fetches, feed_dict),
session=self._sess)
options = options or config_pb2.RunOptions()
feed_dict = self._call_hook_before_run(run_context, actual_fetches,
feed_dict, options)
# Do session run.
run_metadata = run_metadata or config_pb2.RunMetadata()
outputs = _WrappedSession.run(self,
fetches=actual_fetches,
feed_dict=feed_dict,
options=options,
run_metadata=run_metadata)
for hook in self._hooks:
hook.after_run(
run_context,
session_run_hook.SessionRunValues(
results=outputs[hook] if hook in outputs else None,
options=options,
run_metadata=run_metadata))
self._should_stop = self._should_stop or run_context.stop_requested
return outputs['caller']
示例6: before_run
# 需要导入模块: from tensorflow.python.training import session_run_hook [as 别名]
# 或者: from tensorflow.python.training.session_run_hook import SessionRunArgs [as 别名]
def before_run(self, run_context):
return session_run_hook.SessionRunArgs(
{'global_step': contrib_framework.get_global_step(),
'current_loss': run_context.session.graph.get_operation_by_name(
LOSS_NAME).outputs[0]})
示例7: before_run
# 需要导入模块: from tensorflow.python.training import session_run_hook [as 别名]
# 或者: from tensorflow.python.training.session_run_hook import SessionRunArgs [as 别名]
def before_run(self, run_context):
"""Return the update_weights op so that it is executed during this run."""
return session_run_hook.SessionRunArgs(self._update_op)
示例8: before_run
# 需要导入模块: from tensorflow.python.training import session_run_hook [as 别名]
# 或者: from tensorflow.python.training.session_run_hook import SessionRunArgs [as 别名]
def before_run(self, run_context):
del run_context
return SessionRunArgs(
fetches={KMeansClustering.LOSS_OP_NAME: self._loss_tensor})
示例9: before_run
# 需要导入模块: from tensorflow.python.training import session_run_hook [as 别名]
# 或者: from tensorflow.python.training.session_run_hook import SessionRunArgs [as 别名]
def before_run(self, run_context):
self._request_summary = (
self._next_step is None or
self._timer.should_trigger_for_step(self._next_step))
requests = {"global_step": self._global_step_tensor}
opts = (config_pb2.RunOptions(trace_level=config_pb2.RunOptions.FULL_TRACE)
if self._request_summary else None)
return SessionRunArgs(requests, options=opts)
示例10: before_run
# 需要导入模块: from tensorflow.python.training import session_run_hook [as 别名]
# 或者: from tensorflow.python.training.session_run_hook import SessionRunArgs [as 别名]
def before_run(self, run_context):
if not self._wrapper_initialized:
local_cli_wrapper.LocalCLIDebugWrapperSession.__init__(
self, run_context.session, ui_type=self._ui_type)
self._wrapper_initialized = True
# Increment run call counter.
self._run_call_count += 1
# Adapt run_context to an instance of OnRunStartRequest for invoking
# superclass on_run_start().
on_run_start_request = framework.OnRunStartRequest(
run_context.original_args.fetches, run_context.original_args.feed_dict,
None, None, self._run_call_count)
on_run_start_response = self.on_run_start(on_run_start_request)
self._performed_action = on_run_start_response.action
run_args = session_run_hook.SessionRunArgs(
None, feed_dict=None, options=config_pb2.RunOptions())
if self._performed_action == framework.OnRunStartAction.DEBUG_RUN:
self._decorate_options_for_debug(run_args.options,
run_context.session.graph)
elif self._performed_action == framework.OnRunStartAction.INVOKE_STEPPER:
# The _finalized property must be set to False so that the NodeStepper
# can insert ops for retrieving TensorHandles.
# pylint: disable=protected-access
run_context.session.graph._finalized = False
# pylint: enable=protected-access
self.invoke_node_stepper(
stepper.NodeStepper(run_context.session, run_context.original_args.
fetches, run_context.original_args.feed_dict),
restore_variable_values_on_exit=True)
return run_args
示例11: before_run
# 需要导入模块: from tensorflow.python.training import session_run_hook [as 别名]
# 或者: from tensorflow.python.training.session_run_hook import SessionRunArgs [as 别名]
def before_run(self, run_context): # pylint: disable=unused-argument
self._should_trigger = self._timer.should_trigger_for_step(self._iter_count)
if self._should_trigger:
return SessionRunArgs(self._current_tensors)
else:
return None
示例12: before_run
# 需要导入模块: from tensorflow.python.training import session_run_hook [as 别名]
# 或者: from tensorflow.python.training.session_run_hook import SessionRunArgs [as 别名]
def before_run(self, run_context):
del run_context
return SessionRunArgs(
fetches={KMeansClustering.LOSS_OP_NAME: self._loss_tensor})
示例13: before_run
# 需要导入模块: from tensorflow.python.training import session_run_hook [as 别名]
# 或者: from tensorflow.python.training.session_run_hook import SessionRunArgs [as 别名]
def before_run(self, run_context):
return session_run_hook.SessionRunArgs(self._updated_global_step)