TensorFlow freeze_graph.py The name 'save/Const0' refers to a Tensor which does not exist
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The error The name 'save/Const:0' refers to a Tensor which does not exist occurs when using TensorFlow's freeze_graph.py utility to convert a checkpoint into a frozen graph (a single .pb file with weights baked in). This error means the graph definition file (.pb or .pbtxt) does not contain the saver nodes that freeze_graph expects, typically because the graph was exported without including the saver operations.
What freeze_graph Does
freeze_graph.py takes two inputs:
- A graph definition file (
.pbor.pbtxt) containing the computation graph structure - A checkpoint file (
.ckpt) containing the trained weights
It combines them into a single frozen graph where all variables are replaced with constants, making the model portable for inference.
Why This Error Happens
The save/Const:0 tensor is part of TensorFlow's tf.train.Saver operations. When you export the graph definition using tf.train.write_graph(), the saver nodes may not be included if the saver was not yet created at export time:
The graph definition was saved before the saver was added, so freeze_graph cannot find save/Const:0.
How to Fix It
Fix 1: Export the Graph After Creating the Saver
Create the saver first, then export the graph:
Fix 2: Use tf.train.Saver Default Name
freeze_graph looks for saver nodes with the default name prefix save/. If you used a custom saver name, specify it:
If your saver uses a custom name:
Then use:
Fix 3: Use freeze_graph API in Python
Instead of the command-line script, use the Python API which gives you more control:
Fix 4: Use SavedModel Instead (Recommended)
For TensorFlow 2.x, freeze_graph is deprecated. Use SavedModel format instead:
Inspecting Graph Nodes
To debug which nodes exist in your graph:
If this prints no saver nodes, the graph was exported without them.
Common Pitfalls
- Order of operations: The saver must be created before
tf.train.write_graph(). Creating it after means the graph definition does not contain saver operations. - MetaGraph vs GraphDef:
tf.train.Saver.save()also creates a.metafile containing the saver nodes. You can use--input_saverto point to the meta file instead of relying on the graph def. - TF 2.x migration:
freeze_graph.pyis a TF 1.x tool. In TF 2.x, useconvert_variables_to_constants_v2or export as SavedModel directly. - Output node names: The
--output_node_namesmust exactly match the name of your model's output tensor (without the:0suffix). Use the node inspection code above to find the correct name. - Binary vs text format: If your graph file is
.pbtxt(text format), set--input_binary=false.
Summary
- This error means the graph definition file is missing saver nodes (
save/Const:0) - Fix by creating
tf.train.Saver()before callingtf.train.write_graph() - Alternatively, pass the
.metafile via--input_saverflag - For TF 2.x, use SavedModel format and
convert_variables_to_constants_v2instead offreeze_graph - Inspect graph nodes with a Python script to verify saver operations exist

