1 # Copyright 2017 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 """TensorFlow Summary API v2. 16 17 The operations in this package are safe to use with eager execution turned on or 18 off. It has a more flexible API that allows summaries to be written directly 19 from ops to places other than event log files, rather than propagating protos 20 from @{tf.summary.merge_all} to @{tf.summary.FileWriter}. 21 22 To use with eager execution enabled, write your code as follows: 23 24 global_step = tf.train.get_or_create_global_step() 25 summary_writer = tf.contrib.summary.create_file_writer( 26 train_dir, flush_millis=10000) 27 with summary_writer.as_default(), tf.contrib.summary.always_record_summaries(): 28 # model code goes here 29 # and in it call 30 tf.contrib.summary.scalar("loss", my_loss) 31 # In this case every call to tf.contrib.summary.scalar will generate a record 32 # ... 33 34 To use it with graph execution, write your code as follows: 35 36 global_step = tf.train.get_or_create_global_step() 37 summary_writer = tf.contrib.summary.create_file_writer( 38 train_dir, flush_millis=10000) 39 with summary_writer.as_default(), tf.contrib.summary.always_record_summaries(): 40 # model definition code goes here 41 # and in it call 42 tf.contrib.summary.scalar("loss", my_loss) 43 # In this case every call to tf.contrib.summary.scalar will generate an op, 44 # note the need to run tf.contrib.summary.all_summary_ops() to make sure these 45 # ops get executed. 46 # ... 47 train_op = .... 48 49 with tf.Session(...) as sess: 50 tf.global_variables_initializer().run() 51 tf.contrib.summary.initialize(graph=tf.get_default_graph()) 52 # ... 53 while not_done_training: 54 sess.run([train_op, tf.contrib.summary.all_summary_ops()]) 55 # ... 56 57 """ 58 59 from __future__ import absolute_import 60 from __future__ import division 61 from __future__ import print_function 62 63 # pylint: disable=unused-import 64 from tensorflow.contrib.summary.summary_ops import all_summary_ops 65 from tensorflow.contrib.summary.summary_ops import always_record_summaries 66 from tensorflow.contrib.summary.summary_ops import audio 67 from tensorflow.contrib.summary.summary_ops import create_db_writer 68 from tensorflow.contrib.summary.summary_ops import create_file_writer 69 from tensorflow.contrib.summary.summary_ops import create_summary_file_writer 70 from tensorflow.contrib.summary.summary_ops import eval_dir 71 from tensorflow.contrib.summary.summary_ops import flush 72 from tensorflow.contrib.summary.summary_ops import generic 73 from tensorflow.contrib.summary.summary_ops import graph 74 from tensorflow.contrib.summary.summary_ops import histogram 75 from tensorflow.contrib.summary.summary_ops import image 76 from tensorflow.contrib.summary.summary_ops import import_event 77 from tensorflow.contrib.summary.summary_ops import initialize 78 from tensorflow.contrib.summary.summary_ops import never_record_summaries 79 from tensorflow.contrib.summary.summary_ops import record_summaries_every_n_global_steps 80 from tensorflow.contrib.summary.summary_ops import scalar 81 from tensorflow.contrib.summary.summary_ops import should_record_summaries 82 from tensorflow.contrib.summary.summary_ops import summary_writer_initializer_op 83 from tensorflow.contrib.summary.summary_ops import SummaryWriter 84