title: Tensorflow freeze_graph script failing on model defined with Keras
body: <p>I'm attempting to export a model built and trained with Keras to a protobuffer that I can load in a C++ script (as in this example). I've generated a .pb file containing the model definition and a .ckpt file containing the checkpoint data. However, when I try to merge them into a single file using the freeze_graph script I get the error: </p>
  
  <pre><code>ValueError: Fetch argument 'save/restore_all' of 'save/restore_all' cannot be interpreted as a Tensor. ("The name 'save/restore_all' refers to an Operation not in the graph.")
  </code></pre>
  
  <p>I'm saving the model like this:</p>
  
  <pre><code>with tf.Session() as sess:
      model = nndetector.architecture.models.vgg19((3, 50, 50))
      model.load_weights('/srv/nn/weights/scratch-vgg19.h5')
      init_op = tf.initialize_all_variables()
      sess.run(init_op)
      graph_def = sess.graph.as_graph_def()
      tf.train.write_graph(graph_def=graph_def, logdir='.',   name='model.pb', as_text=False)
      saver = tf.train.Saver()
      saver.save(sess, 'model.ckpt')
  </code></pre>
  
  <p>nndetector.architecture.models.vgg19((3, 50, 50)) is simply a vgg19-like model defined in Keras.</p>
  
  <p>I'm calling the freeze_graph script like this: </p>
  
  <pre><code>bazel-bin/tensorflow/python/tools/freeze_graph --input_graph=[path-to-model.pb] --input_checkpoint=[path-to-model.ckpt] --output_graph=[output-path] --output_node_names=sigmoid --input_binary=True
  </code></pre>
  
  <p>If I run the <code>freeze_graph_test</code> script everything works fine.</p>
  
  <p>Does anyone know what I'm doing wrong?</p>
  
  <p>Thanks.</p>
  
  <p>Best regards</p>
  
  <p>Philip</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I've tried printing <code>tf.train.Saver().as_saver_def().restore_op_name</code> which returns <code>save/restore_all</code>.</p>
  
  <p>Additionally, I've tried a simple pure tensorflow example and still get the same error:</p>
  
  <pre><code>a = tf.Variable(tf.constant(1), name='a')
  b = tf.Variable(tf.constant(2), name='b')
  add = tf.add(a, b, 'sum')
  
  with tf.Session() as sess:
  sess.run(tf.initialize_all_variables())
  tf.train.write_graph(graph_def=sess.graph.as_graph_def(), logdir='.',     name='simple_as_binary.pb', as_text=False)
  tf.train.Saver().save(sess, 'simple.ckpt')
  </code></pre>
  
  <p>And I'm actually also unable to restore the graph in python. Using the following code throws <code>ValueError: No variables to save</code> if I execute it separately from saving the graph (that is, if I both save and restore the model in the same script, everything works fine).</p>
  
  <pre><code>with gfile.FastGFile('simple_as_binary.pb') as f:
      graph_def = tf.GraphDef()
      graph_def.ParseFromString(f.read())
  
  with tf.Session() as sess:
      tf.import_graph_def(graph_def)
      saver = tf.train.Saver()
      saver.restore(sess, 'simple.ckpt')
  </code></pre>
  
  <p>I'm not sure if the two problems are related, or if I'm simply not restoring the model correctly in python.</p>