forked from tensorflow/tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsummary.py
More file actions
87 lines (68 loc) · 2.97 KB
/
Copy pathsummary.py
File metadata and controls
87 lines (68 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# pylint: disable=line-too-long
"""This module contains ops for generating summaries.
## Summary Ops
@@tensor_summary
@@scalar
"""
# pylint: enable=line-too-long
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from tensorflow.python.framework import ops
from tensorflow.python.framework import tensor_shape
from tensorflow.python.framework.dtypes import as_dtype
from tensorflow.python.ops.summary_ops import tensor_summary
from tensorflow.python.util.all_util import make_all
SCALAR_SUMMARY_LABEL = "tf_summary_type:scalar"
def scalar(display_name,
tensor,
description="",
labels=None,
collections=None,
name=None):
"""Outputs a `Summary` protocol buffer containing a single scalar value.
The generated Summary has a Tensor.proto containing the input Tensor.
Args:
display_name: A name to associate with the data series. Will be used to
organize output data and as a name in visualizers.
tensor: A tensor containing a single floating point or integer value.
description: An optional long description of the data being output.
labels: a list of strings used to attach metadata.
collections: Optional list of graph collections keys. The new summary op is
added to these collections. Defaults to `[GraphKeys.SUMMARIES]`.
name: An optional name for the generated node (optional).
Returns:
A scalar `Tensor` of type `string`. Which contains a `Summary` protobuf.
Raises:
ValueError: If tensor has the wrong shape or type.
"""
dtype = as_dtype(tensor.dtype)
if dtype.is_quantized or not (dtype.is_integer or dtype.is_floating):
raise ValueError("Can't create scalar summary for type %s." % dtype)
shape = tensor.get_shape()
if not shape.is_compatible_with(tensor_shape.scalar()):
raise ValueError("Can't create scalar summary for shape %s." % shape)
if labels is None:
labels = []
else:
labels = labels[:] # Otherwise we would mutate the input argument
labels.append(SCALAR_SUMMARY_LABEL)
with ops.name_scope(name, "ScalarSummary", [tensor]):
tensor = ops.convert_to_tensor(tensor)
return tensor_summary(display_name, tensor, description, labels,
collections, name)
__all__ = make_all(__name__)