Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Keras model to TensorFlow protobuf

Tags:

We're currently training various neural networks using Keras, which is ideal because it has a nice interface and is relatively easy to use, but we'd like to be able to apply them in our production environment.

Unfortunately the production environment is C++, so our plan is to:

  • Use the TensorFlow backend to save the model to a protobuf
  • Link our production code to TensorFlow, and then load in the protobuf

Unfortunately I don't know how to access the TensorFlow saving utilities from Keras, which normally saves to HDF5 and JSON. How do I save to protobuf?

like image 553
Shep Avatar asked Apr 04 '16 20:04

Shep


People also ask

What is protobuf in TensorFlow?

The protobuf tools parse this text file, and generate the code to load, store, and manipulate graph definitions. If you see a standalone TensorFlow file representing a model, it's likely to contain a serialized version of one of these GraphDef objects saved out by the protobuf code.

What is .PB file in TensorFlow?

The . pb format is the protocol buffer (protobuf) format, and in Tensorflow, this format is used to hold models. Protobufs are a general way to store data by Google that is much nicer to transport, as it compacts the data more efficiently and enforces a structure to the data.


1 Answers

In case you don't need to utilize a GPU in the environment you are deploying to, you could also use my library, called frugally-deep. It is available on GitHub and published under the MIT License: https://github.com/Dobiasd/frugally-deep

frugally-deep allows running forward passes on already-trained Keras models directly in C++ without the need to link against TensorFlow or any other backend.

like image 168
Tobias Hermann Avatar answered Oct 07 '22 02:10

Tobias Hermann