1
$\begingroup$

I implemented a hybrid model with Keras and Pennylane that looks like this: enter image description here

The quantum layer is basically a quantum circuit converted to a keras layer with the qml.qnn.KerasLayer() function. Now I am trying to save and export this model so I can run it in other python scripts, so what do I do?

$\endgroup$

1 Answer 1

1
$\begingroup$

The official documentation of Pennylane claimed that we can just use model.save(SAVE_PATH) to save our hybrid model just like any other normal Tensorflow model. However, referring to the question I posted Error loading saved hybrid quantum (pennylane + tensorflow keras) model: Unknown layer: 'KerasLayer', I had trouble loading the model (.h5 or .keras format) that I saved with that model.

I found the alternative method - save the saves with model.save_weights(WEIGHTS_PATH) to save the weights. To load the model, just define a new model with the same model structure, then use model.load_weights(WEIGHTS_PATH) to load the weights from the saved path. This worked perfectly fine.

$\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.