Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save a Keras model in the CNTK format

Tags:

keras

cntk

Is there a way to save a Keras model to the format of CNTK so that we can load it by using CNTK's API?

I have tried this code below but it failed:

a = Input(shape=(224,224,3))
b = Conv2D(64, (2,2), name='conv1')(a)
model = Model(inputs=a, outputs=b)
cntk.combine(model.outputs).save('model2.dnn')
like image 734
logen Avatar asked Oct 17 '22 09:10

logen


1 Answers

Please see Keras-CNTK saving model-v2 format

To save Keras model in CNTK format (when using CNTK as back end):

import cntk as C
from keras.backend import load_model

keras_model = load_model('my_keras_model.h5')

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

To save Keras in TensorFlow format (when using TensorFlow as backend):

model = load_model('model2.h5')
sess = K.get_session()
tf_saver = tf.train.Saver()
tf_saver.save(sess=sess, save_path=checkpoint_path)
like image 61
Augustine Ng Avatar answered Oct 21 '22 05:10

Augustine Ng