Quantum Convolutional Neural Network for Image Classification using Tensorflow

Imam Muhajir
Analytics Vidhya
Published in
7 min readOct 4, 2021

Implementation Quantum in Neural Network

Photo by Adi Goldstein on Unsplash

INTRODUCTION

Quantum computing has the potential to outperform classical computers and is expected to play an active role in various fields, in quantum machine learning, quantum computing has been found to be useful for enhanced feature representation and state approximation (Watabe et al. 2021). Quantum computing based on quantum bits (qubits) is inspired by the phenomenon of particles in quantum states. This phenomenon is a superposition phenomenon where a particle in a quantum state can have two states at once (Gultom 2017). The approach to this phenomenon is transformed into computations in 6the form of qubits, namely 0.1 or both (Kaye 2007).

MAIN COMPONENT

QUBIT

Quantum computing uses qubits as the basic unit of information, which is represented by a state vector (Gado and Younes, 2021). Dirac notation is one of the notations used in quantum mechanics which was discovered by Paul Dirac. In Dirac notation the symbol that identifies a vector is written as:

Furthermore, these notations will be operated using quantum logic gates. A qubit is the basic unit of quantum information, a quantum bit: a two-level system that can exist in a superposition of those two possible states.

GATES AND OPERATIONS

Quantum gates are unitary operators and are described as unitary matrices relative to some basis. In quantum computing and specifically the quantum circuit model of computation, a quantum logic gate (or simply quantum gate) is a basic quantum circuit operating on a small number of qubits. They are the building blocks of quantum circuits like classical logic gates are for conventional digital circuits. A Gate is an effect that can be applied to a collection of qubits (objects with a Qid). Gates can be applied to qubits by calling theirs on method, or, alternatively calling the gate on the qubits. The object created by such calls is an Operation.

Gates versus operations

The above example shows the first half of a quantum teleportation circuit, found in many quantum computation textbooks. This example uses three different gates: a Hadamard (H), controlled-Not (CNOT), and measurement. These are represented in cirq by cirq.H, cirq.CNOT, and cirq.measure, respectively.
Quantum computing has its own logic gate, namely a quantum logic gate (quantum gate). There are several quantum logic gates, which are as follows:

CIRCUIT

A Circuit is a collection of Moments. A Moment is a collection of Operations that all activities during the same abstract time slice. An Operation is some effect that operates on a specific subset of Qubits, the most common type of Operation is a GateOperation.

ARCHITECTURE CNN VS QCNN

Convolutional Neural Network (CNN) is a deep learning method used to process image data. In the process, CCN has several main layers, namely the Convolution layer, Subsampling Layer, and fully connected layer.

Quantum Convolutional Neural Network (QCNN) is a development of CNN based on quantum computing. QCNN extends the main features and structures of CNNs into quantum systems (Oh et al. 2020).

BUILD QUANTUM CONVOLUTIONAL NEURAL NETWORK

INSTALL LIBRARY

For the manufacture of a quantum convolution neural network, it is recommended to use google collab or Kaggle notebook, because both environments already support the TensorFlow-Quantum package.

import package

INPUT DATA MNIST

The data that will be used is the MNIST database (Modified National Institute of Standards and Technology database).

MNIST DATABASE

The MNIST data that will be used is only two-digit numbers 3 and 6.

example data:

In the process of implementing QCNN with large data, it still requires a large enough resource, therefore for this tutorial, we will resize data to 4 x 4 pixels, and remove contradicting data.

the next process is the binning process on pixel data with a limit value of 0.5, where a pixel value of more or equal to 0.5 will have a value of 1, and a pixel value of less than 0.5 will have a value of 0. One example of the transformation process above are as follows:

The next stage is to prepare the cluster state as a data processing environment because the data used is 4 x 4 pixels, therefore it takes a cluster state with a total of 16 qubits, the cluster states are as follows:

The next process is to transform the data into a data circuit. In this transformation, the Pauli-x gate is added for data with a value of one, and for data with a value of zero, no Pauli-x gate is added.

One example of the transformation above is as follows:

BUILD ARSITEKTUR

The making of the Quantum Convolutional Neural Network Architecture has several stages, namely the manufacture of Quantum Circuits, the construction of the Quantum Layer, and the construction of the Quantum Convolutional Neural Network Architecture.

Quantum Circuit

At the stage of forming a quantum circuit, three main quantum circuits are needed, namely one cubit unitary circuit, two-qubit unitary circuit, and two-qubit pooling circuit, in which the quantum circuit is as follows:

One Cubit Unitary Circuit
Two-qubit Unitary Circuit
Two-qubit Pooling Circuit

The circuit is a component to build a quantum layer architecture. In the next stage of development of the quantum layer.

Quantum Layer

The construction of a quantum layer where there are three layers needed to build a Quantum Convolutional Neural Network Architecture, namely quantum convolution layer, quantum pooling layer, and quantum neural network layer, the layers are as follows:

Quantum Convolution Layer
Quantum Pooling Layer
Quantum Neural Network Layer

The quantum convolution layer consists of seven unitary two-qubit circuits and four one-qubit unitary circuits with an additional six quantum gates. The quantum pooling layer consists of four two-qubit pooling circuits and three one-qubit unitary circuits. Furthermore, the quantum neural network layer consists of an array of Pauli-x gates and Pauli-z gates. After the formation of the quantum layer, the next step is to arrange the quantum layer into a Quantum Convolutional Neural Network Architecture.

Build Become QCNN Architecture

This Quantum Convolutional Neural Network architecture consists of a quantum convolution layer with 16 qubit data input, a quantum pooling layer with 16 qubit data input, and a quantum neural network layer with 8 qubit data input.

Training Model

for this tutorial, we will try simple modeling that doesn’t take much time, with 5 epochs and using 500 data samples. If interested you can try it directly with the different parameters and how they change.

The results of the modeling show quite good results, with the latest validation accuracy of 83.33.

This QCNN modeling still has many shortcomings and weaknesses, especially from the availability of the quantum computing environment that is not widely available, and we create the quantum environment in a classical computer, this is what causes quantum processing on a classical computer to be relatively long. I hope this paper can help readers with further research, and the development of quantum computing. I know there are still many mistakes in my writing, I hope to get feedback and suggestions.

Thank you very much for reading this article.

References:

  • https://www.tensorflow.org/quantum
  • https://quantumai.google/cirq
  • https://en.wikipedia.org/wiki/Quantum_logic_gate
  • Watabe M, Shiba K, Chen C, Sogabe M, Sakamoto K , Sogabe T. 2021. Quantum circuit learning with error backpropagation algorithm and experimental implementation. Journal Quantum Rep. 3(2):333–349. doi.org/10.3390/quantum3020021.
  • Gultom. 2017. Klasifikasi data dengan quantum perceptron. Jurnal Teknovasi. 4(1):1–9.
  • Kaye P, Laflamme R, Mosca M. 2007. An Introduction to Quantum Computing. New York: Oxford University Press.
  • Gado M , Younes A. 2021. Optimization of reversible curcuit using toffoli decompositions with negative controls. Jurnal Symmetry . 13(6): 1025. doi.org/10.3390/sym13061025.
  • Oh S, Choi J, Kim J.2020.A tutorial on quantum Convolutional neural network (QCNN).,forthcoming.

--

--

Imam Muhajir
Analytics Vidhya

Data Scientist at KECILIN.ID || Physicist ||Writer about Data Analysis, Big Data, Machine Learning, and AI. Linkedln: https://www.linkedin.com/in/imammuhajir92/