Пример #1
0
def text(name, data, step, description=None):
    """Write a text summary.

  Arguments:
    name: A name for this summary. The summary tag used for TensorBoard will
      be this name prefixed by any active name scopes.
    data: A UTF-8 string tensor value.
    step: Required `int64`-castable monotonic step value.
    description: Optional long-form description for this summary, as a
      constant `str`. Markdown is supported. Defaults to empty.

  Returns:
    True on success, or false if no summary was emitted because no default
    summary writer was available.
  """
    # TODO(nickfelt): remove on-demand imports once dep situation is fixed.
    from tensorboard import compat
    tf = compat.import_tf_v2()
    summary_metadata = metadata.create_summary_metadata(
        display_name=None, description=description)
    with tf.summary.summary_scope(name, 'text_summary',
                                  values=[data, step]) as (tag, _):
        tf.debugging.assert_type(data, tf.string)
        return tf.summary.write(tag=tag,
                                tensor=data,
                                step=step,
                                metadata=summary_metadata)
Пример #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.
  """
    # 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
Пример #3
0
def text(name, data, step=None, description=None):
    """Write a text summary.

  Arguments:
    name: A name for this summary. The summary tag used for TensorBoard will
      be this name prefixed by any active name scopes.
    data: A UTF-8 string tensor value.
    step: Explicit `int64`-castable monotonic step value for this summary. If
      omitted, this defaults to `tf.summary.experimental.get_step()`, which must
      not be None.
    description: Optional long-form description for this summary, as a
      constant `str`. Markdown is supported. Defaults to empty.

  Returns:
    True on success, or false if no summary was emitted because no default
    summary writer was available.

  Raises:
    ValueError: if a default writer exists, but no step was provided and
      `tf.summary.experimental.get_step()` is None.
  """
    summary_metadata = metadata.create_summary_metadata(
        display_name=None, description=description)
    with tf.summary.summary_scope(name, 'text_summary',
                                  values=[data, step]) as (tag, _):
        tf.debugging.assert_type(data, tf.string)
        return tf.summary.write(tag=tag,
                                tensor=data,
                                step=step,
                                metadata=summary_metadata)
Пример #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.
  """
    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
Пример #5
0
def pb(name, data, display_name=None, description=None):
  """Create a text summary protobuf.

  Arguments:
    name: A name for the generated node. Will also serve as a series name in
      TensorBoard.
    data: A Python bytestring (of type bytes), or Unicode string. Or a numpy
      data array of those types.
    display_name: Optional name for this summary in TensorBoard, as a
      `str`. Defaults to `name`.
    description: Optional long-form description for this summary, as a
      `str`. Markdown is supported. Defaults to empty.

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

  Returns:
    A `tf.Summary` protobuf object.
  """
  try:
    tensor = tf.make_tensor_proto(data, dtype=tf.string)
  except TypeError as e:
    raise ValueError(e)

  if display_name is None:
    display_name = name
  summary_metadata = metadata.create_summary_metadata(
      display_name=display_name, description=description)
  summary = tf.Summary()
  summary.value.add(tag='%s/text_summary' % name,
                    metadata=summary_metadata,
                    tensor=tensor)
  return summary
Пример #6
0
def pb(name, data, display_name=None, description=None):
    """Create a text summary protobuf.

  Arguments:
    name: A name for the generated node. Will also serve as a series name in
      TensorBoard.
    data: A Python bytestring (of type bytes), or Unicode string. Or a numpy
      data array of those types.
    display_name: Optional name for this summary in TensorBoard, as a
      `str`. Defaults to `name`.
    description: Optional long-form description for this summary, as a
      `str`. Markdown is supported. Defaults to empty.

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

  Returns:
    A `tf.Summary` protobuf object.
  """
    try:
        tensor = tensor_util.make_tensor_proto(data, dtype=tf.string)
    except TypeError as e:
        raise ValueError(e)

    if display_name is None:
        display_name = name
    summary_metadata = metadata.create_summary_metadata(
        display_name=display_name, description=description)
    summary = tf.Summary()
    summary.value.add(tag='%s/text_summary' % name,
                      metadata=summary_metadata,
                      tensor=tensor)
    return summary
Пример #7
0
 def log_text(self, tag, value, step):
     """Log string or 2D string tables. """
     summary_metadata = metadata.create_summary_metadata(
         display_name="text", description="Text Summary")
     summary_metadata = tf.SummaryMetadata.FromString(
         summary_metadata.SerializeToString())
     tensor = tf.make_tensor_proto(value, dtype=tf.string)
     summary = tf.Summary(value=[
         tf.Summary.Value(tag=tag, metadata=summary_metadata, tensor=tensor)
     ])
     self.writer.add_summary(summary, step)
     self.writer.flush()
Пример #8
0
def op(name, data, display_name=None, description=None, collections=None):
    """Create a legacy text summary op.

    Text data summarized via this plugin will be visible in the Text Dashboard
    in TensorBoard. The standard TensorBoard Text Dashboard will render markdown
    in the strings, and will automatically organize 1D and 2D tensors into tables.
    If a tensor with more than 2 dimensions is provided, a 2D subarray will be
    displayed along with a warning message. (Note that this behavior is not
    intrinsic to the text summary API, but rather to the default TensorBoard text
    plugin.)

    Args:
      name: A name for the generated node. Will also serve as a series name in
        TensorBoard.
      data: A string-type Tensor to summarize. The text must be encoded in UTF-8.
      display_name: Optional name for this summary in TensorBoard, as a
        constant `str`. Defaults to `name`.
      description: Optional long-form description for this summary, as a
        constant `str`. Markdown is supported. Defaults to empty.
      collections: Optional list of ops.GraphKeys. The collections to which to add
        the summary. Defaults to [Graph Keys.SUMMARIES].

    Returns:
      A TensorSummary op that is configured so that TensorBoard will recognize
      that it contains textual data. The TensorSummary is a scalar `Tensor` of
      type `string` which contains `Summary` protobufs.

    Raises:
      ValueError: If tensor has the wrong type.
    """
    # TODO(nickfelt): remove on-demand imports once dep situation is fixed.
    import tensorflow.compat.v1 as tf

    if display_name is None:
        display_name = name
    summary_metadata = metadata.create_summary_metadata(
        display_name=display_name, description=description
    )
    with tf.name_scope(name):
        with tf.control_dependencies([tf.assert_type(data, tf.string)]):
            return tf.summary.tensor_summary(
                name="text_summary",
                tensor=data,
                collections=collections,
                summary_metadata=summary_metadata,
            )
Пример #9
0
def op(name,
       data,
       display_name=None,
       description=None,
       collections=None):
  """Create a text summary op.

  Text data summarized via this plugin will be visible in the Text Dashboard
  in TensorBoard. The standard TensorBoard Text Dashboard will render markdown
  in the strings, and will automatically organize 1D and 2D tensors into tables.
  If a tensor with more than 2 dimensions is provided, a 2D subarray will be
  displayed along with a warning message. (Note that this behavior is not
  intrinsic to the text summary API, but rather to the default TensorBoard text
  plugin.)

  Args:
    name: A name for the generated node. Will also serve as a series name in
      TensorBoard.
    data: A string-type Tensor to summarize. The text must be encoded in UTF-8.
    display_name: Optional name for this summary in TensorBoard, as a
      constant `str`. Defaults to `name`.
    description: Optional long-form description for this summary, as a
      constant `str`. Markdown is supported. Defaults to empty.
    collections: Optional list of ops.GraphKeys. The collections to which to add
      the summary. Defaults to [Graph Keys.SUMMARIES].

  Returns:
    A TensorSummary op that is configured so that TensorBoard will recognize
    that it contains textual data. The TensorSummary is a scalar `Tensor` of
    type `string` which contains `Summary` protobufs.

  Raises:
    ValueError: If tensor has the wrong type.
  """
  if display_name is None:
    display_name = name
  summary_metadata = metadata.create_summary_metadata(
      display_name=display_name, description=description)
  with tf.name_scope(name):
    with tf.control_dependencies([tf.assert_type(data, tf.string)]):
      return tf.summary.tensor_summary(name='text_summary',
                                       tensor=data,
                                       collections=collections,
                                       summary_metadata=summary_metadata)
Пример #10
0
def pb(name, data, display_name=None, description=None):
    """Create a legacy text summary protobuf.

    Arguments:
      name: A name for the generated node. Will also serve as a series name in
        TensorBoard.
      data: A Python bytestring (of type bytes), or Unicode string. Or a numpy
        data array of those types.
      display_name: Optional name for this summary in TensorBoard, as a
        `str`. Defaults to `name`.
      description: Optional long-form description for this summary, as a
        `str`. Markdown is supported. Defaults to empty.

    Raises:
      ValueError: 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.
    import tensorflow.compat.v1 as tf

    try:
        tensor = tf.make_tensor_proto(data, dtype=tf.string)
    except TypeError as e:
        raise ValueError(e)

    if display_name is None:
        display_name = name
    summary_metadata = metadata.create_summary_metadata(
        display_name=display_name, description=description
    )
    tf_summary_metadata = tf.SummaryMetadata.FromString(
        summary_metadata.SerializeToString()
    )
    summary = tf.Summary()
    summary.value.add(
        tag="%s/text_summary" % name,
        metadata=tf_summary_metadata,
        tensor=tensor,
    )
    return summary
Пример #11
0
def text(name, data, step=None, description=None):
    r"""Write a text summary.

    See also `tf.summary.scalar`, `tf.summary.SummaryWriter`, `tf.summary.image`.

    Writes text Tensor values for later visualization and analysis in TensorBoard.
    Writes go to the current default summary writer.  Like `tf.summary.scalar`
    points, text points are each associated with a `step` and a `name`.
    All the points with the same `name` constitute a time series of text values.

    For Example:
    ```python
    test_summary_writer = tf.summary.create_file_writer('test/logdir')
    with test_summary_writer.as_default():
        tf.summary.text('first_text', 'hello world!', step=0)
        tf.summary.text('first_text', 'nice to meet you!', step=1)
    ```

    The text summary can also contain Markdown, and TensorBoard will render the text
    as such.

    ```python
    with test_summary_writer.as_default():
        text_data = '''
              | *hello* | *there* |
              |---------|---------|
              | this    | is      |
              | a       | table   |
        '''
        text_data = '\n'.join(l.strip() for l in text_data.splitlines())
        tf.summary.text('markdown_text', text_data, step=0)
    ```

    Since text is Tensor valued, each text point may be a Tensor of string values.
    rank-1 and rank-2 Tensors are rendered as tables in TensorBoard.  For higher ranked
    Tensors, you'll see just a 2D slice of the data.  To avoid this, reshape the Tensor
    to at most rank-2 prior to passing it to this function.

    Demo notebook at
    ["Displaying text data in TensorBoard"](https://www.tensorflow.org/tensorboard/text_summaries).

    Arguments:
      name: A name for this summary. The summary tag used for TensorBoard will
        be this name prefixed by any active name scopes.
      data: A UTF-8 string Tensor value.
      step: Explicit `int64`-castable monotonic step value for this summary. If
        omitted, this defaults to `tf.summary.experimental.get_step()`, which must
        not be None.
      description: Optional long-form description for this summary, as a
        constant `str`. Markdown is supported. Defaults to empty.

    Returns:
      True on success, or false if no summary was emitted because no default
      summary writer was available.

    Raises:
      ValueError: if a default writer exists, but no step was provided and
        `tf.summary.experimental.get_step()` is None.
    """
    summary_metadata = metadata.create_summary_metadata(
        display_name=None, description=description
    )
    # TODO(https://github.com/tensorflow/tensorboard/issues/2109): remove fallback
    summary_scope = (
        getattr(tf.summary.experimental, "summary_scope", None)
        or tf.summary.summary_scope
    )
    with summary_scope(name, "text_summary", values=[data, step]) as (tag, _):
        tf.debugging.assert_type(data, tf.string)
        return tf.summary.write(
            tag=tag, tensor=data, step=step, metadata=summary_metadata
        )