MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / BaseLogger

Class BaseLogger

tensorflow/python/keras/callbacks.py:631–676  ·  view source on GitHub ↗

Callback that accumulates epoch averages of metrics. This callback is automatically applied to every Keras model. Arguments: stateful_metrics: Iterable of string names of metrics that should *not* be averaged over an epoch. Metrics in this list will be logged as-is in

Source from the content-addressed store, hash-verified

629
630@keras_export('keras.callbacks.BaseLogger')
631class BaseLogger(Callback):
632 """Callback that accumulates epoch averages of metrics.
633
634 This callback is automatically applied to every Keras model.
635
636 Arguments:
637 stateful_metrics: Iterable of string names of metrics that
638 should *not* be averaged over an epoch.
639 Metrics in this list will be logged as-is in `on_epoch_end`.
640 All others will be averaged in `on_epoch_end`.
641 """
642
643 def __init__(self, stateful_metrics=None):
644 super(BaseLogger, self).__init__()
645 self.stateful_metrics = set(stateful_metrics or [])
646
647 def on_epoch_begin(self, epoch, logs=None):
648 self.seen = 0
649 self.totals = {}
650
651 def on_batch_end(self, batch, logs=None):
652 logs = logs or {}
653 batch_size = logs.get('size', 0)
654 # In case of distribution strategy we can potentially run multiple steps
655 # at the same time, we should account for that in the `seen` calculation.
656 num_steps = logs.get('num_steps', 1)
657 self.seen += batch_size * num_steps
658
659 for k, v in logs.items():
660 if k in self.stateful_metrics:
661 self.totals[k] = v
662 else:
663 if k in self.totals:
664 self.totals[k] += v * batch_size
665 else:
666 self.totals[k] = v * batch_size
667
668 def on_epoch_end(self, epoch, logs=None):
669 if logs is not None:
670 for k in self.params['metrics']:
671 if k in self.totals:
672 # Make value available to next callbacks.
673 if k in self.stateful_metrics:
674 logs[k] = self.totals[k]
675 else:
676 logs[k] = self.totals[k] / self.seen
677
678
679@keras_export('keras.callbacks.TerminateOnNaN')

Callers 1

configure_callbacksFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected