Convert Keras model to C
I never tried, but this can be a way to do it. Firstly, convert the Keras model to Tensorflow, with tools like this one or following this tutorial. After this step, you can use your model with the tf C API.
Convert Keras model to C++
To answer my own question and have a solution - I wrote a plain c++ solution called keras2cpp (its code available on github).
In this solution you store network architecture (in json) and weights (in hdf5). Then you can dump a network to a plain text file with provided script. You can use obtained text file with network in pure c++ code. There are no dependencies on python libraries or hdf5. It should work for theano and tensorflow backend.
error in conversion of keras model to tflite
You are trying to use converting method from saved_model
protobuf with keras model. Your method is tf.lite.TFLiteConverter.from_keras_model(model)
:
import tensorflow as tf
from tensorflow import keras
model = keras.models.load_model('path/to/location')
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
with open('model.tflite', 'wb') as f:
f.write(tflite_model)
See details here
Related Topics
Can Class Template Constructors Have a Redundant Template Parameter List in C++20
Differencebetween Packaged_Task and Async
Lambda Capture as Const Reference
Restrict C++ Template Parameter to Subclass
Initialise Eigen::Vector with Std::Vector
The Implementation of Std::Forward
The Intersection of Two Sorted Arrays
What Are Unevaluated Contexts in C++
Why Is a Char and a Bool the Same Size in C++
Efficiency of the Stl Priority_Queue
How Bad Is Redefining/Shadowing a Local Variable
What Is a Void Pointer and What Is a Null Pointer
How to Generate Thread-Safe Uniform Random Numbers