File tree 1 file changed +9
-5
lines changed
1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -154,11 +154,13 @@ def tf2_compat_logger(config, logdir):
154
154
155
155
class TF2Logger (Logger ):
156
156
def _init (self ):
157
- from tensorflow .python .eager import context
158
- self ._context = context
159
- self ._file_writer = tf .summary .create_file_writer (self .logdir )
157
+ self ._file_writer = None
160
158
161
159
def on_result (self , result ):
160
+ if self ._file_writer is None :
161
+ from tensorflow .python .eager import context
162
+ self ._context = context
163
+ self ._file_writer = tf .summary .create_file_writer (self .logdir )
162
164
with tf .device ("/CPU:0" ), self ._context .eager_mode ():
163
165
with tf .summary .record_if (True ), self ._file_writer .as_default ():
164
166
step = result .get (
@@ -181,10 +183,12 @@ def on_result(self, result):
181
183
self ._file_writer .flush ()
182
184
183
185
def flush (self ):
184
- self ._file_writer .flush ()
186
+ if self ._file_writer is not None :
187
+ self ._file_writer .flush ()
185
188
186
189
def close (self ):
187
- self ._file_writer .close ()
190
+ if self ._file_writer is not None :
191
+ self ._file_writer .close ()
188
192
189
193
190
194
def to_tf_values (result , path ):
You can’t perform that action at this time.
0 commit comments