本文整理汇总了Python中tensorflow.core.framework.summary_pb2.Summary方法的典型用法代码示例。如果您正苦于以下问题:Python summary_pb2.Summary方法的具体用法?Python summary_pb2.Summary怎么用?Python summary_pb2.Summary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.core.framework.summary_pb2
的用法示例。
在下文中一共展示了summary_pb2.Summary方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_summary
# 需要导入模块: from tensorflow.core.framework import summary_pb2 [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
def add_summary(self, summary, global_step=None):
"""Adds a `Summary` protocol buffer to the event file.
This method wraps the provided summary in an `Event` protocol buffer
and adds it to the event file.
You can pass the result of evaluating any summary op, using
@{tf.Session.run} or
@{tf.Tensor.eval}, to this
function. Alternatively, you can pass a `tf.Summary` protocol
buffer that you populate with your own data. The latter is
commonly done to report evaluation results in event files.
Args:
summary: A `Summary` protocol buffer, optionally serialized as a string.
global_step: Number. Optional global step value to record with the
summary.
"""
if isinstance(summary, bytes):
summ = summary_pb2.Summary()
summ.ParseFromString(summary)
summary = summ
event = event_pb2.Event(summary=summary)
self._add_event(event, global_step)
示例2: _write_summary_results
# 需要导入模块: from tensorflow.core.framework import summary_pb2 [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
def _write_summary_results(output_dir, eval_results, current_global_step):
"""Writes eval results into summary file in given dir."""
logging.info('Saving evaluation summary for step %d: %s', current_global_step,
_eval_results_to_str(eval_results))
summary_writer = get_summary_writer(output_dir)
summary = summary_pb2.Summary()
for key in eval_results:
if eval_results[key] is None:
continue
value = summary.value.add()
value.tag = key
if (isinstance(eval_results[key], np.float32) or
isinstance(eval_results[key], float)):
value.simple_value = float(eval_results[key])
else:
logging.warn('Skipping summary for %s, must be a float or np.float32.',
key)
summary_writer.add_summary(summary, current_global_step)
summary_writer.flush()
示例3: assert_summary
# 需要导入模块: from tensorflow.core.framework import summary_pb2 [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
def assert_summary(expected_tags, expected_simple_values, summary_proto):
"""Asserts summary contains the specified tags and values.
Args:
expected_tags: All tags in summary.
expected_simple_values: Simply values for some tags.
summary_proto: Summary to validate.
Raises:
ValueError: if expectations are not met.
"""
actual_tags = set()
for value in summary_proto.value:
actual_tags.add(value.tag)
if value.tag in expected_simple_values:
expected = expected_simple_values[value.tag]
actual = value.simple_value
np.testing.assert_almost_equal(
actual, expected, decimal=2, err_msg=value.tag)
expected_tags = set(expected_tags)
if expected_tags != actual_tags:
raise ValueError('Expected tags %s, got %s.' % (expected_tags, actual_tags))
示例4: to_summary_proto
# 需要导入模块: from tensorflow.core.framework import summary_pb2 [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
def to_summary_proto(summary_str):
"""Create summary based on latest stats.
Args:
summary_str: Serialized summary.
Returns:
summary_pb2.Summary.
Raises:
ValueError: if tensor is not a valid summary tensor.
"""
summary = summary_pb2.Summary()
summary.ParseFromString(summary_str)
return summary
# TODO(ptucker): Move to a non-test package?
示例5: add_summary
# 需要导入模块: from tensorflow.core.framework import summary_pb2 [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
def add_summary(self, summary, global_step=None):
"""Adds a `Summary` protocol buffer to the event file.
This method wraps the provided summary in an `Event` protocol buffer
and adds it to the event file.
You can pass the result of evaluating any summary op, using
[`Session.run()`](client.md#Session.run) or
[`Tensor.eval()`](framework.md#Tensor.eval), to this
function. Alternatively, you can pass a `tf.Summary` protocol
buffer that you populate with your own data. The latter is
commonly done to report evaluation results in event files.
Args:
summary: A `Summary` protocol buffer, optionally serialized as a string.
global_step: Number. Optional global step value to record with the
summary.
"""
if isinstance(summary, bytes):
summ = summary_pb2.Summary()
summ.ParseFromString(summary)
summary = summ
event = event_pb2.Event(summary=summary)
self._add_event(event, global_step)
示例6: _WriteScalarSummaries
# 需要导入模块: from tensorflow.core.framework import summary_pb2 [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
def _WriteScalarSummaries(self, data, subdirs=('',)):
# Writes data to a tempfile in subdirs, and returns generator for the data.
# If subdirs is given, writes data identically to all subdirectories.
for subdir_ in subdirs:
subdir = os.path.join(self.logdir, subdir_)
self._MakeDirectoryIfNotExists(subdir)
sw = SummaryWriter(subdir)
for datum in data:
summary = Summary()
if 'simple_value' in datum:
summary.value.add(tag=datum['tag'],
simple_value=datum['simple_value'])
sw.add_summary(summary, global_step=datum['step'])
elif 'histo' in datum:
summary.value.add(tag=datum['tag'], histo=HistogramProto())
sw.add_summary(summary, global_step=datum['step'])
elif 'session_log' in datum:
sw.add_session_log(datum['session_log'], global_step=datum['step'])
sw.close()
示例7: merge_TFSummary
# 需要导入模块: from tensorflow.core.framework import summary_pb2 [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
def merge_TFSummary(summary_list, weights):
merged_values = {}
weight_sum_map = {}
for i in range(len(summary_list)):
summary = summary_list[i]
if isinstance(summary, bytes):
parse_TFSummary_from_bytes(summary)
summ = summary_pb2.Summary()
summ.ParseFromString(summary)
summary = summ
for e in summary.value:
if e.tag not in merged_values:
merged_values[e.tag] = 0.0
weight_sum_map[e.tag] = 0.0
merged_values[e.tag] += e.simple_value * weights[i]
weight_sum_map[e.tag] += weights[i]
for k in merged_values:
merged_values[k] /= max(0.0000001, weight_sum_map[k])
return tf.Summary(value=[
tf.Summary.Value(tag=k, simple_value=merged_values[k]) for k in merged_values
])
示例8: _assert_simple_summaries
# 需要导入模块: from tensorflow.core.framework import summary_pb2 [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
def _assert_simple_summaries(test_case,
expected_summaries,
summary_str,
tol=1e-6):
"""Assert summary the specified simple values.
Args:
test_case: test case.
expected_summaries: Dict of expected tags and simple values.
summary_str: Serialized `summary_pb2.Summary`.
tol: Tolerance for relative and absolute.
"""
summary = summary_pb2.Summary()
summary.ParseFromString(summary_str)
test_case.assertAllClose(
expected_summaries, {v.tag: v.simple_value for v in summary.value},
rtol=tol,
atol=tol)
示例9: _write_checkpoint_path_to_summary
# 需要导入模块: from tensorflow.core.framework import summary_pb2 [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
def _write_checkpoint_path_to_summary(output_dir, checkpoint_path,
current_global_step):
"""Writes `checkpoint_path` into summary file in the given output directory.
Args:
output_dir: `str`, directory to write the summary file in.
checkpoint_path: `str`, checkpoint file path to be written to summary file.
current_global_step: `int`, the current global step.
"""
checkpoint_path_tag = 'checkpoint_path'
tf.compat.v1.logging.info('Saving \'%s\' summary for global step %d: %s',
checkpoint_path_tag, current_global_step,
checkpoint_path)
summary_proto = summary_pb2.Summary()
summary_proto.value.add(
tag=checkpoint_path_tag,
tensor=tf.make_tensor_proto(checkpoint_path, dtype=tf.dtypes.string))
summary_writer = tf.compat.v1.summary.FileWriterCache.get(output_dir)
summary_writer.add_summary(summary_proto, current_global_step)
summary_writer.flush()
示例10: _AddRateToSummary
# 需要导入模块: from tensorflow.core.framework import summary_pb2 [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
def _AddRateToSummary(tag, rate, step, sw):
"""Adds the given rate to the summary with the given tag.
Args:
tag: Name for this value.
rate: Value to add to the summary. Perhaps an error rate.
step: Global step of the graph for the x-coordinate of the summary.
sw: Summary writer to which to write the rate value.
"""
sw.add_summary(
summary_pb2.Summary(value=[summary_pb2.Summary.Value(
tag=tag, simple_value=rate)]), step)
示例11: make_summary
# 需要导入模块: from tensorflow.core.framework import summary_pb2 [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
def make_summary(name, val):
return summary_pb2.Summary(value=[summary_pb2.Summary.Value(tag=name, simple_value=val)])
示例12: _write_dict_to_summary
# 需要导入模块: from tensorflow.core.framework import summary_pb2 [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
def _write_dict_to_summary(output_dir,
dictionary,
current_global_step):
"""Writes a `dict` into summary file in given output directory.
Args:
output_dir: `str`, directory to write the summary file in.
dictionary: the `dict` to be written to summary file.
current_global_step: `int`, the current global step.
"""
logging.info('Saving dict for global step %d: %s', current_global_step,
_dict_to_str(dictionary))
summary_writer = writer_cache.FileWriterCache.get(output_dir)
summary_proto = summary_pb2.Summary()
for key in dictionary:
if dictionary[key] is None:
continue
if key == "global_step":
continue
value = summary_proto.value.add()
value.tag = key
if (isinstance(dictionary[key], np.float32) or
isinstance(dictionary[key], float)):
value.simple_value = float(dictionary[key])
elif (isinstance(dictionary[key], np.int64) or
isinstance(dictionary[key], np.int32) or
isinstance(dictionary[key], int)):
value.simple_value = int(dictionary[key])
else:
logging.warn('Skipping summary for %s, must be a float, np.float32, np.int64, np.int32 or int.',
key)
summary_writer.add_summary(summary_proto, current_global_step)
summary_writer.flush()
示例13: add_summary
# 需要导入模块: from tensorflow.core.framework import summary_pb2 [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
def add_summary(self, summary, global_step=None):
"""Adds a `Summary` protocol buffer to the event file.
This method wraps the provided summary in an `Event` protocol buffer
and adds it to the event file.
You can pass the result of evaluating any summary op, using
@{tf.Session.run} or
@{tf.Tensor.eval}, to this
function. Alternatively, you can pass a `tf.Summary` protocol
buffer that you populate with your own data. The latter is
commonly done to report evaluation results in event files.
Args:
summary: A `Summary` protocol buffer, optionally serialized as a string.
global_step: Number. Optional global step value to record with the
summary.
"""
if isinstance(summary, bytes):
summ = summary_pb2.Summary()
summ.ParseFromString(summary)
summary = summ
event = event_pb2.Event(wall_time=time.time(), summary=summary)
if global_step is not None:
event.step = int(global_step)
self.add_event(event)
示例14: add_summary
# 需要导入模块: from tensorflow.core.framework import summary_pb2 [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
def add_summary(self, summ, current_global_step):
"""Add summary."""
if isinstance(summ, bytes):
summary_proto = summary_pb2.Summary()
summary_proto.ParseFromString(summ)
summ = summary_proto
if current_global_step in self._summaries:
step_summaries = self._summaries[current_global_step]
else:
step_summaries = []
self._summaries[current_global_step] = step_summaries
step_summaries.append(summ)
# NOTE: Ignore global_step since its value is non-deterministic.
示例15: simple_values_from_events
# 需要导入模块: from tensorflow.core.framework import summary_pb2 [as 别名]
# 或者: from tensorflow.core.framework.summary_pb2 import Summary [as 别名]
def simple_values_from_events(events, tags):
"""Parse summaries from events with simple_value.
Args:
events: List of tensorflow.Event protos.
tags: List of string event tags corresponding to simple_value summaries.
Returns:
dict of tag:value.
Raises:
ValueError: if a summary with a specified tag does not contain simple_value.
"""
step_by_tag = {}
value_by_tag = {}
for e in events:
if e.HasField('summary'):
for v in e.summary.value:
tag = v.tag
if tag in tags:
if not v.HasField('simple_value'):
raise ValueError('Summary for %s is not a simple_value.' % tag)
# The events are mostly sorted in step order, but we explicitly check
# just in case.
if tag not in step_by_tag or e.step > step_by_tag[tag]:
step_by_tag[tag] = e.step
value_by_tag[tag] = v.simple_value
return value_by_tag