5
votes

I've built and trained some networks with TensorFlow and successfully managed to save and restore the model's parameters.

However, for some scenarios - e.g. like deploying a trained network in a customer's infrastructure - it is not the best solution to ship the full code/model. Thus, I am wondering if there is any way to restore/run a trained network without the original code/model used for training?

I guess this leads to the question if TensorFlow is able to save a (compressed?) version of the network architecture into the checkpoint files in addition to the weights of the variables.

Is this somehow possible?

1
Are you looking for TensorFlow Serving? - Sung Kim
At the moment (e.g. for testing models on robots, where the architecture just has to run, therefore having the code is obsolete) I would like to know if there is any way that enables me to do something like saver.restore(sess, "some_checkpoint_file.ckpt") and sess.run(...) without having to copy the whole codebase every time... - daniel451
...but on the long run, yes: it looks like TensorFlow Serving is what I search for, for stable / long term environments. - daniel451
Also, a lightweight solution is freeze_graph, it inlines your variables as constant nodes into graphdef -- github.com/tensorflow/tensorflow/blob/master/tensorflow/python/… - Yaroslav Bulatov

1 Answers

2
votes

If you really need to restore just from the graphdef file (*.pb), to load it from another application for instance, you will need to use the freeze_graph.py script from here: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/freeze_graph.py

This script takes a graphdef (.pb) and a checkpoint (.ckpt) file as input and outputs a graphdef file which contains the weights in the form of constants (you can read the docs on the script for more details).