Keras-CNTK-v2 save format

I am using CNTK as a backend for Keras. I am trying to use my model that I trained using Keras in C ++.

I trained and saved my model using Keras which is in HDF5. How can I use CNTK API to save it in model-v2 format?

I've tried this:

model = load_model('model2.h5')
cntk.ops.functions.Function.save(model, 'CNTK_model2.pb')

      

but i got the following error:

TypeError: save() missing 1 required positional argument: 'filename'

      

If tensorflow were the backend I would do this:

model = load_model('model2.h5')
sess = K.get_session()
tf_saver = tf.train.Saver()
tf_saver.save(sess=sess, save_path=checkpoint_path)

      

How can I achieve the same?

+3


source to share


3 answers


As per the comments here , I was able to use this:



import cntk as C
import keras.backend as K

keras_model = K.load_model('my_keras_model.h5')

C.combine(keras_model.model.outputs).save('my_cntk_model')
cntk_model = C.load_model('my_cntk_model')

      

+3


source


You can do something like this model.outputs[0].save('CNTK_model2.pb')

I assume you called model.compile (i.e. that's the only case I've tried :-)



0


source


The reason you are seeing this error is because the keras cntk firewall is using a user-defined function to reshape on the packet axis that cannot be serialized. We fixed this issue in CNTK v2.2. Upgrade your cntk to v2.2 and upgrade keras to the latest master. Please see this request: https://github.com/fchollet/keras/pull/7907

0


source







All Articles