当前位置: 首页>>代码示例>>Python>>正文


Python tensorflow.Summary方法代码示例

本文整理汇总了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.") 
开发者ID:akzaidi,项目名称:fine-lm,代码行数:26,代码来源:decoding.py

示例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) 
开发者ID:guoruoqian,项目名称:cascade-rcnn_Pytorch,代码行数:24,代码来源:logger.py

示例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.') 
开发者ID:datitran,项目名称:object_detector_app,代码行数:20,代码来源:eval_util.py

示例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() 
开发者ID:jet-black,项目名称:ppo-lstm-parallel,代码行数:19,代码来源:master.py

示例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. 
开发者ID:ahmetozlu,项目名称:vehicle_counting_tensorflow,代码行数:22,代码来源:eval_util.py

示例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) 
开发者ID:Mariewelt,项目名称:OpenChem,代码行数:25,代码来源:logger.py

示例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) 
开发者ID:yangsiyu007,项目名称:SpaceNetExploration,代码行数:26,代码来源:logger.py

示例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 
开发者ID:matpalm,项目名称:bnn,代码行数:26,代码来源:util.py

示例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) 
开发者ID:MagicChuyi,项目名称:SlowFast-Network-pytorch,代码行数:24,代码来源:TF_logger.py

示例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) 
开发者ID:GaoangW,项目名称:TNT,代码行数:23,代码来源:train_tripletloss.py

示例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() 
开发者ID:akar43,项目名称:lsm,代码行数:24,代码来源:tensorboard_logging.py

示例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 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:14,代码来源:seq2seq_attention.py

示例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) 
开发者ID:xuwd11,项目名称:cs294-112_hws,代码行数:7,代码来源:model.py

示例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)) 
开发者ID:xuwd11,项目名称:cs294-112_hws,代码行数:8,代码来源:utils.py

示例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) 
开发者ID:guoruoqian,项目名称:cascade-rcnn_Pytorch,代码行数:6,代码来源:logger.py


注:本文中的tensorflow.Summary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。