Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

@AyushP123, I guess a first question is how to save the graph at least to load it in TensorFlow again? Because you need to find a way to restore it. There is some way to do it:

-- Save

# Save a graph definition (once)
tf.train.write_graph(sess.graph.as_graph_def(), "", "graph.pb")

# Weights initialization
sess.run(tf.global_variables_initializer())

# Training
...

# Save a checkpoint (weights only, no graph definition)
saver = tf.train.Saver()
saver.save(sess, 'tmp.ckpt')

-- Freeze (merge graph definition with weights, remove training-only nodes)

python ~/tensorflow/tensorflow/python/tools/freeze_graph.py \
  --input_graph=graph.pb \
  --input_checkpoint=tmp.ckpt \
  --output_graph=frozen_graph.pb \
  --output_node_names="NameOfOutputNode"

Only after these steps you might load frozen_graph.pb contains both graph definition and weights using OpenCV.