Training with keras+tensorflow in python and predict in C/C++


It is possible to make a fast model with keras with tensor flow as backend and use it to predict in C or C++?

I need to do the prediction inside of a C++ program, but I feel much more comfortable doing the model and the training in keras.


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:

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.

It not only supports prediction with sequential models but also with more complex models build with the functional API.

Additionally to supporting many common layer types it can keep up with (and sometimes even beat) the performance of TensorFlow on a single CPU. You can find up-to-date benchmark results for some common model in the repo.

By automatic testing frugally-deep guarantees that the output of a model used with it in C++ is exactly the same as if run with Keras in Python.

Answered By – Tobias Hermann

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published