Hi @yousrabou !
Before I directly answer your questions I strongly recommend that you take a look at the PennyLane Codebook, especially the module on Variational Quantum Algorithms. It can really help you gain important insights.
Now to your questions:
- There’s not a 1-1 comparison between CNNs and QNNs. Actually many people avoid using the term QNN because it can lead to confusion. Variational quantum circuits are mathematically different from CNNs, and they’re simply quantum algorithms that depend on free parameters. In your case I don’t know what hidden_size is or does (your code is very complex).
- If you want to have a classical layer + a quantum circuit + a classical layer you need to make sure that the inputs and outputs of each match. I would strongly suggest that you first get confortable with running small quantum circuits on their own and understanding their inputs and outputs before trying to create a hybrid program. The foundations of quantum computing learning path of the Codebook can help you a lot here.
- Most gates can handle batching without you needing to do anything, but it’s very common that people send an input with the wrong size to a quantum circuit, which leads to receiving an error. Eg. if you have a gate that receives an input of size 1 but you send an input of size 2x4 it doesn’t know what to do. If you send an input of size 1x4 it knows how to handle it. That being said, my recommendation once again would be to keep things as simple as possible at first.
Additional notes:
Variational quantum circuits will most likely make your algorithms Worse. They will be slow, and they may not increase accuracy at all. Take a look at this blog post and this paper to learn more about comparisons between classical and quantum models, and you’ll see that at the moment the general conclusion is that classical models are better most of the time. This is not to mean that they will always be worse, there’s still a lot of research in this field to understand why or how it could work better, but so far we’re still looking for the right application/data/problem.
I hope this helps you and sorry that my answers were a bit general but I hope they point you in the right direction.