xref: /aosp_15_r20/external/tensorflow/tensorflow/python/training/summary_io.py (revision b6fb3261f9314811a0f4371741dbb8839866f948)
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"""Reads Summaries from and writes Summaries to event files."""
16
17# pylint: disable=unused-import
18from tensorflow.python.summary.summary_iterator import summary_iterator
19from tensorflow.python.summary.writer.writer import FileWriter as _FileWriter
20from tensorflow.python.summary.writer.writer_cache import FileWriterCache as SummaryWriterCache
21# pylint: enable=unused-import
22from tensorflow.python.util.deprecation import deprecated
23
24
25class SummaryWriter(_FileWriter):
26
27  @deprecated("2016-11-30",
28              "Please switch to tf.summary.FileWriter. The interface and "
29              "behavior is the same; this is just a rename.")
30  def __init__(self,
31               logdir,
32               graph=None,
33               max_queue=10,
34               flush_secs=120,
35               graph_def=None):
36    """Creates a `SummaryWriter` and an event file.
37
38    This class is deprecated, and should be replaced with tf.summary.FileWriter.
39
40    On construction the summary writer creates a new event file in `logdir`.
41    This event file will contain `Event` protocol buffers constructed when you
42    call one of the following functions: `add_summary()`, `add_session_log()`,
43    `add_event()`, or `add_graph()`.
44
45    If you pass a `Graph` to the constructor it is added to
46    the event file. (This is equivalent to calling `add_graph()` later).
47
48    TensorBoard will pick the graph from the file and display it graphically so
49    you can interactively explore the graph you built. You will usually pass
50    the graph from the session in which you launched it:
51
52    ```python
53    ...create a graph...
54    # Launch the graph in a session.
55    sess = tf.compat.v1.Session()
56    # Create a summary writer, add the 'graph' to the event file.
57    writer = tf.compat.v1.summary.FileWriter(<some-directory>, sess.graph)
58    ```
59
60    The other arguments to the constructor control the asynchronous writes to
61    the event file:
62
63    *  `flush_secs`: How often, in seconds, to flush the added summaries
64       and events to disk.
65    *  `max_queue`: Maximum number of summaries or events pending to be
66       written to disk before one of the 'add' calls block.
67
68    Args:
69      logdir: A string. Directory where event file will be written.
70      graph: A `Graph` object, such as `sess.graph`.
71      max_queue: Integer. Size of the queue for pending events and summaries.
72      flush_secs: Number. How often, in seconds, to flush the
73        pending events and summaries to disk.
74      graph_def: DEPRECATED: Use the `graph` argument instead.
75    """
76    super(SummaryWriter, self).__init__(logdir, graph, max_queue, flush_secs,
77                                        graph_def)
78