Esempio n. 1
0
def _image3_animated_gif(tag: str,
                         image: Union[np.array, torch.Tensor],
                         scale_factor: float = 1):
    """Function to actually create the animated gif.
    Args:
        tag (str): Data identifier
        image (np.array or Tensor): 3D image tensors expected to be in `HWD` format
        scale_factor (float): amount to multiply values by. if the image data is between 0 and 1, using 255 for this value will
        scale it to displayable range
    """
    assert len(
        image.shape
    ) == 3, "3D image tensors expected to be in `HWD` format, len(image.shape) != 3"

    ims = [(np.asarray((image[:, :, i])) * scale_factor).astype(np.uint8)
           for i in range(image.shape[2])]
    ims = [GifImage.fromarray(im) for im in ims]
    img_str = b""
    for b_data in PIL.GifImagePlugin.getheader(ims[0])[0]:
        img_str += b_data
    img_str += b"\x21\xFF\x0B\x4E\x45\x54\x53\x43\x41\x50" b"\x45\x32\x2E\x30\x03\x01\x00\x00\x00"
    for i in ims:
        for b_data in PIL.GifImagePlugin.getdata(i):
            img_str += b_data
    img_str += b"\x3B"
    summary_image_str = summary_pb2.Summary.Image(height=10,
                                                  width=10,
                                                  colorspace=1,
                                                  encoded_image_string=img_str)
    image_summary = summary_pb2.Summary.Value(tag=tag, image=summary_image_str)
    return summary_pb2.Summary(value=[image_summary])
Esempio n. 2
0
def text_pb(tag, data, description=None):
    """Create a text tf.Summary protobuf.

  Arguments:
    tag: String tag for the summary.
    data: A Python bytestring (of type bytes), a Unicode string, or a numpy data
      array of those types.
    description: Optional long-form description for this summary, as a `str`.
      Markdown is supported. Defaults to empty.

  Raises:
    TypeError: If the type of the data is unsupported.

  Returns:
    A `tf.Summary` protobuf object.
  """
    try:
        tensor = tensor_util.make_tensor_proto(data, dtype=np.object)
    except TypeError as e:
        raise TypeError('tensor must be of type string', e)
    summary_metadata = metadata.create_summary_metadata(
        display_name=None, description=description)
    summary = summary_pb2.Summary()
    summary.value.add(tag=tag, metadata=summary_metadata, tensor=tensor)
    return summary
Esempio n. 3
0
 def __call__(self):
     entries = []
     for tag, value in self.items():
         if isinstance(value, DelayedScalar):
             entries.append(
                 summary_pb2.Summary.Value(tag=tag, simple_value=value()))
         elif isinstance(value, Image):
             image_summary = summary_pb2.Summary.Image(
                 encoded_image_string=value.png,
                 colorspace=value.shape[0],
                 height=value.shape[1],
                 width=value.shape[2])
             entries.append(
                 summary_pb2.Summary.Value(tag=tag, image=image_summary))
         elif isinstance(value, Text):
             metadata = summary_pb2.SummaryMetadata(
                 plugin_data=summary_pb2.SummaryMetadata.PluginData(
                     plugin_name='text'))
             entries.append(
                 summary_pb2.Summary.Value(
                     tag=tag,
                     metadata=metadata,
                     tensor=make_tensor_proto(
                         values=value.text.encode('utf-8'), shape=(1, ))))
         else:
             raise NotImplementedError(tag, value)
     return summary_pb2.Summary(value=entries)
Esempio n. 4
0
def text_pb(tag, data, description=None):
    """Create a text tf.Summary protobuf.

  Arguments:
    tag: String tag for the summary.
    data: A Python bytestring (of type bytes), a Unicode string, or a numpy data
      array of those types.
    description: Optional long-form description for this summary, as a `str`.
      Markdown is supported. Defaults to empty.

  Raises:
    TypeError: If the type of the data is unsupported.

  Returns:
    A `tf.Summary` protobuf object.
  """
    # TODO(nickfelt): remove on-demand imports once dep situation is fixed.
    from tensorboard.compat import tf
    try:
        tensor = tensor_util.make_tensor_proto(data, dtype=tf.string)
    except TypeError as e:
        raise TypeError("tensor must be of type string", e)
    summary_metadata = metadata.create_summary_metadata(
        display_name=None, description=description)
    summary = summary_pb2.Summary()
    summary.value.add(tag=tag, metadata=summary_metadata, tensor=tensor)
    return summary
Esempio n. 5
0
def scalar_pb(tag, data, description=None):
    """Create a scalar summary_pb2.Summary protobuf.

  Arguments:
    tag: String tag for the summary.
    data: A 0-dimensional `np.array` or a compatible python number type.
    description: Optional long-form description for this summary, as a
      `str`. Markdown is supported. Defaults to empty.

  Raises:
    ValueError: If the type or shape of the data is unsupported.

  Returns:
    A `summary_pb2.Summary` protobuf object.
  """
    arr = np.array(data)
    if arr.shape != ():
        raise ValueError('Expected scalar shape for tensor, got shape: %s.' %
                         arr.shape)
    if arr.dtype.kind not in ('b', 'i', 'u', 'f'):  # bool, int, uint, float
        raise ValueError('Cast %s to float is not supported' % arr.dtype.name)
    tensor_proto = tensor_util.make_tensor_proto(arr.astype(np.float32))
    summary_metadata = metadata.create_summary_metadata(
        display_name=None, description=description)
    summary = summary_pb2.Summary()
    summary.value.add(tag=tag, metadata=summary_metadata, tensor=tensor_proto)
    return summary
Esempio n. 6
0
 def AddHistogram(
     self,
     tag,
     wall_time=0,
     step=0,
     hmin=1,
     hmax=2,
     hnum=3,
     hsum=4,
     hsum_squares=5,
     hbucket_limit=None,
     hbucket=None,
 ):
     histo = summary_pb2.HistogramProto(
         min=hmin,
         max=hmax,
         num=hnum,
         sum=hsum,
         sum_squares=hsum_squares,
         bucket_limit=hbucket_limit,
         bucket=hbucket,
     )
     event = event_pb2.Event(
         wall_time=wall_time,
         step=step,
         summary=summary_pb2.Summary(
             value=[summary_pb2.Summary.Value(tag=tag, histo=histo)]),
     )
     self.AddEvent(event)
Esempio n. 7
0
    def add_3dvolume(self, volume, tag, global_step=None, walltime=None):
        filename = tag + "_"
        if global_step is None:
            filename += datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
        else:
            filename += str(global_step)

        if isinstance(volume, torch.Tensor):
            volume = volume.detach().cpu().numpy()

        img = ants.from_numpy(volume)
        ants.image_write(img, os.path.join(self._log_dir,
                                           filename + ".nii.gz"))

        plugin_data = tf.SummaryMetadata.PluginData(
            plugin_name="tb_3d_volume_plugin",
            content=TextPluginData(version=0).SerializeToString())
        metadata = tf.SummaryMetadata(plugin_data=plugin_data)
        tensor = TensorProto(
            dtype='DT_STRING',
            string_val=[filename.encode(encoding='utf_8')],
            tensor_shape=TensorShapeProto(dim=[TensorShapeProto.Dim(size=1)]))
        summary = summary_pb2.Summary(value=[
            summary_pb2.Summary.Value(
                tag=tag, metadata=metadata, tensor=tensor)
        ])
        self._file_writer.add_summary(summary,
                                      global_step=global_step,
                                      walltime=walltime)
        self._file_writer.flush()
Esempio n. 8
0
def mesh_pb(tag,
            vertices,
            faces=None,
            colors=None,
            config_dict=None,
            description=None):
    """Create a mesh summary to save in pb format.

    Args:
      tag: String tag for the summary.
      vertices: numpy array of shape `[dim_1, ..., dim_n, 3]` representing the 3D
        coordinates of vertices.
      faces: numpy array of shape `[dim_1, ..., dim_n, 3]` containing indices of
        vertices within each triangle.
      colors: numpy array of shape `[dim_1, ..., dim_n, 3]` containing colors for
        each vertex.
      config_dict: Dictionary with ThreeJS classes names and configuration.
      description: Optional long-form description for this summary, as a
        constant `str`. Markdown is supported. Defaults to empty.

    Returns:
      Instance of tf.Summary class.
    """
    json_config = _get_json_config(config_dict)

    summaries = []
    tensors = [
        metadata.MeshTensor(vertices, plugin_data_pb2.MeshPluginData.VERTEX,
                            tf.float32),
        metadata.MeshTensor(faces, plugin_data_pb2.MeshPluginData.FACE,
                            tf.int32),
        metadata.MeshTensor(colors, plugin_data_pb2.MeshPluginData.COLOR,
                            tf.uint8),
    ]
    tensors = [tensor for tensor in tensors if tensor.data is not None]
    components = metadata.get_components_bitmask(
        [tensor.content_type for tensor in tensors])
    for tensor in tensors:
        shape = tensor.data.shape
        shape = [dim if dim is not None else -1 for dim in shape]
        tensor_proto = tensor_util.make_tensor_proto(tensor.data,
                                                     dtype=tensor.data_type)
        summary_metadata = metadata.create_summary_metadata(
            tag,
            None,  # display_name
            tensor.content_type,
            components,
            shape,
            description,
            json_config=json_config,
        )
        instance_tag = metadata.get_instance_name(tag, tensor.content_type)
        summaries.append((instance_tag, summary_metadata, tensor_proto))

    summary = summary_pb2.Summary()
    for instance_tag, summary_metadata, tensor_proto in summaries:
        summary.value.add(tag=instance_tag,
                          metadata=summary_metadata,
                          tensor=tensor_proto)
    return summary
Esempio n. 9
0
def _image3_animated_gif(imp, scale_factor=1):
    """
    Function to actually create the animated gif.
    Args:
        imp: tuple of tag and a list of image tensors
        scale_factor: amount to multiply values by. if the image data is between 0 and 1, using 255 for this value will
        scale it to displayable range
    """

    (tag, ims) = imp
    ims = [(np.asarray((ims[:, :, i])) * scale_factor).astype(np.uint8)
           for i in range(ims.shape[2])]
    ims = [GifImage.fromarray(im) for im in ims]
    img_str = b''
    for b_data in PIL.GifImagePlugin.getheader(ims[0])[0]:
        img_str += b_data
    img_str += b'\x21\xFF\x0B\x4E\x45\x54\x53\x43\x41\x50' \
               b'\x45\x32\x2E\x30\x03\x01\x00\x00\x00'
    for i in ims:
        for b_data in PIL.GifImagePlugin.getdata(i):
            img_str += b_data
    img_str += b'\x3B'
    summary_image_str = summary_pb2.Summary.Image(height=10,
                                                  width=10,
                                                  colorspace=1,
                                                  encoded_image_string=img_str)
    image_summary = summary_pb2.Summary.Value(tag=tag, image=summary_image_str)
    return summary_pb2.Summary(value=[image_summary])
Esempio n. 10
0
 def AddScalar(self, tag, wall_time=0, step=0, value=0):
     event = event_pb2.Event(
         wall_time=wall_time,
         step=step,
         summary=summary_pb2.Summary(
             value=[summary_pb2.Summary.Value(tag=tag, simple_value=value)
                    ]))
     self.AddEvent(event)
Esempio n. 11
0
 def _GenerateEventsData(self):
     with test_util.FileWriterCache.get(self.log_dir) as fw:
         event = event_pb2.Event(
             wall_time=1,
             step=1,
             summary=summary_pb2.Summary(value=[
                 summary_pb2.Summary.Value(tag='s1', simple_value=0)
             ]))
         fw.add_event(event)
Esempio n. 12
0
def histogram_pb(tag, data, buckets=None, description=None):
    """Create a histogram summary protobuf.

  Arguments:
    tag: String tag for the summary.
    data: A `np.array` or array-like form of any shape. Must have type
      castable to `float`.
    buckets: Optional positive `int`. The output will have this
      many buckets, except in two edge cases. If there is no data, then
      there are no buckets. If there is data but all points have the
      same value, then there is one bucket whose left and right
      endpoints are the same.
    description: Optional long-form description for this summary, as a
      `str`. Markdown is supported. Defaults to empty.

  Returns:
    A `summary_pb2.Summary` protobuf object.
  """
    # TODO(nickfelt): remove on-demand imports once dep situation is fixed.
    from tensorboard.compat import tf
    bucket_count = DEFAULT_BUCKET_COUNT if buckets is None else buckets
    data = np.array(data).flatten().astype(float)
    if data.size == 0:
        buckets = np.array([]).reshape((0, 3))
    else:
        min_ = np.min(data)
        max_ = np.max(data)
        range_ = max_ - min_
        if range_ == 0:
            center = min_
            buckets = np.array([[center - 0.5, center + 0.5,
                                 float(data.size)]])
        else:
            bucket_width = range_ / bucket_count
            offsets = data - min_
            bucket_indices = np.floor(offsets / bucket_width).astype(int)
            clamped_indices = np.minimum(bucket_indices, bucket_count - 1)
            one_hots = (np.array([clamped_indices
                                  ]).transpose() == np.arange(0, bucket_count)
                        )  # broadcast
            assert one_hots.shape == (data.size,
                                      bucket_count), (one_hots.shape,
                                                      (data.size,
                                                       bucket_count))
            bucket_counts = np.sum(one_hots, axis=0)
            edges = np.linspace(min_, max_, bucket_count + 1)
            left_edges = edges[:-1]
            right_edges = edges[1:]
            buckets = np.array([left_edges, right_edges,
                                bucket_counts]).transpose()
    tensor = tensor_util.make_tensor_proto(buckets, dtype=tf.float64)

    summary_metadata = metadata.create_summary_metadata(
        display_name=None, description=description)
    summary = summary_pb2.Summary()
    summary.value.add(tag=tag, metadata=summary_metadata, tensor=tensor)
    return summary
Esempio n. 13
0
 def _value_from_op(self, op):
     with tf.Session() as sess:
         summary_pbtxt = sess.run(op)
     summary = summary_pb2.Summary()
     summary.ParseFromString(summary_pbtxt)
     # There may be multiple values (e.g., for an image summary that emits
     # multiple images in one batch). That's fine; we'll choose any
     # representative value, assuming that they're homogeneous.
     assert summary.value
     return summary.value[0]
Esempio n. 14
0
def histogram_pb(tag, data, buckets=None, description=None):
    """Create a histogram summary protobuf.

    Arguments:
      tag: String tag for the summary.
      data: A `np.array` or array-like form of any shape. Must have type
        castable to `float`.
      buckets: Optional positive `int`. The output shape will always be
        [buckets, 3]. If there is no data, then an all-zero array of shape
        [buckets, 3] will be returned. If there is data but all points have
        the same value, then all buckets' left and right endpoints are the
        same and only the last bucket has nonzero count.
      description: Optional long-form description for this summary, as a
        `str`. Markdown is supported. Defaults to empty.

    Returns:
      A `summary_pb2.Summary` protobuf object.
    """
    bucket_count = DEFAULT_BUCKET_COUNT if buckets is None else buckets
    data = np.array(data).flatten().astype(float)
    if bucket_count == 0 or data.size == 0:
        histogram_buckets = np.zeros((bucket_count, 3))
    else:
        min_ = np.min(data)
        max_ = np.max(data)
        range_ = max_ - min_
        if range_ == 0:
            left_edges = right_edges = np.array([min_] * bucket_count)
            bucket_counts = np.array([0] * (bucket_count - 1) + [data.size])
            histogram_buckets = np.array(
                [left_edges, right_edges, bucket_counts]).transpose()
        else:
            bucket_width = range_ / bucket_count
            offsets = data - min_
            bucket_indices = np.floor(offsets / bucket_width).astype(int)
            clamped_indices = np.minimum(bucket_indices, bucket_count - 1)
            one_hots = np.array([clamped_indices]).transpose() == np.arange(
                0, bucket_count)  # broadcast
            assert one_hots.shape == (data.size, bucket_count), (
                one_hots.shape,
                (data.size, bucket_count),
            )
            bucket_counts = np.sum(one_hots, axis=0)
            edges = np.linspace(min_, max_, bucket_count + 1)
            left_edges = edges[:-1]
            right_edges = edges[1:]
            histogram_buckets = np.array(
                [left_edges, right_edges, bucket_counts]).transpose()
    tensor = tensor_util.make_tensor_proto(histogram_buckets, dtype=np.float64)

    summary_metadata = metadata.create_summary_metadata(
        display_name=None, description=description)
    summary = summary_pb2.Summary()
    summary.value.add(tag=tag, metadata=summary_metadata, tensor=tensor)
    return summary
Esempio n. 15
0
def read_tensor_summary(path):
    with tf.gfile.Open(path, 'rb') as summary_file:
        summary_string = summary_file.read()

    if not summary_string:
        raise message.DecodeError('Empty summary.')

    summary_proto = summary_pb2.Summary()
    summary_proto.ParseFromString(summary_string)
    tensor_proto = summary_proto.value[0].tensor
    array = tensor_util.make_ndarray(tensor_proto)

    return array
Esempio n. 16
0
def _summary_pb(tag, hparams_plugin_data):
    """Create a summary holding the given `HParamsPluginData` message.

    Args:
      tag: The `str` tag to use.
      hparams_plugin_data: The `HParamsPluginData` message to use.

    Returns:
      A TensorBoard `summary_pb2.Summary` message.
    """
    summary = summary_pb2.Summary()
    summary_metadata = metadata.create_summary_metadata(hparams_plugin_data)
    summary.value.add(tag=tag, metadata=summary_metadata)
    return summary
Esempio n. 17
0
  def AddScalarTensor(self, tag, wall_time=0, step=0, value=0):
    """Add a rank-0 tensor event.

    Note: This is not related to the scalar plugin; it's just a
    convenience function to add an event whose contents aren't
    important.
    """
    tensor = tensor_util.make_tensor_proto(float(value))
    event = event_pb2.Event(
        wall_time=wall_time,
        step=step,
        summary=summary_pb2.Summary(
            value=[summary_pb2.Summary.Value(tag=tag, tensor=tensor)]))
    self.AddEvent(event)
Esempio n. 18
0
def test_hook(mocked_run):
    history = wandb_sdk.History(mocked_run)
    summaries_logged = []

    def spy_cb(row, step=None):
        summaries_logged.append(row)

    history._set_callback(spy_cb)

    g1 = tf.Graph()
    with g1.as_default():
        get_or_create_global_step()
        c1 = tf.constant(42)
        tf_summary.scalar("c1", c1)
        summary_op = tf_summary.merge_all()

        hook = wandb.tensorflow.WandbHook(summary_op, history=history, steps_per_log=1)
        with MonitoredTrainingSession(hooks=[hook]) as sess:
            summary, acc = sess.run([summary_op, c1])
        history.add({})  # Flush the previous row.

    # test digesting encoded summary
    assert wandb.tensorboard.tf_summary_to_dict(summary) == {"c1": 42.0}
    assert summaries_logged[0]["c1"] == 42.0

    # test digesting Summary object
    summary_pb = summary_pb2.Summary()
    summary_pb.ParseFromString(summary)
    assert wandb.tensorboard.tf_summary_to_dict(summary_pb) == {"c1": 42.0}

    # test digesting a list of encoded summaries
    g2 = tf.Graph()
    with g2.as_default():
        get_or_create_global_step()
        c2 = tf.constant(23)
        tf_summary.scalar("c2", c2)
        summary_op = tf_summary.merge_all()

        hook = wandb.tensorflow.WandbHook(summary_op, history=history, steps_per_log=1)
        with MonitoredTrainingSession(hooks=[hook]) as sess:
            summary2, acc2 = sess.run([summary_op, c2])
        history.add({})
    assert wandb.tensorboard.tf_summary_to_dict([summary, summary2]) == {
        "c1": 42.0,
        "c2": 23.0,
    }
    assert summaries_logged[1]["c2"] == 23.0
Esempio n. 19
0
 def AddImage(self,
              tag,
              wall_time=0,
              step=0,
              encoded_image_string=b'imgstr',
              width=150,
              height=100):
     image = summary_pb2.Summary.Image(
         encoded_image_string=encoded_image_string,
         width=width,
         height=height)
     event = event_pb2.Event(
         wall_time=wall_time,
         step=step,
         summary=summary_pb2.Summary(
             value=[summary_pb2.Summary.Value(tag=tag, image=image)]))
     self.AddEvent(event)
Esempio n. 20
0
        def canonical(summary):
            """Return a canonical form for `summary`.

            The result is such that `canonical(a) == canonical(b)` if and only
            if `a` and `b` are logically equivalent.

            Args:
              summary: A `summary_pb2.Summary` containing hparams plugin data.
            """
            new_summary = summary_pb2.Summary()
            new_summary.MergeFrom(summary)
            values = new_summary.value
            self.assertEqual(len(values), 1, values)
            value = values[0]
            raw_content = value.metadata.plugin_data.content
            value.metadata.plugin_data.content = b"<snipped>"
            content = plugin_data_pb2.HParamsPluginData.FromString(raw_content)
            return (new_summary, content)
Esempio n. 21
0
  def _writeMetadata(self, logdir, summary_metadata, nonce=''):
    """Write to disk a summary with the given metadata.

    Arguments:
      logdir: a string
      summary_metadata: a `SummaryMetadata` protobuf object
      nonce: optional; will be added to the end of the event file name
        to guarantee that multiple calls to this function do not stomp the
        same file
    """

    summary = summary_pb2.Summary()
    summary.value.add(
        tensor=tensor_util.make_tensor_proto(['po', 'ta', 'to'], dtype=tf.string),
        tag='you_are_it',
        metadata=summary_metadata)
    writer = test_util.FileWriter(logdir, filename_suffix=nonce)
    writer.add_summary(summary.SerializeToString())
    writer.close()
Esempio n. 22
0
 def AddAudio(self,
              tag,
              wall_time=0,
              step=0,
              encoded_audio_string=b'sndstr',
              content_type='audio/wav',
              sample_rate=44100,
              length_frames=22050):
     audio = summary_pb2.Summary.Audio(
         encoded_audio_string=encoded_audio_string,
         content_type=content_type,
         sample_rate=sample_rate,
         length_frames=length_frames)
     event = event_pb2.Event(
         wall_time=wall_time,
         step=step,
         summary=summary_pb2.Summary(
             value=[summary_pb2.Summary.Value(tag=tag, audio=audio)]))
     self.AddEvent(event)
Esempio n. 23
0
  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)

      with test_util.FileWriterCache.get(subdir) as sw:
        for datum in data:
          summary = summary_pb2.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=summary_pb2.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'])
Esempio n. 24
0
 def normalize_summary_pb(self, pb):
     """Pass `pb`'s `TensorProto` through a marshalling roundtrip.
 `TensorProto`s can be equal in value even if they are not identical
 in representation, because data can be stored in either the
 `tensor_content` field or the `${dtype}_value` field. This
 normalization ensures a canonical form, and should be used before
 comparing two `Summary`s for equality.
 """
     result = summary_pb2.Summary()
     if not isinstance(pb, summary_pb2.Summary):
         # pb can come from `pb_via_op` which creates a TB Summary.
         pb = test_util.ensure_tb_summary_proto(pb)
     result.MergeFrom(pb)
     for value in result.value:
         if value.HasField('tensor'):
             new_tensor = tensor_util.make_tensor_proto(
                 tensor_util.make_ndarray(value.tensor))
             value.ClearField('tensor')
             value.tensor.MergeFrom(new_tensor)
     return result
Esempio n. 25
0
    def test_only_1_summary_generated(self):
        """Tests that the streaming op only generates 1 summary for PR curves.

    This test was made in response to a bug in which calling the streaming op
    actually introduced 2 tags.
    """
        predictions = tf.constant([0.2, 0.4, 0.5, 0.6, 0.8], dtype=tf.float32)
        labels = tf.constant([False, True, True, False, True], dtype=tf.bool)
        _, update_op = summary.streaming_op(name='pr_curve',
                                            predictions=predictions,
                                            labels=labels,
                                            num_thresholds=10)
        with self.test_session() as sess:
            sess.run(tf.local_variables_initializer())
            sess.run(update_op)
            summary_proto = summary_pb2.Summary()
            summary_proto.ParseFromString(sess.run(tf.summary.merge_all()))

        tags = [v.tag for v in summary_proto.value]
        # Only 1 tag should have been introduced.
        self.assertEqual(['pr_curve/pr_curves'], tags)
Esempio n. 26
0
def Scalar(tag, val):
    return summary_pb2.Summary(
        value=[summary_pb2.Summary.Value(tag=tag, simple_value=val)])
 def FakeScalarSummary(tag, value):
     value = summary_pb2.Summary.Value(tag=tag, simple_value=value)
     summary = summary_pb2.Summary(value=[value])
     return summary
Esempio n. 28
0
 def tensor_via_op(self, summary_op):
     actual_pbtxt = summary_op.eval()
     actual_proto = summary_pb2.Summary()
     actual_proto.ParseFromString(actual_pbtxt)
     return actual_proto
Esempio n. 29
0
 def pb_via_op(self, summary_op, feed_dict=None):
     with tf.compat.v1.Session() as sess:
         actual_pbtxt = sess.run(summary_op, feed_dict=feed_dict or {})
     actual_proto = summary_pb2.Summary()
     actual_proto.ParseFromString(actual_pbtxt)
     return actual_proto
Esempio n. 30
0
 def pb_via_op(self, summary_op):
     """Parses pb proto."""
     actual_pbtxt = summary_op.eval()
     actual_proto = summary_pb2.Summary()
     actual_proto.ParseFromString(actual_pbtxt)
     return actual_proto