Skip to content

Commit

Permalink
refactor: _log_epoch_metrics()
Browse files Browse the repository at this point in the history
In this refactored version, I have changed the code to consolidate two loops into one loop for the same method, improving efficiency and readability.
  • Loading branch information
arjun-234 authored Jul 3, 2023
1 parent 428ed9f commit 6a05407
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions keras/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2889,8 +2889,14 @@ def _log_epoch_metrics(self, epoch, logs):
if not logs:
return

train_logs = {k: v for k, v in logs.items() if not k.startswith("val_")}
val_logs = {k: v for k, v in logs.items() if k.startswith("val_")}
train_logs = dict()
val_logs = dict()
for k, v in logs.items():
if k.startswith("val_"):
val_logs[k] = v
else:
train_logs[k] = v

train_logs = self._collect_learning_rate(train_logs)
if self.write_steps_per_second:
train_logs["steps_per_second"] = self._compute_steps_per_second()
Expand Down

0 comments on commit 6a05407

Please sign in to comment.