title: TensorFlow saving into/loading a graph from a file
body: <p>From what I've gathered so far, there are several different ways of dumping a TensorFlow graph into a file and then loading it into another program, but I haven't been able to find clear examples/information on how they work. What I already know is this:</p>
  
  <ol>
  <li>Save the model's variables into a checkpoint file (.ckpt) using a <code>tf.train.Saver()</code> and restore them later (<a href="https://www.tensorflow.org/versions/r0.10/how_tos/variables/index.html" rel="noreferrer">source</a>)</li>
  <li>Save a model into a .pb file and load it back in using <code>tf.train.write_graph()</code> and <code>tf.import_graph_def()</code> (<a href="https://github.com/tensorflow/tensorflow/issues/616" rel="noreferrer">source</a>)</li>
  <li>Load in a model from a .pb file, retrain it, and dump it into a new .pb file using Bazel (<a href="https://petewarden.com/2016/02/28/tensorflow-for-poets/" rel="noreferrer">source</a>)</li>
  <li>Freeze the graph to save the graph and weights together (<a href="https://www.tensorflow.org/versions/r0.9/how_tos/tool_developers/index.html#freezing" rel="noreferrer">source</a>)</li>
  <li>Use <code>as_graph_def()</code> to save the model, and for weights/variables, map them into constants (<a href="https://stackoverflow.com/questions/34343259/is-there-an-example-on-how-to-generate-protobuf-files-holding-trained-tensorflow">source</a>)</li>
  </ol>
  
  <p>However, I haven't been able to clear up several questions regarding these different methods:</p>
  
  <ol>
  <li>Regarding checkpoint files, do they only save the trained weights of a model? Could checkpoint files be loaded into a new program, and be used to run the model, or do they simply serve as ways to save the weights in a model at a certain time/stage?</li>
  <li>Regarding <code>tf.train.write_graph()</code>, are the weights/variables saved as well?</li>
  <li>Regarding Bazel, can it only save into/load from .pb files for retraining? Is there a simple Bazel command just to dump a graph into a .pb?</li>
  <li>Regarding freezing, can a frozen graph be loaded in using <code>tf.import_graph_def()</code>?</li>
  <li>The Android demo for TensorFlow loads in Google's Inception model from a .pb file. If I wanted to substitute my own .pb file, how would I go about doing that? Would I need to change any native code/methods?</li>
  <li>In general, what exactly is the difference between all these methods? Or more broadly, what is the difference between <code>as_graph_def()</code>/.ckpt/.pb?</li>
  </ol>
  
  <p>In short, what I'm looking for is a method to save both a graph (as in, the various operations and such) and its weights/variables into a file, which can then be used to load the graph and weights into another program, for use (not necessarily continuing/retraining).</p>
  
  <p>Documentation about this topic isn't very straightforward, so any answers/information would be greatly appreciated.</p>