1
$\begingroup$

I need to convert Keras model to C++ code. I found some implementations to do this: keras2cpp, another keras2cpp and frugalydeep. Only the third one was able to convert my model to cpp code. But the frugalydeep has no support for GPU. Therefore I am looking for another option to make this. My thoughts are to save Keras model to .pb(protobuf) file and then load this model with Tensorflow C API.

Do you think this will be possible? Or I will have to manually rewrite the Keras model to Tensorflow C API.

Are there any other ways to do this task?

$\endgroup$

1 Answer 1

1
$\begingroup$

My thoughts are to save Keras model to .pb(protobuf) file and then load this model with Tensorflow C API.

Do you think this will be possible?

the answer is yes, absolutely. there are many ways to do this and i'll list some here so that you can pick up what suites your needs.

  • you can use cppflow, which is a c++ wrapper for the tensorflow C API, and actually makes it way easier to do the job than using the C API directly. they also have some examples on how to use it and in fact i think that this is the best solution out there.
  • you can see this wonderful repo hello_tf_c_api, especially this example.

or you can follow these articles on medium if you wish to use the c API directly:

there's also these two wonderful github gists that would walk you through how to do this exactly (although i recommend the c approach because it's more straightforward):

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.