Sebastian Metzler
Sebastian Metzler

Reputation: 242

Save tf.summary.image with Estimator API

at the moment I trying to get a little bit more familiar with the TF Estimator API. I'm working/learning with the example from this blog entry.

Now I have the problem that I'm not able to save a simple image summary (tf.summary.image).

I added a SummarySaverHook in the experiment_fn and add the hook to the eval_hooks parameter of the Experiment constructor:

def experiment_fn(run_config, params):
   ...
   summary_hook = tf.train.SummarySaverHook(
      100,
      output_dir='/summeries',
      summary_op=tf.summary.merge_all()
   )
   ...
   experiment = tf.contrib.learn.Experiment(
      estimator=estimator,  # Estimator
      train_input_fn=train_input_fn,  # First-class function
      eval_input_fn=eval_input_fn,  # First-class function
      train_steps=params.train_steps,  # Minibatch steps
      min_eval_frequency=params.min_eval_frequency,  # Eval frequency
      train_monitors=[train_input_hook],  # Hooks for training
      eval_hooks=[eval_input_hook, summary_hook],  # Hooks for evaluation
      eval_steps=None  # Use evaluation feeder until its empty
   )

What is not clear to me is where I have to add the tf.summary.image() function so that the image will be shown in the image tab of tensorboard.

Thanks in advance.

Upvotes: 2

Views: 1097

Answers (1)

DomJack
DomJack

Reputation: 4183

You shouldn't have to add a hook. Just add the tf.summary.image call anywhere in your model_fn/input_fn and the estimator should automatically add a summary hook for all summaries created.

Upvotes: 1

Related Questions