Python tensorflow.core.framework.summary_pb2.Summary() Examples

The following are 30 code examples of tensorflow.core.framework.summary_pb2.Summary(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tensorflow.core.framework.summary_pb2 , or try the search function .
Example #1
Source File: writer.py    From keras-lambda with MIT License 6 votes vote down vote up
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) 
Example #2
Source File: util_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
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? 
Example #3
Source File: util_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
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)) 
Example #4
Source File: head_test.py    From estimator with Apache License 2.0 6 votes vote down vote up
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) 
Example #5
Source File: graph_actions.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
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() 
Example #6
Source File: data_utils.py    From ULTRA with Apache License 2.0 6 votes vote down vote up
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
    ]) 
Example #7
Source File: writer.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
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) 
Example #8
Source File: estimator.py    From estimator with Apache License 2.0 6 votes vote down vote up
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() 
Example #9
Source File: head_utils.py    From estimator with Apache License 2.0 6 votes vote down vote up
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) 
Example #10
Source File: util_test.py    From lambda-packs with MIT License 6 votes vote down vote up
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? 
Example #11
Source File: util_test.py    From lambda-packs with MIT License 6 votes vote down vote up
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)) 
Example #12
Source File: base_head_test.py    From estimator with Apache License 2.0 6 votes vote down vote up
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) 
Example #13
Source File: graph_actions.py    From lambda-packs with MIT License 6 votes vote down vote up
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() 
Example #14
Source File: util_test.py    From deep_image_model with Apache License 2.0 6 votes vote down vote up
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? 
Example #15
Source File: writer.py    From deep_image_model with Apache License 2.0 6 votes vote down vote up
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) 
Example #16
Source File: writer.py    From lambda-packs with MIT License 6 votes vote down vote up
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) 
Example #17
Source File: event_file_inspector_test.py    From deep_image_model with Apache License 2.0 6 votes vote down vote up
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() 
Example #18
Source File: util_test.py    From deep_image_model with Apache License 2.0 6 votes vote down vote up
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)) 
Example #19
Source File: summary_format.py    From tensorlang with Apache License 2.0 5 votes vote down vote up
def parse(bytes, wall_time, step, visit):
  summary = summary_pb2.Summary()
  summary.ParseFromString(bytes)

  for value in summary.value:
    if value.HasField('tensor') and value.tag == HEALTH_PILL_EVENT_TAG:
      continue

    for summary_type, summary_func in _SUMMARY_TYPES.items():
      if value.HasField(summary_type):
        datum = getattr(value, summary_type)
        tag = value.node_name if summary_type == 'tensor' else value.tag
        parsed = summary_func(tag, wall_time, step, datum)
        visit(summary_type, parsed) 
Example #20
Source File: train.py    From cog with Apache License 2.0 5 votes vote down vote up
def evaluate(sess, model_val, n_batches, test_writer, global_step, trial,
             tuner, acc_train):
  t_start = time.time()
  acc_val_ = 0
  loss_val_ = 0
  for _ in range(n_batches):
    acc_tmp, loss_tmp, = sess.run([model_val.acc, model_val.loss])
    acc_val_ += acc_tmp
    loss_val_ += loss_tmp
  acc_val_ /= n_batches
  loss_val_ /= n_batches

  # Write summaries
  vals = [summary_pb2.Summary.Value(tag='summary/accuracy_val',
                                    simple_value=acc_val_),
          summary_pb2.Summary.Value(tag='summary/loss_val',
                                    simple_value=loss_val_)]
  test_writer.add_summary(summary_pb2.Summary(value=vals), trial)

  print('Step {:d} Trial {:d}'.format(global_step, trial))
  print('Evaluation took: {:0.2f}s'.format(time.time() - t_start))
  print('Accuracy training: {:0.4f}'.format(acc_train))
  print('Accuracy validation: {:0.4f}'.format(acc_val_))
  sys.stdout.flush()

  # Report the test set precision as the measure
  if tuner:
    tuner.report_measure(acc_val_, trial)

  return acc_val_ 
Example #21
Source File: vgsl_model.py    From ECO-pytorch with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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) 
Example #22
Source File: estimator_v2.py    From boxnet with GNU General Public License v3.0 5 votes vote down vote up
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() 
Example #23
Source File: vgsl_model.py    From hands-detection with MIT License 5 votes vote down vote up
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) 
Example #24
Source File: tensorboard_logger.py    From tensorboard_logger with MIT License 5 votes vote down vote up
def _image_summary(self, tf_name, images, step=None):
        """
        Log a list of images.

        References:
            https://github.com/yunjey/pytorch-tutorial/blob/master/tutorials/04-utils/tensorboard/logger.py#L22

        Example:
            >>> tf_name = 'foo'
            >>> value = ([0, 1, 2, 3, 4, 5], [1, 20, 10, 22, 11])
            >>> self = Logger(None, is_dummy=True)
            >>> images = [np.random.rand(10, 10), np.random.rand(10, 10)]
            >>> summary = self._image_summary(tf_name, images, step=None)
            >>> assert len(summary.value) == 2
            >>> assert summary.value[0].image.width == 10
        """
        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 = summary_pb2.Summary.Image(
                encoded_image_string=s.getvalue(),
                height=img.shape[0],
                width=img.shape[1]
            )
            # Create a Summary value
            img_value = summary_pb2.Summary.Value(tag='{}/{}'.format(tf_name, i),
                                                  image=img_sum)
            img_summaries.append(img_value)
            summary = summary_pb2.Summary()
            summary.value.add(tag=tf_name, image=img_sum)

        summary = summary_pb2.Summary(value=img_summaries)
        return summary 
Example #25
Source File: vgsl_model.py    From Action_Recognition_Zoo with MIT License 5 votes vote down vote up
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) 
Example #26
Source File: summaries.py    From FRU with MIT License 5 votes vote down vote up
def get_value_from_summary_string(tag, summary_str):
    """ get_value_from_summary_string.

    Retrieve a summary value from a summary string.

    Arguments:
        tag: `str`. The summary tag (name).
        summary_str: `str`. The summary string to look in.

    Returns:
        A `float`. The retrieved value.

    Raises:
        `Exception` if tag not found.

    """

    # Compatibility hotfix for the seq2seq example
    if tag == u'acc:0/':
        tag = u'acc_0/'

    # Fix for TF 0.12
    if tag[-1] == '/':
        tag = tag[:-1]
    summ = summary_pb2.Summary()
    summ.ParseFromString(summary_str)

    for row in summ.value:
        if row.tag.endswith(tag):
            return float(row.simple_value)

    raise ValueError("Tag: " + tag + " cannot be found in summaries list.") 
Example #27
Source File: tensorboard_logger.py    From tensorboard_logger with MIT License 5 votes vote down vote up
def _scalar_summary(self, tf_name, value, step=None):
        summary = summary_pb2.Summary()
        summary.value.add(tag=tf_name, simple_value=value)
        return summary 
Example #28
Source File: vgsl_model.py    From object_detection_kitti with Apache License 2.0 5 votes vote down vote up
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) 
Example #29
Source File: vgsl_model.py    From object_detection_with_tensorflow with MIT License 5 votes vote down vote up
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) 
Example #30
Source File: rhn_train.py    From iss-rnns with Apache License 2.0 5 votes vote down vote up
def write_scalar_summary(summary_writer, tag, value, step):
  value = summary_pb2.Summary.Value(tag=tag, simple_value=float(value))
  summary = summary_pb2.Summary(value=[value])
  summary_writer.add_summary(summary, step)