本文整理汇总了Python中tensorflow.Summary方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.Summary方法的具体用法?Python tensorflow.Summary怎么用?Python tensorflow.Summary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.Summary方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_postdecode_hooks
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Summary [as 别名]
def run_postdecode_hooks(decode_hook_args):
"""Run hooks after decodes have run."""
hooks = decode_hook_args.problem.decode_hooks
if not hooks:
return
global_step = latest_checkpoint_step(decode_hook_args.estimator.model_dir)
if global_step is None:
tf.logging.info(
"Skipping decode hooks because no checkpoint yet available.")
return
tf.logging.info("Running decode hooks.")
parent_dir = os.path.join(decode_hook_args.output_dirs[0], os.pardir)
final_dir = os.path.join(parent_dir, "decode")
summary_writer = tf.summary.FileWriter(final_dir)
for hook in hooks:
# Isolate each hook in case it creates TF ops
with tf.Graph().as_default():
summaries = hook(decode_hook_args)
if summaries:
summary = tf.Summary(value=list(summaries))
summary_writer.add_summary(summary, global_step)
summary_writer.close()
tf.logging.info("Decode hooks done.")
示例2: image_summary
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Summary [as 别名]
def image_summary(self, tag, images, step):
"""Log a list of images."""
img_summaries = []
for i, img in enumerate(images):
# Write the image to a string
try:
s = StringIO()
except:
s = BytesIO()
scipy.misc.toimage(img).save(s, format="png")
# Create an Image object
img_sum = tf.Summary.Image(encoded_image_string=s.getvalue(),
height=img.shape[0],
width=img.shape[1])
# Create a Summary value
img_summaries.append(tf.Summary.Value(tag='%s/%d' % (tag, i), image=img_sum))
# Create and write Summary
summary = tf.Summary(value=img_summaries)
self.writer.add_summary(summary, step)
示例3: write_metrics
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Summary [as 别名]
def write_metrics(metrics, global_step, summary_dir):
"""Write metrics to a summary directory.
Args:
metrics: A dictionary containing metric names and values.
global_step: Global step at which the metrics are computed.
summary_dir: Directory to write tensorflow summaries to.
"""
logging.info('Writing metrics to tf summary.')
summary_writer = tf.summary.FileWriter(summary_dir)
for key in sorted(metrics):
summary = tf.Summary(value=[
tf.Summary.Value(tag=key, simple_value=metrics[key]),
])
summary_writer.add_summary(summary, global_step)
logging.info('%s: %f', key, metrics[key])
summary_writer.close()
logging.info('Metrics written to tf summary.')
示例4: log_summary
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Summary [as 别名]
def log_summary(self, reward, step, a_probs, picked_a, a_dim, discrete):
import tensorflow as tf
summary = tf.Summary()
summary.value.add(tag='Reward/per_episode', simple_value=float(reward))
if not discrete:
for i in range(a_dim):
prefix = "Action" + str(i)
summary.value.add(tag=prefix + '/mean', simple_value=float(a_probs[i]))
summary.value.add(tag=prefix + "/std", simple_value=float(a_probs[i + a_dim]))
summary.value.add(tag=prefix + '/picked', simple_value=float(picked_a[i]))
else:
for i in range(a_dim):
prefix = "Action" + str(i)
summary.value.add(tag=prefix + '/prob', simple_value=float(a_probs[i]))
summary.value.add(tag='Action/picked', simple_value=float(picked_a))
self.summary_writer.add_summary(summary, step)
self.summary_writer.flush()
示例5: write_metrics
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Summary [as 别名]
def write_metrics(metrics, global_step, summary_dir):
"""Write metrics to a summary directory.
Args:
metrics: A dictionary containing metric names and values.
global_step: Global step at which the metrics are computed.
summary_dir: Directory to write tensorflow summaries to.
"""
tf.logging.info('Writing metrics to tf summary.')
summary_writer = tf.summary.FileWriterCache.get(summary_dir)
for key in sorted(metrics):
summary = tf.Summary(value=[
tf.Summary.Value(tag=key, simple_value=metrics[key]),
])
summary_writer.add_summary(summary, global_step)
tf.logging.info('%s: %f', key, metrics[key])
tf.logging.info('Metrics written to tf summary.')
# TODO(rathodv): Add tests.
示例6: image_summary
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Summary [as 别名]
def image_summary(self, tag, images, step):
"""Log a list of images."""
img_summaries = []
for i, img in enumerate(images):
# Write the image to a string
try:
s = StringIO()
except ImportError:
s = BytesIO()
scipy.misc.toimage(img).save(s, format="png")
# Create an Image object
img_sum = tf.Summary.Image(encoded_image_string=s.getvalue(),
height=img.shape[0],
width=img.shape[1])
# Create a Summary value
img_summaries.append(tf.Summary.Value(tag='%s/%d' % (tag, i),
image=img_sum))
# Create and write Summary
summary = tf.Summary(value=img_summaries)
self.writer.add_summary(summary, step)
示例7: image_summary
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Summary [as 别名]
def image_summary(self, tag, images, step):
"""Log a list of images."""
img_summaries = []
for i, img_np in enumerate(images):
# Write the image to a buffer
s = BytesIO()
# torch image: C X H X W
# numpy image: H x W x C
img_np = img_np.transpose((1, 2, 0))
im = Image.fromarray(img_np.astype(np.uint8))
im.save(s, format='png')
# Create an Image object
img_summary = tf.Summary.Image(encoded_image_string=s.getvalue(),
height=img_np.shape[0],
width=img_np.shape[1])
# Create a Summary value
img_summaries.append(tf.Summary.Value(tag='%s/%d' % (tag, i), image=img_summary))
# Create and write Summary
summary = tf.Summary(value=img_summaries)
self.writer.add_summary(summary, step)
示例8: pil_image_to_tf_summary
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Summary [as 别名]
def pil_image_to_tf_summary(img, tag="debug_img"):
# serialise png bytes
sio = io.BytesIO()
img.save(sio, format="png")
png_bytes = sio.getvalue()
# https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/framework/summary.proto
return tf.Summary(value=[tf.Summary.Value(tag=tag,
image=tf.Summary.Image(height=img.size[0],
width=img.size[1],
colorspace=3, # RGB
encoded_image_string=png_bytes))])
#def dice_loss(y, y_hat, batch_size, smoothing=0):
# y = tf.reshape(y, (batch_size, -1))
# y_hat = tf.reshape(y_hat, (batch_size, -1))
# intersection = y * y_hat
# intersection_rs = tf.reduce_sum(intersection, axis=1)
# nom = intersection_rs + smoothing
# denom = tf.reduce_sum(y, axis=1) + tf.reduce_sum(y_hat, axis=1) + smoothing
# score = 2.0 * (nom / denom)
# loss = 1.0 - score
# loss = tf.Print(loss, [intersection, intersection_rs, nom, denom], first_n=100, summarize=10000)
# return loss
示例9: image_summary
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Summary [as 别名]
def image_summary(self, tag, images, step):
"""Log a list of images."""
# 图像信息 日志
img_summaries = []
for i, img in enumerate(images):
# Write the image to a string
try:
s = StringIO()
except:
s = BytesIO()
scipy.misc.toimage(img).save(s, format="png")
# Create an Image object
img_sum = tf.Summary.Image(encoded_image_string=s.getvalue(),
height=img.shape[0],
width=img.shape[1])
# Create a Summary value
img_summaries.append(tf.Summary.Value(tag='%s/%d' % (tag, i), image=img_sum))
# Create and write Summary
summary = tf.Summary(value=img_summaries)
self.writer.add_summary(summary, step)
示例10: save_variables_and_metagraph
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Summary [as 别名]
def save_variables_and_metagraph(sess, saver, summary_writer, model_dir, model_name, step):
# Save the model checkpoint
print('Saving variables')
start_time = time.time()
checkpoint_path = os.path.join(model_dir, 'model-%s.ckpt' % model_name)
saver.save(sess, checkpoint_path, global_step=step, write_meta_graph=False)
save_time_variables = time.time() - start_time
print('Variables saved in %.2f seconds' % save_time_variables)
metagraph_filename = os.path.join(model_dir, 'model-%s.meta' % model_name)
save_time_metagraph = 0
if not os.path.exists(metagraph_filename):
print('Saving metagraph')
start_time = time.time()
saver.export_meta_graph(metagraph_filename)
save_time_metagraph = time.time() - start_time
print('Metagraph saved in %.2f seconds' % save_time_metagraph)
summary = tf.Summary()
#pylint: disable=maybe-no-member
summary.value.add(tag='time/save_variables', simple_value=save_time_variables)
summary.value.add(tag='time/save_metagraph', simple_value=save_time_metagraph)
summary_writer.add_summary(summary, step)
示例11: log_images
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Summary [as 别名]
def log_images(self, tag, images, step):
"""Logs a list of images."""
im_summaries = []
for nr, img in enumerate(images):
# Write the image to a string
s = StringIO()
plt.imsave(s, img, format='png')
# Create an Image object
img_sum = tf.Summary.Image(
encoded_image_string=s.getvalue(),
height=img.shape[0],
width=img.shape[1])
# Create a Summary value
im_summaries.append(
tf.Summary.Value(tag='%s/%d' % (tag, nr), image=img_sum))
# Create and write Summary
summary = tf.Summary(value=im_summaries)
self.writer.add_summary(summary, step)
self.writer.flush()
示例12: _RunningAvgLoss
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Summary [as 别名]
def _RunningAvgLoss(loss, running_avg_loss, summary_writer, step, decay=0.999):
"""Calculate the running average of losses."""
if running_avg_loss == 0:
running_avg_loss = loss
else:
running_avg_loss = running_avg_loss * decay + (1 - decay) * loss
running_avg_loss = min(running_avg_loss, 12)
loss_sum = tf.Summary()
loss_sum.value.add(tag='running_avg_loss', simple_value=running_avg_loss)
summary_writer.add_summary(loss_sum, step)
sys.stdout.write('running_avg_loss: %f\n' % running_avg_loss)
return running_avg_loss
示例13: write_summary
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Summary [as 别名]
def write_summary(value, tag, summary_writer, global_step):
"""Write a single summary value to tensorboard"""
summary = tf.Summary()
summary.value.add(tag=tag, simple_value=value)
summary_writer.add_summary(summary, global_step)
示例14: log_value
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Summary [as 别名]
def log_value(self, tag, value, step):
summary = tf.Summary()
summary.value.add(tag=tag, simple_value=value)
self._summary_writer.add_summary(summary, step)
self._rows.append("{tag:.<25} {value}".format(tag=tag, value=value))
示例15: scalar_summary
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import Summary [as 别名]
def scalar_summary(self, tag, value, step):
"""Log a scalar variable."""
summary = tf.Summary(value=[tf.Summary.Value(tag=tag, simple_value=value)])
self.writer.add_summary(summary, step)