Skip to content

Commit 003e7d0

Browse files
Dan Manétensorflower-gardener
authored andcommitted
Add an explanation of the summary migration to the tf.contrib.deprecated module
Also update docstrings on the old implementations to point to the explanation. Change: 140903864
1 parent 4bdf451 commit 003e7d0

4 files changed

Lines changed: 102 additions & 39 deletions

File tree

tensorflow/contrib/deprecated/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ py_library(
1111
name = "deprecated_py",
1212
srcs = [
1313
"__init__.py",
14-
"summaries.py",
1514
],
1615
srcs_version = "PY2AND3",
1716
deps = ["//tensorflow/python:logging_ops"],

tensorflow/contrib/deprecated/__init__.py

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,86 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
# ==============================================================================
15-
"""Deprecated endpoints that we aren't yet ready to remove entirely.
15+
"""Non-core alias for the deprecated tf.X_summary ops.
16+
17+
For TensorFlow 1.0, we have re-organized the TensorFlow summary ops into a
18+
submodule, and made some semantic tweaks. The first thing to note is that we
19+
moved the APIs around as follows:
20+
21+
tf.scalar_summary -> tf.summary.scalar
22+
tf.histogram_summary -> tf.summary.histogram
23+
tf.audio_summary -> tf.summary.audio
24+
tf.image_summary -> tf.summary.image
25+
tf.merge_summary -> tf.summary.merge
26+
tf.merge_all_summaries -> tf.summary.merge_all
27+
28+
We think this is a cleaner API and will improve long-term discoverability and
29+
clarity of the TensorFlow API. However, we also took the opportunity to make an
30+
important change to how summary "tags" work. The "tag" of a summary is the
31+
string that is associated with the output data, i.e. the key for organizing the
32+
generated protobufs.
33+
34+
Previously, the tag was allowed to be any unique string, and had no relation
35+
to the summary op generating it, and no relation to the TensorFlow name system.
36+
This made it very difficult to write re-usable code that would add summary
37+
ops to the graph. If you had a function that would add summary ops, you would
38+
need to manually pass in a name scope to that function to create de-duplicated
39+
tags, otherwise your program would fail with a runtime error due to tag
40+
collision.
41+
42+
The new summary APIs under tf.summary throw away the "tag" as an independent
43+
concept; instead, the first argument is the node name. This means that summary
44+
tags now automatically inherit the surrounding TF name scope, and automatically
45+
are deduplicated if there is a conflict. However, now the only allowed
46+
characters are alphanumerics, underscores, and forward slashes. To make
47+
migration easier, the new APIs automatically convert illegal characters to
48+
underscores.
49+
50+
Just as an example, consider the following "before" and "after" code snippets:
51+
52+
# Before
53+
def add_activation_summaries(v, scope):
54+
tf.scalar_summary("%s/fraction_of_zero" % scope, tf.nn.fraction_of_zero(v))
55+
tf.histogram_summary("%s/activations" % scope, v)
56+
57+
# After
58+
def add_activation_summaries(v):
59+
tf.summary.scalar("fraction_of_zero", tf.nn.fraction_of_zero(v))
60+
tf.summary.histogram("activations", v)
61+
62+
Now, so long as the add_activation_summaries function is called from within the
63+
right name scope, the behavior is the same.
64+
65+
Because this change does modify the behavior and could break tests, we can't
66+
automatically migrate usage to the new APIs. That is why we are making the old
67+
APIs temporarily available here at tf.contrib.deprecated.
68+
69+
In addition to the name change described above, there are two further changes
70+
to the new summary ops:
71+
72+
- the "max_images" argument for tf.image_summary was renamed to "max_outputs
73+
for tf.summary.image
74+
- tf.scalar_summary accepted arbitrary tensors of tags and values. However,
75+
tf.summary.scalar requires a single scalar name and scalar value. In most
76+
cases, you can create tf.summary.scalars in a loop to get the same behavior
77+
78+
As before, TensorBoard will group charts by the top-level name scope. This may
79+
be inconvenient, since in the new summary ops the summary will inherit that
80+
name scope without user control. We plan to add more grouping mechanisms to
81+
TensorBoard, so it will be possible to specify the TensorBoard group for
82+
each summary via the summary API.
83+
1684
"""
1785
from __future__ import absolute_import
1886
from __future__ import division
1987
from __future__ import print_function
2088

89+
2190
# pylint: disable=unused-import,line-too-long
22-
from tensorflow.contrib.deprecated.summaries import audio_summary
23-
from tensorflow.contrib.deprecated.summaries import histogram_summary
24-
from tensorflow.contrib.deprecated.summaries import image_summary
25-
from tensorflow.contrib.deprecated.summaries import merge_all_summaries
26-
from tensorflow.contrib.deprecated.summaries import merge_summary
27-
from tensorflow.contrib.deprecated.summaries import scalar_summary
91+
from tensorflow.python.ops.logging_ops import audio_summary
92+
from tensorflow.python.ops.logging_ops import histogram_summary
93+
from tensorflow.python.ops.logging_ops import image_summary
94+
from tensorflow.python.ops.logging_ops import merge_all_summaries
95+
from tensorflow.python.ops.logging_ops import merge_summary
96+
from tensorflow.python.ops.logging_ops import scalar_summary
2897
# pylint: enable=unused-import,line-too-long

tensorflow/contrib/deprecated/summaries.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

tensorflow/python/ops/logging_ops.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,14 @@ def _Collect(val, collections, default_collections):
7171

7272

7373
def histogram_summary(tag, values, collections=None, name=None):
74+
# pylint: disable=line-too-long
7475
"""Outputs a `Summary` protocol buffer with a histogram.
7576
77+
This ops is deprecated. Please switch to tf.summary.histogram.
78+
79+
For an explanation of why this op was deprecated, and information on how to
80+
migrate, look ['here'](https://www.tensorflow.org/code/tensorflow/contrib/deprecated/__init__.py)
81+
7682
The generated
7783
[`Summary`](https://www.tensorflow.org/code/tensorflow/core/framework/summary.proto)
7884
has one summary value containing a histogram for `values`.
@@ -99,8 +105,12 @@ def histogram_summary(tag, values, collections=None, name=None):
99105

100106

101107
def image_summary(tag, tensor, max_images=3, collections=None, name=None):
108+
# pylint: disable=line-too-long
102109
"""Outputs a `Summary` protocol buffer with images.
103110
111+
For an explanation of why this op was deprecated, and information on how to
112+
migrate, look ['here'](https://www.tensorflow.org/code/tensorflow/contrib/deprecated/__init__.py)
113+
104114
The summary has up to `max_images` summary values containing images. The
105115
images are built from `tensor` which must be 4-D with shape `[batch_size,
106116
height, width, channels]` and where `channels` can be:
@@ -155,8 +165,13 @@ def audio_summary(tag,
155165
max_outputs=3,
156166
collections=None,
157167
name=None):
168+
# pylint: disable=line-too-long
158169
"""Outputs a `Summary` protocol buffer with audio.
159170
171+
This op is deprecated. Please switch to tf.summary.audio.
172+
For an explanation of why this op was deprecated, and information on how to
173+
migrate, look ['here'](https://www.tensorflow.org/code/tensorflow/contrib/deprecated/__init__.py)
174+
160175
The summary has up to `max_outputs` summary values containing audio. The
161176
audio is built from `tensor` which must be 3-D with shape `[batch_size,
162177
frames, channels]` or 2-D with shape `[batch_size, frames]`. The values are
@@ -202,6 +217,9 @@ def merge_summary(inputs, collections=None, name=None):
202217
# pylint: disable=line-too-long
203218
"""Merges summaries.
204219
220+
This op is deprecated. Please switch to tf.summary.merge, which has identical
221+
behavior.
222+
205223
This op creates a
206224
[`Summary`](https://www.tensorflow.org/code/tensorflow/core/framework/summary.proto)
207225
protocol buffer that contains the union of all the values in the input
@@ -230,6 +248,9 @@ def merge_summary(inputs, collections=None, name=None):
230248
def merge_all_summaries(key=ops.GraphKeys.SUMMARIES):
231249
"""Merges all summaries collected in the default graph.
232250
251+
This op is deprecated. Please switch to tf.summary.merge_all, which has
252+
identical behavior.
253+
233254
Args:
234255
key: `GraphKey` used to collect the summaries. Defaults to
235256
`GraphKeys.SUMMARIES`.
@@ -271,8 +292,13 @@ def get_summary_op():
271292

272293

273294
def scalar_summary(tags, values, collections=None, name=None):
295+
# pylint: disable=line-too-long
274296
"""Outputs a `Summary` protocol buffer with scalar values.
275297
298+
This ops is deprecated. Please switch to tf.summary.scalar.
299+
For an explanation of why this op was deprecated, and information on how to
300+
migrate, look ['here'](https://www.tensorflow.org/code/tensorflow/contrib/deprecated/__init__.py)
301+
276302
The input `tags` and `values` must have the same shape. The generated
277303
summary has a summary value for each tag-value pair in `tags` and `values`.
278304

0 commit comments

Comments
 (0)