Convert Keras Model to C++

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



Leave a reply



Submit