in tensorflow_fold/blocks/plan.py [0:0]
def finalize_stats(self):
"""Finalizes metrics and losses. Gets/creates global_step if unset."""
if self.has_finalized_stats:
raise RuntimeError('finalize_stats() has already been called')
self._finalized = True
if self.compute_summaries:
for name, tensor in six.iteritems(self.metrics):
if tensor.get_shape().ndims == 0:
tf.summary.scalar(name, tensor)
else:
tf.summary.histogram(name, tensor)
if self.losses:
loss_dtype = next(six.itervalues(self.losses)).dtype
if not loss_dtype.is_floating:
raise TypeError('invalid loss dtype %r, must be a floating point type'
% loss_dtype)
if self.compute_summaries:
self._batch_size_ph = tf.placeholder(loss_dtype, [], name='batch_size')
loss_sums = []
for name, tensor in six.iteritems(self.losses):
loss_sums.append(tf.reduce_sum(tensor))
if self.compute_summaries:
tf.summary.scalar(name, loss_sums[-1] / self._batch_size_ph)
if loss_sums:
self._loss_total = tf.add_n(loss_sums)
# computing a loss total summary is redundant if there is only one loss
if self.compute_summaries and len(loss_sums) > 1:
tf.summary.scalar('loss_total', self.loss_total / self._batch_size_ph)
if self.compute_summaries:
self._summaries = tf.summary.merge_all()
if self._summaries is None: self._summaries = tf.constant('')