Handwritten Numeric Image Classification with Quantum Neural Network using Quantum Computer Circuit Simulator

Abstract—Quantum Computer is a computer machine using principles of quantum mechanics in doing its computation. The Quantum Computer Machine itself is still in the development stage and has not been deployed yet, however TensorFlow provides a library for hybrid quantum-classical machine learning called TensorFlow Quantum (TFQ). One of the quantum computing models is the Quantum Neural Network (QNN). QNN is adapted from classical neural networks capable of processing qubit data and passing quantum circuits. QNN is a machine learning model that allows quantum computers to classify image data. The image data used is classical data, but classical data cannot reach a superposition state. So in order to carry out this protocol, the data must be readable into a quantum device that provides superposition. QNN uses a supervised learning method to predict image data. Quantum Neural Network (QNN) with a supervised learning method for classifying handwritten numeric image data is implemented using a quantum computer circuit simulation using the Python 3.6 programming language. The quantum computer circuit simulation is designed using library Cirq and TFQ. The classification process is carried out on Google Colab. The results of training on the QNN model obtained a value of 0.337 for the loss value and 0.3427 for the validation loss value. Meanwhile, the hinge accuracy value from the training results is 0.8603 for the hinge accuracy value with training data and 0.8669 for the hinge accuracy validation value. Model testing is done by providing 100 handwritten number images that are tested, with 53 image data of number three and 47 image data of number six. The results obtained for the percentage of testing accuracy are 100% for the number three image and 100% for the number six image. Thus, the total percentage of testing is 100%.


I. INTRODUCTION
Quantum Computer is a computer machine which uses quantum mechanics for doing its computation [10], [11]. The intensity of the most sophisticated computer now days, has not been satisfied human to possess a super speedy computer. It is not impossible; in the future the most sophisticated super computer will be left by many companies and replaced by quantum computer [10]. Quantum computer machine itself is still in developing phase and has not been spread, but TensorFlow supplies library to hybrid quantum-classical machine learning which is called TensorFlow Quantum (TFQ). One model of quantum computing is quantum neural network (QNN). QNN is adapted from classical neural network which is able to proceed qubit data and surpass quantum circuit. Qubit is a measurement unit data in quantum computer [1], [2], [3], [4], [5], [6].
QNN is a machine learning model that allows quantum computers to classify image data. The image data used is classical data, but classical data cannot reach a superposition state. So in order to carry out this protocol, the data must be readable into a quantum device that provides superposition. QNN uses a supervised learning method to predict image data [7], [9]. Supervised learning is an approach where trained data is already available, and consists of variable which is targeted [8].
Based on the background above, the following problems are formulated: How to implement the supervised learning method to classify handwritten numeric image data in the Quantum Neural Network (QNN) model in order to achieve a superposition state?
The paper focuses on implementing the quantum neural network (QNN) by using supervised learning method in order to classify numeric handwritten data image. QNN is modelled by using computer quantum simulator circuit which is designed by making use of python-based library Cirq and TFQ. Furthermore, the implementation of the classification process is carried out on Google Colab.
The limitations of the problem in this paper are: 1) Handwritten image data obtained from MNIST (Modified National Institute Of Standards and Technology) [12].
2) Handwritten image data used are handwritten images of number 3 and handwritten images of number 6 with 11,520 training data and 1,968 testing data.
3) The size of the handwritten image data used is 28x28 pixels which are converted to 4x4 pixels.
4) The resulting output is a Boolean number where the value 1.0 or true represents the number 3 and the value -1.0 or false represents the number 6.
7) The learning method used is a supervised learning method.
In the rest of paper, we show the research methodology in Section II. In Section III, the implementation and testing of model is presented. The last section is conclusion of our research.

II. RESEARCH METHODOLOGY
The research method in this research is shown in the following Fig. 1.

A. Collecting and Processing of Classical Data Image
Data that is used to train model consist of classical image data. Those data are divided into 60.000 train data and 10.000 validity data. Classic image data is used constitute data which is obtained from MNIST database (Modified National Institute of Standards and Technology database).

B. Preprocessing Data
Pre-processing data image is done by the following steps:

1) Filtering datasets:
In MNIST datasets consist of ten labels in various images of handwritten number. At the time of writing, quantum computation could only identify Boolean values, so the dataset needed to be filtered so that it could be operated on quantum circuits. The data used comes from dataset 3 and dataset 6, where dataset 3 contains data handwritten image number three and dataset 6 contains data handwritten image number six.
The filter-function is as in the following Fig. 2 Furthermore, the training data and test data are filtered, and at the same time labey y is converted into Boolean numbers, i.e. "true" value for number three and "false" value for number six. This process reduced the number of training data to 12,049 and test data to 1,968.

2) Downscaling/Resizing classic image data:
The classic MNIST image data is 28x28 pixels. This size is too large for the quantum computations running on conventional computers at this time. The image will be resized to 4x4 pixels so that it can be fed into the quantum circuit.
Image training data used during training is image data that has gone through the downscaling stage. Below are the before and after downscaling images, as seen respectively in Fig. 3 and Fig. 4.
3) Filtering contradictive image: Contradictory images are images labeled 3 and 6. This is done to reduce data barriers which will reduce accuracy when conducting training data on the model to be created. Fig. 5 shows the steps of filtering the contradictive image.
Classical class 3 and class 6 image dataset will be filtered, contradictory images will be deleted and non-contradictory images will be saved. Unique handwritten image data will be saved while image data that is more than one and classified into two (contradictory) labels will be deleted. This process reduced the number of training data to 11,520. 4) Convert classic image data to quantum data: Image processing using quantum computers requires quantum data in qubits. An image is made up of pixels, each pixel in the classic image data representing one qubit of data, with a state that depends on its pixel value. The first step is to convert the classic image data to binary coding (see Fig. 6).
Classical image data that has gone through the binary coding process will be converted into quantum data using the Cirq library (see Fig. 7).
After the classical image data becomes quantum data using circuits from Cirq, the circuits are converted to tensors (see Fig. 8).

C. Setting up Model
The quantum neural network (QNN) model that is built will be used to recognize images. This model uses two qubit gates, with continuously readout qubit. Thus, this model use layered approach; each layer will pass through the same gate. Each qubit data plays a role in the qubit readout.
The script above in Fig. 9 is a readout preparation for creating a gate layer, then entering it into the circuit in Fig. 10, as well as preparing for building a quantum model.  (IJACSA) International Journal of Advanced Computer Science and Applications, Vol. 11, No. 10, 2020 313 | P a g e www.ijacsa.thesai.org Data entered through gate XX, each qubit data will become one qubit that is read. The image used is 4x4 pixels in size. Each qubit in its pixel will be read to predict the image. After the XX gate circuit is built, next build a two layer model equal to the circuit size and enter the readout preparation that was made previously. The process of building the two layer moden is shown in Fig. 11.
The model is wrapped into the tfq-keras Model. Here, the Keras model is built with quantum components. This model uses quantum data by using the Parameterized Quantum Circuits (PQC) layer for training circuit models on quantum data [7].
Range readout from layer PQC is [ -1, 1], thus, optimum hinge loss is required. Re-adjust is required. The data type label y_train_nocon which is initially Boolean will be converted to a matrix [ -1, 1], according to the hinge loss. Threshold 0.0 is used to change data type when the output emerges, data type will return to be Boolean. Thus the output which comes out there is -1.0 for false value and 1.0 for true value.
Describing training procedures to the model is carried out using the compile method. Image data originating from conventional computers will enter through the PQC layer, then the image data will be quantum processed and the processed data will be sent again to a conventional computer to display the output.

D. Training Model with the Data Train
Model is trained by using trained image data and the output to be validated.

E. Testing
Classic image data handwritten which was trained will be tested by image. The output in the form of Boolean number where value of 1.0 or true represents number 3 and value of -1.0 or false represents number 6.
III. IMPLEMENTATION AND TESTING Testing of the model is performed using image test data. The testing is recorded by observing the results of the QNN testing process which is processed using the supervised learning method to predict classical handwritten image data. Fig. 13 shows a graph of the loss value from the results of the training that has been performed. The level of learning in the model built is 0.3370 for the loss value with training data and 0.3427 for the validation loss value.

A. Results of Model Training
Meanwhile, the hinge accuracy value from the training results is 0.8603 for the accuracy value on the training data and 0.8669 for the validation hinge accuracy value. The graph of the training accuracy and validation accuracy values can be seen in Fig. 14.

B. Results of Model Testing
Testing is performed by providing several images; the model will predict the answer. Image number 3 will be represented as true with an answer output of 1.0 and image number six 6 will be represented as false with an answer output of -1.0. The model will be tested with 100 handwritten numeric images. The test results of the test data can be seen in the Table I. Based on the data from the results of the tests that have been carried out, the accuracy percentage can be obtained with the following calculations:

Accuracy Percentage=
The Quantity of True Testing Data The Quantity of Testing Data ×100% (IJACSA) International Journal of Advanced Computer Science and Applications, Vol. 11, No. 10, 2020 314 | P a g e www.ijacsa.thesai.org  The testing with 53 image data of number three represented by a value of 1.0 or true, the percentage of accuracy is obtained as follows: Accuracy Percentage= 53 53 ×100% Accuracy Percentage=100% The testing with 47 image data of number six represented by a value -1.0 or false, the percentage of accuracy is obtained as follows: Accuracy Percentage = 47 47 ×100% Accuracy Percentage=100%

C. Summary of Test Results
From the results of tests that have been carried out using 100 handwritten numeric image data with the Quantum Neural Network (QNN) model, it shows that the accuracy results for each image type and the overall accuracy results are in the following Table II:   TABLE II. SUMMARY OF TEST RESULT

Type of Images Last Percentage
Image of number three 100% Image of number six 100% Total 100%

IV. CONCLUSION
The implementation of the supervised learning method to classify handwritten numeric image data on the Quantum Neural Network (QNN) model in order to achieve a superposition state has been successful and the data can be read on a quantum computer circuit simulator.
The results of training on the QNN model obtained a value of 0.337 for the loss value and 0.3427 for the validation loss value. Meanwhile, the hinge accuracy value from the training results is 0.8603 for the hinge accuracy value with training data and 0.8669 for the hinge accuracy validation value.
Model testing is done by providing 100 handwritten numeric images that are tested, with 53 image data of number three and 47 image data of number six. The results obtained for the percentage of testing accuracy are 100% for the number three image and 100% for the number six image. Thus, the total percentage of testing is 100%. Based on the results of the total accuracy, the overall performance of the model is maximized.