How to find the Input and Output Nodes of a Frozen Model
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
A frozen model is usually a TensorFlow graph definition, often stored as a .pb file, where variables have been turned into constants for inference. To run inference or convert the model to another format, you need to know which nodes feed data into the graph and which nodes represent the final outputs you care about.
The awkward part is that a frozen graph can contain many operations, including preprocessing, intermediate tensors, and control nodes. So "find the inputs and outputs" usually means inspecting the graph and identifying placeholders on the front edge and terminal prediction tensors on the back edge.
Load the Frozen Graph
In legacy TensorFlow workflows, a frozen graph is often inspected through tf.compat.v1:
Using name="" avoids adding a prefix such as import/, which makes node names easier to read.
Find Likely Input Nodes
For many frozen models, input nodes are operations of type Placeholder:
This is often enough for simple inference graphs. A placeholder is a strong hint that external data is expected to be fed there.
Be aware that some graphs have multiple placeholders, such as:
- the main input tensor,
- a dropout keep-prob placeholder in older models,
- a boolean training flag,
- sequence-length tensors or auxiliary inputs.
So not every placeholder is necessarily a user-facing model input.
Find Likely Output Nodes
A common heuristic is to look for ops whose outputs are not consumed by later ops:
This lists terminal tensors. It is a useful starting point, though some terminal nodes may be irrelevant housekeeping outputs rather than the final prediction you want.
Use Graph Semantics, Not Just Heuristics
Placeholders and terminal tensors are heuristics, not perfect truth. You still need to interpret the model:
- a node named
input_idsorimagesis often a true input, - a node named
Softmax,Identity,ArgMax, orlogitsis often a likely output, - dropout or training placeholders may not be needed for inference,
- some models expose an
Identityop just to give the final tensor a stable export name.
That is why inspecting node names is often as important as inspecting node types.
A Practical Inspection Script
Here is a compact script that prints both placeholders and terminal tensors:
This gives you a manageable list to compare against documentation, training code, or model-export scripts.
Common Pitfalls
- Assuming every placeholder is a real user input rather than a training-only control tensor.
- Assuming every terminal tensor is the desired prediction output.
- Forgetting that imported graphs may add name prefixes if imported with a non-empty scope.
- Treating all
.pbfiles the same without knowing whether they are frozen graphs, SavedModel assets, or something else. - Skipping node-name inspection and relying only on op type.
Summary
- Frozen models are usually inspected by loading the graph and listing operations.
- '
Placeholderops are the first place to look for inputs.' - Tensors with no consumers are good candidates for outputs.
- Node names such as
logits,Softmax, orIdentityoften help confirm the real inference outputs. - Heuristics get you close, but final confirmation should come from model context or export documentation.
Related reading
- How to find the wrong predictions in Keras?
- How to find wrong prediction cases in test set CNNs using Keras
- How to Fine-tuning a Pretrained Network in Tensorflow?
- How to fit list of numpy array into LSTM Neural Network?
- How to find the most likely sequences of hidden states for a Hidden Markov Model
- How to find which version of TensorFlow is installed in my system?
- How to fix low volatile GPU-Util with Tensorflow-GPU and Keras?
- How to fix 'Object arrays cannot be loaded when allow_pickleFalse' in the sketch_rnn algorithm
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.