1# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ==============================================================================
15"""Summary Operations."""
16# pylint: disable=protected-access
17from __future__ import absolute_import
18from __future__ import division
19from __future__ import print_function
20
21from tensorflow.core.framework import summary_pb2
22from tensorflow.python.framework import ops
23from tensorflow.python.ops import gen_logging_ops
24from tensorflow.python.ops import summary_op_util
25# go/tf-wildcard-import
26# pylint: disable=wildcard-import
27from tensorflow.python.ops.gen_logging_ops import *
28from tensorflow.python.util.tf_export import tf_export
29# pylint: enable=wildcard-import
30
31
32@tf_export("summary.tensor_summary")
33def tensor_summary(name,
34                   tensor,
35                   summary_description=None,
36                   collections=None,
37                   summary_metadata=None,
38                   family=None,
39                   display_name=None):
40  """Outputs a `Summary` protocol buffer with a serialized tensor.proto.
41
42  Args:
43    name: A name for the generated node. If display_name is not set, it will
44      also serve as the tag name in TensorBoard. (In that case, the tag
45      name will inherit tf name scopes.)
46    tensor: A tensor of any type and shape to serialize.
47    summary_description: A long description of the summary sequence. Markdown
48      is supported.
49    collections: Optional list of graph collections keys. The new summary op is
50      added to these collections. Defaults to `[GraphKeys.SUMMARIES]`.
51    summary_metadata: Optional SummaryMetadata proto (which describes which
52      plugins may use the summary value).
53    family: Optional; if provided, used as the prefix of the summary tag,
54      which controls the name used for display on TensorBoard when
55      display_name is not set.
56    display_name: A string used to name this data in TensorBoard. If this is
57      not set, then the node name will be used instead.
58
59  Returns:
60    A scalar `Tensor` of type `string`. The serialized `Summary` protocol
61    buffer.
62  """
63
64  if summary_metadata is None:
65    summary_metadata = summary_pb2.SummaryMetadata()
66
67  if summary_description is not None:
68    summary_metadata.summary_description = summary_description
69
70  if display_name is not None:
71    summary_metadata.display_name = display_name
72
73  serialized_summary_metadata = summary_metadata.SerializeToString()
74
75  with summary_op_util.summary_scope(
76      name, family, values=[tensor]) as (tag, scope):
77    val = gen_logging_ops._tensor_summary_v2(
78        tensor=tensor,
79        tag=tag,
80        name=scope,
81        serialized_summary_metadata=serialized_summary_metadata)
82    summary_op_util.collect(val, collections, [ops.GraphKeys.SUMMARIES])
83  return val
84
85ops.NotDifferentiable("TensorSummary")
86