本文整理汇总了Python中tensorflow.core.framework.summary_pb2.Summary.Value方法的典型用法代码示例。如果您正苦于以下问题:Python Summary.Value方法的具体用法?Python Summary.Value怎么用?Python Summary.Value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.core.framework.summary_pb2.Summary
的用法示例。
在下文中一共展示了Summary.Value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_loop
# 需要导入模块: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2.Summary import Value [as 别名]
def run_loop(self):
# Count the steps.
current_step = training_util.global_step(self._sess, self._step_counter)
added_steps = current_step - self._last_step
self._last_step = current_step
# Measure the elapsed time.
current_time = time.time()
elapsed_time = current_time - self._last_time
self._last_time = current_time
# Reports the number of steps done per second
if elapsed_time > 0.:
steps_per_sec = added_steps / elapsed_time
else:
steps_per_sec = float("inf")
summary = Summary(value=[Summary.Value(tag=self._summary_tag,
simple_value=steps_per_sec)])
if self._sv.summary_writer:
self._sv.summary_writer.add_summary(summary, current_step)
logging.log_first_n(logging.INFO, "%s: %g", 10,
self._summary_tag, steps_per_sec)
示例2: run_loop
# 需要导入模块: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2.Summary import Value [as 别名]
def run_loop(self):
# Count the steps.
current_step = training_util.global_step(self._sess, self._sv.global_step)
added_steps = current_step - self._last_step
self._last_step = current_step
# Measure the elapsed time.
current_time = time.time()
elapsed_time = current_time - self._last_time
self._last_time = current_time
# Reports the number of steps done per second
steps_per_sec = added_steps / elapsed_time
summary = Summary(value=[Summary.Value(tag=self._summary_tag,
simple_value=steps_per_sec)])
if self._sv.summary_writer:
self._sv.summary_writer.add_summary(summary, current_step)
logging.log_first_n(logging.INFO, "%s: %g", 10,
self._summary_tag, steps_per_sec)
示例3: scalar
# 需要导入模块: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2.Summary import Value [as 别名]
def scalar(name, scalar):
"""Outputs a `Summary` protocol buffer containing a single scalar value.
The generated Summary has a Tensor.proto containing the input Tensor.
Args:
name: A name for the generated node. Will also serve as the series name in
TensorBoard.
scalar: A real numeric Tensor containing a single value.
collections: Optional list of graph collections keys. The new summary op is
added to these collections. Defaults to `[GraphKeys.SUMMARIES]`.
Returns:
A scalar `Tensor` of type `string`. Which contains a `Summary` protobuf.
Raises:
ValueError: If tensor has the wrong shape or type.
"""
name = _clean_tag(name)
if not isinstance(scalar, float):
# try conversion, if failed then need handle by user.
scalar = float(scalar)
return Summary(value=[Summary.Value(tag=name, simple_value=scalar)])
示例4: histogram
# 需要导入模块: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2.Summary import Value [as 别名]
def histogram(name, values):
# pylint: disable=line-too-long
"""Outputs a `Summary` protocol buffer with a histogram.
The generated
[`Summary`](https://www.tensorflow.org/code/tensorflow/core/framework/summary.proto)
has one summary value containing a histogram for `values`.
This op reports an `InvalidArgument` error if any value is not finite.
Args:
name: A name for the generated node. Will also serve as a series name in
TensorBoard.
values: A real numeric `Tensor`. Any shape. Values to use to
build the histogram.
Returns:
A scalar `Tensor` of type `string`. The serialized `Summary` protocol
buffer.
"""
name = _clean_tag(name)
hist = make_histogram(values.astype(float))
return Summary(value=[Summary.Value(tag=name, histo=hist)])
示例5: audio
# 需要导入模块: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2.Summary import Value [as 别名]
def audio(tag, tensor, sample_rate):
"""Outputs a `Summary` protocol buffer with audio.
The audio is built from `tensor` which must be 2-D with shape `[num_frames,
channels]`.
Args:
tag: A name for the generated node. Will also serve as a series name in
TensorBoard.
tensor: A 2-D `int16` `Tensor` of shape `[num_frames, channels]`
sample_rate: An `int` declaring the sample rate for the provided audio
Returns:
A scalar `Tensor` of type `string`. The serialized `Summary` protocol
buffer.
"""
tag = _clean_tag(tag)
if len(tensor.shape) == 1:
num_frames, num_channels = len(tensor), 1
elif len(tensor.shape) == 2:
num_frames, num_channels = tensor.shape
else:
raise ValueError("audio must have 1 or 2 dimensions, not {}".format(len(tensor.shape)))
tensor = make_audio(tensor, sample_rate, num_frames, num_channels)
return Summary(value=[Summary.Value(tag=tag, audio=tensor)])
示例6: after_run
# 需要导入模块: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2.Summary import Value [as 别名]
def after_run(self, run_context, run_values):
_ = run_context
stale_global_step = run_values.results
if self._timer.should_trigger_for_step(stale_global_step+1):
# get the real value after train op.
global_step = run_context.session.run(self._global_step_tensor)
if self._timer.should_trigger_for_step(global_step):
elapsed_time, elapsed_steps = self._timer.update_last_triggered_step(
global_step)
if elapsed_time is not None:
steps_per_sec = elapsed_steps / elapsed_time
if self._summary_writer is not None:
summary = Summary(value=[Summary.Value(
tag=self._summary_tag, simple_value=steps_per_sec)])
self._summary_writer.add_summary(summary, global_step)
logging.info("%s: %g", self._summary_tag, steps_per_sec)
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:19,代码来源:basic_session_run_hooks.py
示例7: write_summary
# 需要导入模块: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2.Summary import Value [as 别名]
def write_summary(summary_writer, label, value, step):
"""Write a summary for a certain evaluation."""
summary = Summary(value=[Summary.Value(tag=label, simple_value=float(value))])
summary_writer.add_summary(summary, step)
summary_writer.flush()
示例8: after_run
# 需要导入模块: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2.Summary import Value [as 别名]
def after_run(self, run_context, run_values):
_ = run_context
global_step = run_values.results
if self._timer.should_trigger_for_step(global_step):
elapsed_time, elapsed_steps = self._timer.update_last_triggered_step(
global_step)
if elapsed_time is not None:
steps_per_sec = elapsed_steps / elapsed_time
if self._summary_writer is not None:
summary = Summary(value=[Summary.Value(
tag=self._summary_tag, simple_value=steps_per_sec)])
self._summary_writer.add_summary(summary, global_step)
logging.info("%s: %g", self._summary_tag, steps_per_sec)
示例9: every_n_step_end
# 需要导入模块: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2.Summary import Value [as 别名]
def every_n_step_end(self, current_step, outputs):
current_time = time.time()
if self._last_reported_time is not None and self._summary_writer:
added_steps = current_step - self._last_reported_step
elapsed_time = current_time - self._last_reported_time
steps_per_sec = added_steps / elapsed_time
summary = Summary(value=[Summary.Value(tag=self._summary_tag,
simple_value=steps_per_sec)])
self._summary_writer.add_summary(summary, current_step)
self._last_reported_step = current_step
self._last_reported_time = current_time
示例10: image
# 需要导入模块: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2.Summary import Value [as 别名]
def image(tag, tensor):
"""Outputs a `Summary` protocol buffer with images.
The summary has up to `max_images` summary values containing images. The
images are built from `tensor` which must be 3-D with shape `[height, width,
channels]` and where `channels` can be:
* 1: `tensor` is interpreted as Grayscale.
* 3: `tensor` is interpreted as RGB.
* 4: `tensor` is interpreted as RGBA.
The `name` in the outputted Summary.Value protobufs is generated based on the
name, with a suffix depending on the max_outputs setting:
* If `max_outputs` is 1, the summary value tag is '*name*/image'.
* If `max_outputs` is greater than 1, the summary value tags are
generated sequentially as '*name*/image/0', '*name*/image/1', etc.
Args:
tag: A name for the generated node. Will also serve as a series name in
TensorBoard.
tensor: A 3-D `uint8` or `float32` `Tensor` of shape `[height, width,
channels]` where `channels` is 1, 3, or 4.
Returns:
A scalar `Tensor` of type `string`. The serialized `Summary` protocol
buffer.
"""
tag = _clean_tag(tag)
if not isinstance(tensor, np.ndarray):
# try conversion, if failed then need handle by user.
tensor = np.ndarray(tensor, dtype=np.float32)
shape = tensor.shape
height, width, channel = shape[0], shape[1], shape[2]
if channel == 1:
# walk around. PIL's setting on dimension.
tensor = np.reshape(tensor, (height, width))
image = make_image(tensor, height, width, channel)
return Summary(value=[Summary.Value(tag=tag, image=image)])
示例11: _log_and_record
# 需要导入模块: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2.Summary import Value [as 别名]
def _log_and_record(self, elapsed_steps, elapsed_time, global_step):
global_step_per_sec = elapsed_steps / elapsed_time
examples_per_sec = self._batch_size * global_step_per_sec
if self._summary_writer is not None:
global_step_summary = Summary(value=[
Summary.Value(tag='global_step/sec', simple_value=global_step_per_sec)
])
example_summary = Summary(value=[
Summary.Value(tag='examples/sec', simple_value=examples_per_sec)
])
self._summary_writer.add_summary(global_step_summary, global_step)
self._summary_writer.add_summary(example_summary, global_step)
logging.info('global_step/sec: %g', global_step_per_sec)
logging.info('examples/sec: %g', examples_per_sec)
示例12: write_hptuning_metric
# 需要导入模块: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2.Summary import Value [as 别名]
def write_hptuning_metric(args, metric):
"""
Write a summary containing the tuning loss metric, as required by hyperparam tuning.
"""
summary = Summary(value=[Summary.Value(tag='training/hptuning/metric', simple_value=metric)])
# for hyperparam tuning, we write a summary log to a directory 'eval' below the job directory
eval_path = os.path.join(args['output_dir'], 'eval')
summary_writer = tf.summary.FileWriter(eval_path)
# Note: adding the summary to the writer is enough for hyperparam tuning.
# The ml engine system is looking for any summary added with the hyperparam metric tag.
summary_writer.add_summary(summary)
summary_writer.flush()
示例13: add_summary
# 需要导入模块: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2.Summary import Value [as 别名]
def add_summary(self, summary_tag, summary_value, global_step):
""" Adds summary at specific step.
Args:
summary_tag: A string, the name of the summary.
summary_value: The value of the summary at current step.
global_step: The step.
"""
summary = Summary(value=[Summary.Value(
tag=summary_tag, simple_value=summary_value)])
self._summary_writer.add_summary(summary, global_step)
self._summary_writer.flush()
示例14: add_entry
# 需要导入模块: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2.Summary import Value [as 别名]
def add_entry(self, index, tag, value, **kwargs):
if "image" in kwargs and value is not None:
image_string = tf.image.encode_jpeg(value, optimize_size=True, quality=80)
summary_value = Summary.Image(width=value.shape[1],
height=value.shape[0],
colorspace=value.shape[2],
encoded_image_string=image_string)
else:
summary_value = Summary.Value(tag=tag, simple_value=value)
if summary_value is not None:
entry = Summary(value=[summary_value])
self._train_writer.add_summary(entry, index)
示例15: tf_scalar_summary
# 需要导入模块: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2.Summary import Value [as 别名]
def tf_scalar_summary(vals):
# pylint: disable=import-error,no-name-in-module
from tensorflow.core.framework.summary_pb2 import Summary
return Summary(
value=[Summary.Value(tag=key, simple_value=val) for key, val in vals.items()]
)