gin/tf/utils.py
def after_create_session(self, session=None, coord=None):
    """Writes out Gin's operative config, and maybe adds a summary of it."""
    config_str = config.operative_config_str()
    if not tf.gfile.IsDirectory(self._output_dir):
      tf.gfile.MakeDirs(self._output_dir)
    global_step_val = 0
    if session is not None:
      global_step = tf.train.get_global_step()
      if global_step is not None:
        global_step_val = session.run(global_step)
    filename = '%s-%s.gin' % (self._base_name, global_step_val)
    config_path = os.path.join(self._output_dir, filename)
    with tf.gfile.GFile(config_path, 'w') as f:
      f.write(config_str)

    if self._summarize_config:
      md_config_str = self._markdownify_operative_config_str(config_str)
      summary_metadata = summary_pb2.SummaryMetadata()
      summary_metadata.plugin_data.plugin_name = 'text'
      summary_metadata.plugin_data.content = b'{}'
      text_tensor = tf.make_tensor_proto(md_config_str)
      summary = summary_pb2.Summary()
      summary.value.add(
          tag='gin/' + self._base_name,
          tensor=text_tensor,
          metadata=summary_metadata)
      if not self._summary_writer:
        # Creating the FileWriter also creates the events file, so it should be
        # done here (where it is most likely to only occur on chief workers), as
        # opposed to in the constructor.
        self._summary_writer = tf.summary.FileWriterCache.get(self._output_dir)
      self._summary_writer.add_summary(summary, global_step_val)
      self._summary_writer.flush()
def after_create_session(self, session=None, coord=None):
    """Writes out Gin's operative config, and maybe adds a summary of it."""
    config_str = config.operative_config_str()
    if not tf.gfile.IsDirectory(self._output_dir):
      tf.gfile.MakeDirs(self._output_dir)
    global_step_val = 0
    if session is not None:
      global_step = tf.train.get_global_step()
      if global_step is not None:
        global_step_val = session.run(global_step)
    filename = '%s-%s.gin' % (self._base_name, global_step_val)
    config_path = os.path.join(self._output_dir, filename)
    with tf.gfile.GFile(config_path, 'w') as f:
      f.write(config_str)

    if self._summarize_config:
      md_config_str = self._markdownify_operative_config_str(config_str)
      summary_metadata = summary_pb2.SummaryMetadata()
      summary_metadata.plugin_data.plugin_name = 'text'
      summary_metadata.plugin_data.content = b'{}'
      text_tensor = tf.make_tensor_proto(md_config_str)
      summary = summary_pb2.Summary()
      summary.value.add(
          tag='gin/' + self._base_name,
          tensor=text_tensor,
          metadata=summary_metadata)
      if not self._summary_writer:
        # Creating the FileWriter also creates the events file, so it should be
        # done here (where it is most likely to only occur on chief workers), as
        # opposed to in the constructor.
        self._summary_writer = tf.summary.FileWriterCache.get(self._output_dir)
      self._summary_writer.add_summary(summary, global_step_val)
      self._summary_writer.flush()
Writes out Gin's operative config, and maybe adds a summary of it.