Variational Quantum Neural Networks (VQNNS) in Image Classification
Quantum machine learning has established as an interdisciplinary field to
overcome limitations of classical machine learning and neural networks. This is
a field of research which can prove that quantum computers are able to solve
problems with complex correlations between inputs that can be hard for
classical computers. This suggests that learning models made on quantum
computers may be more powerful for applications, potentially faster computation
and better generalization on less data. The objective of this paper is to
investigate how training of quantum neural network (QNNs) can be done using
quantum optimization algorithms for improving the performance and time
complexity of QNNs. A classical neural network can be partially quantized to
create a hybrid quantum-classical neural network which is used mainly in
classification and image recognition. In this paper, a QNN structure is made
where a variational parameterized circuit is incorporated as an input layer
named as Variational Quantum Neural Network (VQNNs). We encode the cost
function of QNNs onto relative phases of a superposition state in the Hilbert
space of the network parameters. The parameters are tuned with an iterative
quantum approximate optimisation (QAOA) mixer and problem hamiltonians. VQNNs
is experimented with MNIST digit recognition (less complex) and crack image
classification datasets (more complex) which converges the computation in
lesser time than QNN with decent training accuracy.
Meghashrita Das, Tirupati Bolisetti
# Variational Quantum Neural Networks (VQNNs) in Image Classification

###### Abstract

Quantum machine learning has established as an interdisciplinary field to overcome limitations of classical machine learning and neural networks. This is a field of research which can prove that quantum computers are able to solve problems with complex correlations between inputs that can be hard for classical computers. This suggests that learning models made on quantum computers may be more powerful for applications, potentially faster computation and better generalization on less data. The objective of this paper is to investigate how training of quantum neural network (QNNs) can be done using quantum optimization algorithms for improving the performance and time complexity of QNNs. A classical neural network can be partially quantized to create a hybrid quantum-classical neural network which is used mainly in classification and image recognition. In this paper, a QNN structure is made where a variational parameterized circuit is incorporated as an input layer named as Variational Quantum Neural Network (VQNNs). We encode the cost function of QNNs onto relative phases of a superposition state in the Hilbert space of the network parameters. The parameters are tuned with an iterative quantum approximate optimisation (QAOA) mixer and problem hamiltonians. VQNNs is experimented with MNIST digit recognition (less complex) and crack image classification datasets (more complex) which converges the computation in lesser time than QNN with decent training accuracy.

Keywords:Quantum Neural Network Parameterized circuit Image classification Hilbert space Quantum Approximate Optimization

## 1 Introduction

Quantum computation offers potential avenue to increase the power of machine learning, neural networks models which is discussed in this paper with an algorithm. The objective of this research is to find a way to improve performance of QNN by variational approaches[1]. We have used QAOA to train QNNs. Rather than using one qubit parameterized single circuit in input layer of QNN, we have used a 2 qubit parameterized circuit which is having Cost and Mixer Hamiltonians to calculate the cost of the classical QNN. QAOA uses a parameterized quantum circuit \(\big{|}\Psi(\theta)\big{\rangle}\) to generate trial wave functions which is \(\big{|}\Psi(\gamma,\beta)\big{\rangle}\) to
compute or estimate the expectation value of \(\left\langle\Psi(\gamma,\beta)|H|\Psi(\gamma,\beta)\right\rangle\) with respect to the problem Hamiltonian \(H\). Now this variational QNN is applied on image processing applications (Classification and Recognition) which shows that VQNNs can improve time complexity and training accuracy[6].

## 2 Hybrid Quantum Classical Neural Networks

Quantum machine learning (QML) proposes new types of models that leverage quantum computers' unique capabilities to, for example, work in exponentially higher-dimensional feature spaces to improve the accuracy of models. A neural network is an elaborate function that is built by composing smaller building blocks called neurons[8]. A neuron is nonlinear function that maps one or more inputs to a single real number. Graphically, we represent neurons as nodes in a graph and each edge in our graph is associated with a scalar-value called a weight. The idea of QNN is to multiply each neuron by a different scalar before being collected and processed into a single value. The objective when training a neural network consists primarily of choosing our weights which is the building block oh hybrid QNNs[12].

## 3 Variational Quantum Neural Networks (VQNNs)

### Parameterized quantum circuit

A variational quantum circuit is comprised of three components. First, a feature map F which maps classical data point x into a m qubit quantum state \(\left|\Psi\right\rangle\) :

\[\left|\Psi(x)\right\rangle=F(x)\big{|}0\big{\rangle}^{\otimes}m \tag{1}\]

Second, an ansatz which will build the quantum state with entanglements and rotation gates. The rotational angle of ansatz is parameterized by a vector \(\theta\)[9].

\[\big{|}\phi(x,\theta)\big{\rangle}=A(\theta)\big{|}\Psi(x)\big{\rangle} \tag{2}\]

Finally, an observable \(O\) is measured, and the eigenvalue corresponding to the resultant quantum state is recorded[5]. A variational quantum circuit is run repeatedly with an input \(x\) and parameter vector \(\theta\). The circuit's expectation value (f) can be,

\[f(x,\theta)=\big{\langle}\phi\big{(}x,\theta\big{)}|O|\phi\big{(}x,\theta \big{)}\big{\rangle} \tag{3}\]

When a variational quantum circuit is used for machine learning, this approximated expectation value is typically treated as the output of the model.

### Qaoa

QAOA is a hybrid quantum classical variational algorithm. Unlike the gate-based quantum computation model, it is based on adiabatic theorem from quantum
mechanics. In this model, to perform any computation we need two Hamiltonians called \(\mathrm{H_{M}}\) and \(\mathrm{H_{C}}\). Amongst them, the ground state of \(\mathrm{H_{M}}\) should be a preparable state and \(\mathrm{H_{C}}\) encodes the solution to our problem. QAOA is the trial a parameterized state \(|\Psi(\gamma,\beta)\rangle\) (for some values of parameters \(\gamma\), \(\beta\)) that should be prepared on a quantum computer. This state will give an expectation value of \(\left\langle\Psi(\gamma,\beta)|H|\Psi(\gamma,\beta)\right\rangle\) with respect to the problem Hamiltonian \(H\)[10].

### VQNN Algorithm

In this paper, VQNN is proposed where the quantum training process can be described as the state evolution with the Hilbert space of the parameter register and the QNN register[11]. The quantum training protocol acts on both the parameter register (\(\gamma\), \(\beta\)) and QNN register to encode the cost function of QNN which is a variant of the original QAOA Mixers[2]. These operations can be mathematically expressed as \(e^{-i\gamma C\theta}\) and \(e^{-i\beta H_{\mathrm{M}}}\), where \(\theta\) are the parameter vectors of QNN, \(C(\theta\) ) is the cost function of the QNN, and \(\gamma\)i and \(\beta\)i are tunable hyperparameters. By heuristically tuning the hyperparameters, the quantum training can be done in on the optimal parameters of the QNN after iterations of the QAOA ansatz operations[3].

#### 3.3.1 QAOA ansatz

: The QAOA ansatz has two parts, Mixer and Cost Hamiltonian. The Mixer Hamiltonian (\(\mathrm{H_{M}}\)) is choosen as Eq. 4,

\[H_{\mathrm{M}}=\sum_{j=1}^{n}X_{\mathrm{j}} \tag{4}\]

where \(\mathrm{X_{j}}\) is the Pauli X operator acting on the jth qubit. Then the Cost Hamiltonian (\(\mathrm{H_{C}}\)) is formed with rotational Pauli \(z\) gate and cx gates with a rotational angle \(\theta\). Finally a measurement in the computational basis is performed on the state[7]. Repeating the above state preparation and measurement, the expected value of the cost function,

\[\left\langle C\right\rangle=\left\langle(\beta,\gamma)|H_{\mathrm{C}}|(\beta, \gamma)\right\rangle \tag{5}\]

Here the expectation of QAOA ansatz for rotaltional angle as \(\pi/4\) will be -0.124. Fig.1 represents the quantum circuit.

#### 3.3.2 Training with QNN

: A Neural Network with 2 layers of ConvNN and a fully connected layer at the end is used and the value of the last neuron of the fully-connected layer is fed as the parameter \(\theta\) into the above quantum QAOA ansatz circuit[4].

## 4 Experimental Settings

VQNN algorithm is experimented with MNIST digit datasets and crack detection datasets. MNIST image dataset is taken as a simple and relatively less complex
where the performance of VQNN is measured and later it is experimented with a bit complex image recognition dataset to measure its compatibility. MNIST dataset contains 200 images from the training sample which contains hand written 0 and 1 digits. The crack detection kaggle dataset consists of various concrete surfaces labelled either negative if the surface presents no cracks and positive otherwise. Each class has 1,000 images for a total of 2,000 images.

## 5 Results

MNIST and Crack detection datasets are trained with QNN and VQNNs. The results are shown in the below Table 1 which shows that VQNN is taking less time than QNNs for the experiment with detecting surface cracks with an imporoved accuracy. Fig 2, Fig 3, Fig 4 and Fig 5 describe the training convergence for corresponding experiments with QNNs and VQNNs. Fig 6 is the predicted MNIST digits by VQNNs and Fig 7 is the predicted cracks as positive and negative by VQNNs.