How do I find the variable names and values that are saved in a checkpoint?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
In TensorFlow, the easiest way to inspect a checkpoint is to list the variable names first and then read individual tensors by name. The main tools are tf.train.list_variables() for names and shapes, and tf.train.load_checkpoint() for fetching the stored values.
Start by Listing What Is Inside the Checkpoint
If you already know the checkpoint path, list the variables before trying to read values. That tells you the exact names TensorFlow saved.
This step is important because TensorFlow variable names inside checkpoints are often more detailed than the names you expect from model code, especially in object-based checkpoints.
Read Individual Tensor Values
Once you know the variable name, use a checkpoint reader to fetch the actual tensor value.
This is the most direct inspection workflow in TensorFlow 2.
A Small End-to-End Example
It helps to see where these names come from. In object-based checkpoints, the names often reflect object attributes.
When you run this, the names will come from the checkpoint object graph, not just from the short weight and bias labels you see in Python source.
Why the Names Sometimes Look Strange
TensorFlow 2 checkpoints are object-based, which means paths are derived from tracked object attributes. That is why names may look more like:
- object paths
- layer attribute names
- internal variable keys
than like the plain variable names you remember from model code.
This often surprises people migrating from older TensorFlow 1 workflows, where variable naming conventions felt more graph-centric.
Use the Exact Name Returned by list_variables
If you try to guess a name instead of reading it from the checkpoint metadata first, you will often get a key error or the wrong tensor. The safest sequence is:
- call
list_variables - copy the exact name
- call
get_tensor(name)
That works for both model weights and optimizer state stored in the checkpoint.
Checkpoint Directory Versus Specific File
TensorFlow APIs can work with either:
- a checkpoint directory that has checkpoint metadata
- a fully resolved checkpoint prefix
Using tf.train.latest_checkpoint() is often the safest option because it resolves the newest checkpoint prefix correctly.
If this returns None, the issue is not variable inspection. It means TensorFlow did not find a valid checkpoint there.
SavedModel Is a Different Question
People sometimes confuse checkpoints with SavedModel exports. They are related but not identical:
- checkpoints store variable state
- SavedModel stores an exportable model artifact with signatures and weights
If your goal is “inspect raw variables,” the checkpoint APIs are the right place to start.
Common Pitfalls
- Guessing variable names instead of listing them from the checkpoint first.
- Pointing
list_variablesat the wrong directory and then assuming the checkpoint is empty. - Forgetting that TensorFlow 2 uses object-based checkpoint naming, which can look different from layer variable names in source code.
- Expecting SavedModel inspection tools to answer raw checkpoint questions directly.
- Printing every tensor value from a huge checkpoint without filtering, which can produce an overwhelming amount of output.
Summary
- Use
tf.train.list_variables()to discover the names and shapes saved in a checkpoint. - Use
tf.train.load_checkpoint()andget_tensor()to inspect actual values. - Let
tf.train.latest_checkpoint()resolve the current checkpoint prefix when possible. - Expect TensorFlow 2 checkpoint names to reflect object paths, not just short variable names.
- List first, then read values by exact name.

