I'm relatively new to the topic of QCNNs and I wanted to understand how the number of qubits is selected in the encoded quantum layer. Like is it based on the image we want to encode? What is the maximum image size that we can encode today in a quantum layer?


2 Answers 2


It usually depends on what types of data you're using and how many qubits you want to start your QCNN with. Suppose you want to encode MNIST image data as an input of your QCNN. There are several ways you can do this.

First, you can do amplitude encoding to express pixel values of the images as amplitudes of your input quantum states. Since each image has 28 by 28 = 784 pixels, one reasonable way to use amplitude encode is to downsize the image into fewer number of pixels, so that you can encode into amplitudes of 8 qubits (2^8 = 256) or 9 qubits (2^9 = 512).

Since amplitude encoding is often costy, you might want to pre-process your data classically (e.g. through classical neural networks or PCA) to extract 'features' of your image. Then, you can use those feature vectors as input by perhaps using them as angles of rotation gates that prepare your initial states to QCNN. This is how the paper about hierarchical quantum classifier used (https://www.nature.com/articles/s41534-018-0116-9).

There are many other ways to perform such quantum feature maps, maybe this neat explanation on pennylane website (and papers listed in the link) might help: https://pennylane.ai/qml/glossary/quantum_embedding.html. Also, check out https://github.com/takh04/QCNN for python implementions of QCNN.

  • $\begingroup$ Understood! Thanks for the resources as well @Leeseok Kim $\endgroup$
    – sohamb172
    Commented Feb 25, 2022 at 7:24

For images it depends on which quantum embedding method you choose.

Let's take as an example MNIST dataset, as Leeseok Kim suggested, since it's simple and has small, grayscale images. Let's downsize them further to 14x14 images (196 pixel brightness values). The most common embedding methods will need:

  • Basis embedding: It takes the N values, change to binary representation (of length M) and every value is represented as a state of quantum subsystem of M qubits (N*M qubits needed). For 14x14 image with pixel values as unsigned 8-bit integer it's 196 values encoded into 8 qubits - 1584 qubits.
  • Angle embedding: It takes N pixel values, scale them to range [0, $\pi$] end perform $y-axis$ rotation on system of N qubits sytem (one value encoded into one qubit). In our example it's 196 qubits.
  • Amplitude embedding: It encodes N pixel values into amplitudes of your quantum state. Since for n qubits it's $2^n$ possible states, you need $n\geq log_2(N)$ qubits. For 196 pixel values it's 8 qubits.

For more methods here's nice overview.
If the images has channels (e. g. RBG images) you can perform encoding for every channel separately, or 'flatten' images into the sequence of pixel values.
But basically all encoding decisions are based on these questions:

  • simulation/hardware resources: How much qubits you can simulate/perform operations on and how much time do you have?
  • accurate data representation: How precisely I want to encode images and which method is the best for QCNN models results?

When it comes to maximal size of encoded image today, the biggest resolution for QCNN training I spotted was 28x28 in this paper (encoded into 11-qubit IonQ device). However, way more often you'll find smaller images, like 14 by 14 pixels.

Everything above is for the whole image encoding. However, there are Quantum Convolutional Neural Networks, which needs to encode only small part of an image at once. With this approach, you can pass through the quantum layer image of any size.

  • $\begingroup$ Thanks, @Marek Kowalik $\endgroup$
    – sohamb172
    Commented Mar 20, 2022 at 6:07

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.