Last active
December 10, 2018 07:01
-
-
Save devforfu/0fa872d97950376a8c7aba0384947995 to your computer and use it in GitHub Desktop.
Stream Logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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