Is it possible to use the freeze_graph.py
tool with models saved via saver.save
in TensorFlow v1? If so, how?
I have code that looks roughly like this:
supervisor = tf.train.Supervisor(logdir=output_directory_path)
with supervisor.managed_session() as session:
# train the model here
supervisor.saver.save(session, output_directory_path)
This produces a directory containing:
checkpoint
output
output-16640.data-00000-of-00001
output-16640.index
output-16640.meta
Where output
is a directory containing the files for intermediate training steps. The rest are files.
My understanding is that this is a meta graph (the .meta
file) and its variables (the .data*
file) in saver v2 format. These files contain the data needed for the freeze_graph.py
tool but it is unclear how to tell the freeze_graph.py
tool to load the data from these files.
All of these attempts produce the error message Input checkpoint '...' doesn't exist!
python freeze_graph.py --input_checkpoint checkpoint --output_graph /tmp/out
python freeze_graph.py --input_checkpoint . --output_graph /tmp/out
python freeze_graph.py --input_checkpoint output-16640 --output_graph /tmp/out
The freeze_graph.py
code includes the comment 'input_checkpoint' may be a prefix if we're using Saver V2 format
next to where the --input_checkpoint
argument is used so I had thought the third of the above attempts would work but, alas, no.
As @mrry pointed out in a comment, the answer to this particular question is to prefix the output prefix with ./
. When this was done I discovered it is also necessary to provide values for the --input_graph
and --output_name_names
arguments.
The command now looks like
python freeze_graph.py \
--input_graph output/graph.pbtxt \
--input_checkpoint ./output-16640 \
--output_graph /tmp/out \
--output_node_names <name>
Unfortunately my graph contains variables for pre-loaded data which causes freeze_graph.py
to fail with a message like Attempting to use uninitialized value ...
; solving this subsequent problem is beyond the scope of this question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With