Writes metrics out as custom scalar summaries. Arguments: logs: Dict. Keys are scalar summary names, values are NumPy scalars. prefix: String. The prefix to apply to the scalar summary names. step: Int. The global step to use for TensorBoard.
(self, logs, prefix, step)
| 1705 | self._is_tracing = False |
| 1706 | |
| 1707 | def _log_metrics(self, logs, prefix, step): |
| 1708 | """Writes metrics out as custom scalar summaries. |
| 1709 | |
| 1710 | Arguments: |
| 1711 | logs: Dict. Keys are scalar summary names, values are NumPy scalars. |
| 1712 | prefix: String. The prefix to apply to the scalar summary names. |
| 1713 | step: Int. The global step to use for TensorBoard. |
| 1714 | """ |
| 1715 | if logs is None: |
| 1716 | logs = {} |
| 1717 | |
| 1718 | # Group metrics by the name of their associated file writer. Values |
| 1719 | # are lists of metrics, as (name, scalar_value) pairs. |
| 1720 | logs_by_writer = { |
| 1721 | self._train_run_name: [], |
| 1722 | self._validation_run_name: [], |
| 1723 | } |
| 1724 | validation_prefix = 'val_' |
| 1725 | for (name, value) in logs.items(): |
| 1726 | if name in ('batch', 'size', 'num_steps'): |
| 1727 | # Scrub non-metric items. |
| 1728 | continue |
| 1729 | if name.startswith(validation_prefix): |
| 1730 | name = name[len(validation_prefix):] |
| 1731 | writer_name = self._validation_run_name |
| 1732 | else: |
| 1733 | writer_name = self._train_run_name |
| 1734 | name = prefix + name # assign batch or epoch prefix |
| 1735 | logs_by_writer[writer_name].append((name, value)) |
| 1736 | |
| 1737 | with context.eager_mode(): |
| 1738 | with summary_ops_v2.always_record_summaries(): |
| 1739 | for writer_name in logs_by_writer: |
| 1740 | these_logs = logs_by_writer[writer_name] |
| 1741 | if not these_logs: |
| 1742 | # Don't create a "validation" events file if we don't |
| 1743 | # actually have any validation data. |
| 1744 | continue |
| 1745 | writer = self._get_writer(writer_name) |
| 1746 | with writer.as_default(): |
| 1747 | for (name, value) in these_logs: |
| 1748 | summary_ops_v2.scalar(name, value, step=step) |
| 1749 | |
| 1750 | def _log_weights(self, epoch): |
| 1751 | """Logs the weights of the Model to TensorBoard.""" |
no test coverage detected