There are several different ways of dumping a TensorFlow graph into a file and then loading it into another program, this project provides clear examples/information on how they work:
- The checkpoint files (produced e.g. by calling saver.save() on a tf.train.Saver object) contain only the weights, and any other variables defined in the same program. To use them in another program, you must re-create the associated graph structure (e.g. by running code to build it again, or calling tf.import_graph_def()), which tells TensorFlow what to do with those weights. Note that calling saver.save() also produces a file containing a MetaGraphDef, which contains a graph and details of how to associate the weights from a checkpoint with that graph. See the tutorial for more details.*
- Freeze the graph to save the graph and weights together using freeze_graph. A frozen graph can be loaded using tf.import_graph_def()(This file may be not found in your tensorflow, you can save it to your project). In this case, the weights are (typically) embedded in the graph, so you don't need to load a separate checkpoint.
- Using Tensor/Variables: Using tf.initialize_variables(var_list) to initialize variables you need, and use tf.train.Optimizer.minize(loss,var_list) to optimize the variables.
- Using Constants: Using freeze_graph to store variables as constants
- TensorFlow saving into/loading a graph from a file
- Is there an example on how to generate protobuf files holding trained Tensorflow graphs
- How can I execute a TensorFlow graph from a protobuf in C++?
- A Tool Developer's Guide to TensorFlow Model Files
- Tensorflow APIs
- freeze_graph
- tf_restore_graph.py
- FineTune Overview