title: Tensorflow Estimator API: Summaries
body: <p>I can't achieve to make summaries work with the Estimator API of Tensorflow.</p>
  
  <p>The Estimator class is very useful for many reasons: I have already implemented my own classes which are really similar but I am trying to switch to this one.</p>
  
  <p>Here is the code sample:</p>
  
  <pre><code>import tensorflow as tf
  import tensorflow.contrib.layers as layers
  import tensorflow.contrib.learn as learn
  import numpy as np
  
   # To reproduce the error: docker run --rm -w /algo -v $(pwd):/algo tensorflow/tensorflow bash -c "python sample.py"
  
  def model_fn(x, y, mode):
      logits = layers.fully_connected(x, 12, scope="dense-1")
      logits = layers.fully_connected(logits, 56, scope="dense-2")
      logits = layers.fully_connected(logits, 4, scope="dense-3")
  
      loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=y), name="xentropy")
  
      return {"predictions":logits}, loss, tf.train.AdamOptimizer(0.001).minimize(loss)
  
  
  def input_fun():
      """ To be completed for a 4 classes classification problem """
  
      feature = tf.constant(np.random.rand(100,10))
      labels = tf.constant(np.random.random_integers(0,3, size=(100,)))
  
      return feature, labels
  
  estimator = learn.Estimator(model_fn=model_fn, )
  
  trainingConfig = tf.contrib.learn.RunConfig(save_checkpoints_secs=60)
  
  estimator = learn.Estimator(model_fn=model_fn, model_dir="./tmp", config=trainingConfig)
  
  # Works
  estimator.fit(input_fn=input_fun, steps=2)
  
  # The following code does not work
  
  # Can't initialize saver
  
  # saver = tf.train.Saver(max_to_keep=10) # Error: No variables to save
  
  # The following fails because I am missing a saver... :(
  
  hooks=[
          tf.train.LoggingTensorHook(["xentropy"], every_n_iter=100),
          tf.train.CheckpointSaverHook("./tmp", save_steps=1000, checkpoint_basename='model.ckpt'),
          tf.train.StepCounterHook(every_n_steps=100, output_dir="./tmp"),
          tf.train.SummarySaverHook(save_steps=100, output_dir="./tmp"),
  ]
  
  estimator.fit(input_fn=input_fun, steps=2, monitors=hooks)
  </code></pre>
  
  <p>As you can see, I can create an Estimator and use it but I can achieve to add hooks to the fitting process.</p>
  
  <p>The logging hooks works just fine but the others require both <strong>tensors</strong> and a <strong>saver</strong> which I can't provide.</p>
  
  <p>The tensors are defined in the model function, thus I can't pass them to the <strong>SummaryHook</strong> and the <strong>Saver</strong> can't be initialized because there is no tensor to save...</p>
  
  <p>Is there a solution to my problem? (I am guessing yes but there is a lack of documentation of this part in the tensorflow documentation)</p>
  
  <ul>
  <li>How can I initialized my <strong>saver</strong>? Or should I use other objects such as <em>Scaffold</em>?</li>
  <li>How can I pass <strong>summaries</strong> to the <strong>SummaryHook</strong> since they are defined in my model function?</li>
  </ul>
  
  <p>Thanks in advance.</p>
  
  <p><em>PS: I have seen the DNNClassifier API but I want to use the estimator API for Convolutional Nets and others. I need to create summaries for any estimator.</em></p>