TensorFlow
model retraining
frozen model
machine learning
*.pb file

Re-train a frozen .pb model in TensorFlow

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

A frozen .pb model is meant for inference, not normal continued training. Freezing replaces trainable variables with constants, which means the original weights are no longer represented as mutable training state. So the honest answer is: you generally do not re-train a frozen graph directly. Instead, you either go back to the unfrozen checkpoint or use the frozen graph as a fixed feature extractor and train new layers on top.

Why Frozen Graphs Are Hard to Retrain

In TensorFlow 1.x style workflows, freezing converts variables into constant nodes inside the graph. Constants do not receive optimizer updates.

That means the normal training ingredients are missing:

  • mutable variables
  • optimizer state
  • a straightforward save-and-restore training path

So if the original checkpoint still exists, that is the best place to resume training.

Best Option: Go Back to the Original Checkpoint

If you have access to the original training graph and checkpoint files, use those instead of the frozen .pb.

python
1import tensorflow as tf
2
3checkpoint = tf.train.Checkpoint(model=model, optimizer=optimizer)
4checkpoint.restore('/path/to/checkpoint')
5model.fit(dataset, epochs=5)

This is the real retraining workflow. The frozen graph should be treated as a deployment artifact, not as the canonical training artifact.

Practical Alternative: Use the Frozen Graph as a Fixed Base

If the checkpoint is gone, the next realistic option is transfer learning: import the frozen graph, identify a useful output tensor, and attach new trainable layers on top.

In legacy TensorFlow 1.x style code, the import step looked like this:

python
1import tensorflow as tf
2
3graph = tf.Graph()
4with graph.as_default():
5    with tf.io.gfile.GFile('frozen_model.pb', 'rb') as f:
6        graph_def = tf.compat.v1.GraphDef()
7        graph_def.ParseFromString(f.read())
8        tf.import_graph_def(graph_def, name='')

At that point, the imported graph can serve as a fixed feature producer, but not as a fully retrainable network in the original sense.

What Fine-Tuning Looks Like in Practice

The common legacy strategy is:

  1. load the frozen graph
  2. locate the input tensor and a useful intermediate or output tensor
  3. feed data through the frozen base
  4. train a new classifier or regression head on top of those features

Conceptually, that is closer to transfer learning than full retraining.

If you control a newer TensorFlow or Keras pipeline, the better long-term move is to rebuild the model architecture in a trainable form, load whatever weights you can recover, and continue from there.

Reconstructing the Model Is Sometimes Possible

If you know the original architecture and can extract the constants, you may be able to rebuild a trainable model manually. But that is a reconstruction project, not a normal retraining workflow. It is error-prone, time-consuming, and usually only justified when the original training artifacts are lost and the model is too valuable to discard.

That is why the general engineering advice is simple: keep checkpoints or SavedModels, not just frozen .pb files.

Legacy TensorFlow Context Matters

Questions about frozen .pb files usually come from TensorFlow 1.x workflows. In modern TensorFlow, SavedModel and Keras model saving are better choices because they preserve more of the structure needed for reuse and fine-tuning.

So if you are designing a pipeline today, avoid depending on frozen graphs as the only long-term artifact.

Common Pitfalls

  • Assuming a frozen .pb file is just a normal training checkpoint in another format.
  • Trying to run optimizer updates against constants that were created during graph freezing.
  • Throwing away the original checkpoint and then expecting full fine-tuning to remain easy later.
  • Confusing transfer learning on top of frozen features with true retraining of the original model weights.
  • Keeping only deployment artifacts instead of storing trainable model artifacts such as checkpoints or SavedModels.

Summary

  • A frozen .pb model is primarily an inference artifact, not a normal retraining artifact.
  • The best retraining path is to return to the original checkpoint or unfrozen model.
  • If that is impossible, treat the frozen graph as a fixed feature extractor and train a new head on top.
  • Full reconstruction is possible only in special cases and is usually expensive.
  • Preserve trainable artifacts if you expect the model to be updated later.

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.