Skip to content

Instantly share code, notes, and snippets.

@devforfu
Last active December 10, 2018 07:01
Show Gist options
  • Save devforfu/0fa872d97950376a8c7aba0384947995 to your computer and use it in GitHub Desktop.
Save devforfu/0fa872d97950376a8c7aba0384947995 to your computer and use it in GitHub Desktop.
Stream Logger
class StreamLogger(Callback):
def __init__(self, streams=None, log_every=1):
self.streams = streams or [sys.stdout]
self.log_every = log_every
def epoch_ended(self, phases, epoch, **kwargs):
if epoch % self.log_every != 0:
return
metrics = merge_dicts([phase.last_metrics for phase in phases])
values = [f'{k}={v:.4f}' for k, v in metrics.items()]
values_string = ', '.join(values)
string = f'Epoch: {epoch:4d} | {values_string}\n'
for stream in self.streams:
stream.write(string)
stream.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment