How to train a quantum circuit in a hybrid model

Hi, I implemented successfully the hybrid model of Quanvolution Neural Networks for MNIST classification with the circuit with random parameters. I really don’t know how can I be able to train the parameters if the prediction of the model is done after the classical convolution model that follows the quantum circuit that I want to train.

Hi @Jacopo_Dardini,

Are you referring to this demo?

If that’s the case then it’s important to notice that in the Note in the introduction we specify that the quantum circuit is fixed and non-trainable. Only the classical part is trainable in that example.

I’m not sure whether it would be possible to adapt the demo in such a way that the quantum circuit can be trained, so my recommendation would be to check the paper referenced in the demo to learn more about the choices they made for their approach.

If you do implement an alternative where you train the quantum part feel free to share it here!

thanks for your response. Yes, I am referring to that demo, in which there is written the following note:

“In this tutorial we follow the approach of Ref. [1] in which a fixed non-trainable quantum circuit is used as a “quanvolution” kernel, while the subsequent classical layers are trained for the classification problem of interest. However, by leveraging the ability of PennyLane to evaluate gradients of quantum circuits, the quantum kernel could also be trained.”

I don’t understand how you can optimize the parameters of the quantum circuit in this kind of hybrid model.

Hi @Jacopo_Dardini,

I now understand your question.

I guess you could add a Keras layer to your model as shown in this demo. However you’d have issues with the sizes and dimensions for training. So maybe you would need to combine it with something like this demo on Generalization in QML from few training data. This is probably not going to be an easy task so maybe if you want to focus on the QCNN side of things you can just focus on the demo on Generalization.

I hope this helps!