Skip to content

Commit a2f2c7b

Browse files
rachellj218tensorflower-gardener
authored andcommitted
Replace tf.keras.callbacks.TensorBoard callback with a new callback TensorBoardWithValidation inherited from the former callback, which makes evaluation at the end of specified epochs and export the results to tensorboard.
PiperOrigin-RevId: 219749605
1 parent a61fff3 commit a2f2c7b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tensorflow/contrib/tpu/python/tpu/keras_support.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -1536,10 +1536,17 @@ def evaluate(self,
15361536
verbose=1,
15371537
sample_weight=None,
15381538
steps=None):
1539-
assert not self._numpy_to_infeed_manager_list # Ensure empty.
1539+
original_numpy_to_infeed_manager_list = []
1540+
if self._numpy_to_infeed_manager_list:
1541+
# evaluate call may be executed as callbacks during the training. In this
1542+
# case, _numpy_to_infeed_manager_list is not empty, so save it for
1543+
# recovery at the end of evaluate call.
1544+
original_numpy_to_infeed_manager_list = self._numpy_to_infeed_manager_list
1545+
self._numpy_to_infeed_manager_list = []
15401546

15411547
with _tpu_session_context():
1542-
infeed_managers = [] # Managers to clean up at the end of the fit call.
1548+
# Managers to clean up at the end of the evaluate call.
1549+
infeed_managers = []
15431550
if isinstance(x, dataset_ops.Dataset):
15441551
# TODO(b/111413240): Support taking a tf.data.Dataset directly.
15451552
raise ValueError(
@@ -1569,7 +1576,8 @@ def evaluate(self,
15691576
return super(KerasTPUModel, self).evaluate(x, y, batch_size, verbose,
15701577
sample_weight, steps)
15711578
finally:
1572-
self._numpy_to_infeed_manager_list = []
1579+
self._numpy_to_infeed_manager_list = (
1580+
original_numpy_to_infeed_manager_list)
15731581

15741582
def _pipeline_fit(self, x, y, batch_size, epochs, verbose, callbacks,
15751583
validation_split, validation_data, shuffle, class_weight,

0 commit comments

Comments
 (0)