Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code to pass appropriate logs to on_test|train_end() methods #38499

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions tensorflow/python/keras/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,9 @@ def on_train_end(self, logs=None):
Subclasses should override for any actions to run.

Arguments:
logs: Dict. Currently no data is passed to this argument for this method
but that may change in the future.
logs: Dict. Currently the output of the last call to `on_epoch_end()`
is passed to this argument for this method but that may change in
the future.
"""

@doc_controls.for_subclass_implementers
Expand All @@ -737,7 +738,8 @@ def on_test_end(self, logs=None):
Subclasses should override for any actions to run.

Arguments:
logs: Dict. Currently no data is passed to this argument for this method
logs: Dict. Currently the output of the last call to
`on_test_batch_end()` is passed to this argument for this method
but that may change in the future.
"""

Expand Down
8 changes: 5 additions & 3 deletions tensorflow/python/keras/engine/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,7 @@ def fit(self,
train_function = self.make_train_function()
self._train_counter.assign(0)
callbacks.on_train_begin()
training_logs = None
# Handle fault-tolerance for multi-worker.
# TODO(omalleyt): Fix the ordering issues that mean this has to
# happen after `callbacks.on_train_begin`.
Expand Down Expand Up @@ -944,10 +945,11 @@ def fit(self,
epoch_logs.update(val_logs)

callbacks.on_epoch_end(epoch, epoch_logs)
training_logs = epoch_logs
if self.stop_training:
break

callbacks.on_train_end()
callbacks.on_train_end(logs=training_logs)
return self.history

def test_step(self, data):
Expand Down Expand Up @@ -1177,9 +1179,9 @@ def evaluate(self,
logs = tmp_logs # No error, now safe to assign to logs.
end_step = step + data_handler.step_increment
callbacks.on_test_batch_end(end_step, logs)
callbacks.on_test_end()

logs = tf_utils.to_numpy_or_python_type(logs)
callbacks.on_test_end(logs=logs)

if return_dict:
return logs
else:
Expand Down