(summary_dir, scalar_tensors_dict)
return host_call_fn, scalar_tensors_dict
Creates a host_call function that writes summaries on TPU.
Creates a host_call function that writes summaries on TPU.
Creates a host_call function that writes summaries on TPU .
def add_scalars_to_summary(summary_dir, scalar_tensors_dict):
  """Creates a host_call function that writes summaries on TPU."""

  #  All tensors outfed from TPU should preserve batch size dimension.
  scalar_tensors_dict = {
      k: tf.reshape(v, [1]) for k, v in scalar_tensors_dict.items()
  }

  def host_call_fn(**kwargs):
    writer = contrib_summary.create_file_writer(summary_dir, max_queue=1000)
    always_record = contrib_summary.always_record_summaries()
    with writer.as_default(), always_record:
      for name, scalar in kwargs.items():
        contrib_summary.scalar(name, tf.reduce_mean(scalar))
      return contrib_summary.all_summary_ops()

  return host_call_fn, scalar_tensors_dict
def add_scalars_to_summary ( summary_dir , scalar_tensors_dict ) : #  All tensors outfed from TPU should preserve batch size dimension. scalar_tensors_dict = { k : tf . reshape ( v , [ 1 ] ) for k , v in scalar_tensors_dict . items ( ) } def host_call_fn ( * * kwargs ) : writer = contrib_summary . create_file_writer ( summary_dir , max_queue = 1000 ) always_record = contrib_summary . always_record_summaries ( ) with writer . as_default ( ) , always_record : for name , scalar in kwargs . items ( ) : contrib_summary . scalar ( name , tf . reduce_mean ( scalar ) ) return contrib_summary . all_summary_ops ( ) return host_call_fn , scalar_tensors_dict