machine learning
pre-trained models
TensorFlow
PyTorch
model formats

Pre-trained checkpoints .chkpt Vs GraphDef .pb

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

In TensorFlow, a checkpoint and a GraphDef .pb file solve different problems even though both are associated with saved models. A checkpoint is primarily about restoring variables so you can resume or reuse model state, while a GraphDef .pb file is a serialized computation graph, often used for inference-oriented export in older TensorFlow workflows.

What a Checkpoint Contains

A TensorFlow checkpoint stores variable values and the information needed to restore those variables into a compatible object graph. In practical terms, checkpoints are for state restoration.

Typical uses include:

  • continuing interrupted training
  • loading pre-trained weights into the same model architecture
  • restoring optimizer state when the checkpoint tracks it

A minimal TensorFlow 2 example looks like this.

python
1import tensorflow as tf
2
3weight = tf.Variable(3.0)
4ckpt = tf.train.Checkpoint(weight=weight)
5path = ckpt.save("/tmp/demo_ckpt")
6
7weight.assign(0.0)
8ckpt.restore(path).assert_consumed()
9print(weight.numpy())

After restoration, weight returns to the saved value.

The important point is that a checkpoint does not stand alone as a full deployable inference artifact. It assumes you know what variables should exist and where they belong.

What a GraphDef .pb File Contains

A GraphDef .pb file is a serialized protobuf representation of a TensorFlow graph. In older TensorFlow 1.x workflows, it was common to freeze a graph so that variable values became constants embedded into the graph, producing a single inference-oriented .pb file.

A small TensorFlow 2 example can still produce a frozen GraphDef.

python
1import tensorflow as tf
2from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2
3
4class AddOne(tf.Module):
5    @tf.function(input_signature=[tf.TensorSpec(shape=None, dtype=tf.float32)])
6    def __call__(self, x):
7        return x + 1.0
8
9module = AddOne()
10concrete = module.__call__.get_concrete_function()
11frozen = convert_variables_to_constants_v2(concrete)
12
13tf.io.write_graph(frozen.graph, "/tmp", "add_one.pb", as_text=False)

That .pb file describes computation. In a frozen graph scenario, it may also contain the constant values needed for inference.

The Practical Difference

The simplest mental model is:

  • checkpoint equals restorable state
  • GraphDef .pb equals serialized graph structure

That difference drives how each format is used.

If you want to fine-tune a model, continue training, or swap weights into the same architecture, use a checkpoint.

If you want an older-style inference graph that can be loaded and executed as a frozen computation, a .pb graph is the relevant artifact.

Why Confusion Happens

Many pre-trained TensorFlow models used to ship as a mix of graph files, checkpoint files, label maps, and config files. People would see both a checkpoint and a .pb file in the same project and assume they were interchangeable.

They are not.

A checkpoint generally needs compatible code or an equivalent object structure to restore into. A frozen .pb graph is closer to a portable inference representation, but it is less convenient for further training because the variables may no longer exist as variables.

Legacy TensorFlow vs Current Practice

The checkpoint-versus-GraphDef distinction comes mostly from TensorFlow 1.x mental models. In current TensorFlow workflows, you will more often see:

  • checkpoints for training state
  • 'SavedModel for export and serving'
  • '.keras for Keras-native saving workflows'

That means raw .pb questions are often legacy deployment questions rather than the default modern recommendation.

Still, understanding the distinction matters when you inherit older pre-trained model packages or need to convert legacy assets.

Common Pitfalls

The most common mistake is trying to resume training from a .pb graph as if it were a normal checkpoint.

Another mistake is assuming a checkpoint is self-sufficient for inference deployment. It is not, because the runtime still needs the compatible model structure.

A third issue is mixing TensorFlow 1.x terminology with TensorFlow 2 saving APIs without noticing that the preferred export formats changed.

Finally, do not assume that a file extension tells the whole story. The actual contents and the surrounding loading code matter.

Summary

  • A checkpoint stores variable state for restoration and continued model use.
  • A GraphDef .pb file stores a serialized computation graph, often for legacy inference export.
  • Checkpoints are the right tool for resuming training or loading weights into a compatible model.
  • Frozen .pb graphs are more aligned with inference than with ongoing training.
  • In modern TensorFlow, SavedModel and .keras are often more relevant than raw GraphDef files.
  • When working with pre-trained assets, identify whether you need state restoration or graph export before choosing the format.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Practice ML system design

All Rights Reserved.