Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting trained Tensorflow model to protobuf

The inception net in the Android Tensorflow Demo stores the model as a protobuf file (tensorflow_inception_graph.pb). I'd like to replace this network with another one.

Is there documentation or an example somewhere on how to convert a trained TensorFlow network in Python to .pb? I'm aware of TensorFlow's Saver but this seems to be used to save intermediate training state. Not sure how it works if the model is already trained.

like image 976
Zach Rattner Avatar asked Feb 06 '16 22:02

Zach Rattner


People also ask

What is TensorFlow Protobuf?

TensorFlow protocol buffer. Since protocol buffers use a structured format when storing data, they can be represented with Python classes. In TensorFlow, the tf. train. Example class represents the protocol buffer used to store data for the input pipeline.

What is StatefulPartitionedCall?

StatefulPartitionedCall is an op that does a simple function call in TF. Our converter doesn't normally have to deal with it since the optimizer we run before conversion automatically inlines most function calls.


2 Answers

Here's an example of saving and loading

like image 168
Yaroslav Bulatov Avatar answered Oct 12 '22 23:10

Yaroslav Bulatov


tf.Graph.as_graph_def() retrieves the serialized graph. Then you just write it to a file.

like image 34
Jay Alammar Avatar answered Oct 12 '22 23:10

Jay Alammar