10

I am a beginner in NN APIs and TensorFlow.

I am trying to save my trained model in protobuff format (.pb), there are many blogs explaining how to save the model as protobuff. One thing I did not understand is what is the importance of freezing the graph before saving it as protobuff? I read that freezing coverts variable to constants, does that mean the model is not trainable anymore? What else will freezing do on models? What is that model loses after freezing? Can anyone please explain or give some pointers on details of freezing?

Gibolt
  • 42,564
  • 15
  • 187
  • 127
DTharun
  • 746
  • 7
  • 16

2 Answers2

5

This is only a partial answer to your question.

A freezed graph is easily optimizable. When doing inference (forward propagation) for instance you can fuse some of the layers together. This you can't do with a graph separated between variables and operations (a not frozen graph). Why would you want to fuse layers together? There are multiple reasons. Going hardware specific: it might be easier to compute a number of operations together in a group of tensors, specific to the structure of your cpu or gpu. TensorRT is a graph optimizer for instance that works starting from a frozen graph (here more info on graph optimizations done by tensorRT: https://devblogs.nvidia.com/tensorrt-integration-speeds-tensorflow-inference/ ). This software does graph optimizations as well as hardware specific ones.

As far as I understand you can unfreeze a graph. I have only worked optimizing them, so I haven't use this feature. But here there is code for it: https://gist.github.com/tokestermw/795cc1fd6d0c9069b20204cbd133e36b

Here is another question that might be useful: TensorFlow: Is there a way to convert a frozen graph into a checkpoint model? It has not yet been answered though.

Nyla Worker
  • 133
  • 2
  • 11
2

Freezing the model means producing a singular file containing information about the graph and checkpoint variables, but saving these hyperparameters as constants within the graph structure. This eliminates additional information saved in the checkpoint files such as the gradients at each point, which are included so that the model can be reloaded and training continued from where you left off. As this is not needed when serving a model purely for inference they are discarded in freezing. A frozen model is a file of the Google .pb file type.

Sai Krishnadas
  • 2,863
  • 9
  • 36
  • 69