Handwritten numeral recognition method based on quantum neural network, product, medium and equipment
The quantum neural network is constructed through quantum optimization algorithms and cross-entropy loss functions. Using quantum superposition characteristics and parallel computing characteristics, the problems of large quantum neural network storage resources and low computing efficiency in the existing technology are solved, and the efficiency of handwritten numbers is improved. Accuracy.
Patent Information
- Application Number
- CN202411041548.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2024-12-13
- Estimated Expiration
- 2044-07-31
AI Technical Summary
The existing quantum neural network model fails to fully utilize the quantum superposition characteristics and parallel computing characteristics, resulting in a large amount of storage resources and low computing efficiency, and thus low recognition efficiency and accuracy when recognizing handwritten numbers.
Through quantum optimization algorithms and cross-entropy loss function, a quantum neural network is built, and the image data is converted into quantum image information qubit sequences using multi-qubit controllable Ry gates, a weighted quantum bit sequence is generated, and nonlinear through quantum layer and activation layer Mapping, and finally output handwritten numeric recognition results.
Effectively reduce storage resources, improve the computing and training speed of quantum neural networks, and improve the efficiency and accuracy of handwritten digit recognition.
Smart Images

Figure CN119131812A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of quantum computing technology, and in particular to a method, product, medium and device for handwritten digit recognition based on quantum neural network. Background Art
[0002] At present, the recognition of human handwriting is still a hot topic in research. Handwriting recognition technology has been widely used in tax form processing, mail classification and computer marking. Among them, the recognition technology of handwritten numbers is widely used in bank check information, envelope postal code information, customs and other scenarios. In these applications, handwritten number recognition algorithms are usually required to have high recognition speed and recognition accuracy as well as high reliability and stability. Although there are only ten categories of handwritten numbers and the strokes are simple, there are still great difficulties in their recognition. Quantum neural networks are used in the prior art to realize the recognition of handwritten numbers.
[0003] Quantum neural network is a hot subject that is the intersection of traditional computer science and quantum information science. Combining the basic principles of artificial neural networks with the quantum computing paradigm can solve the bottleneck problems that hinder the development of both fields. It also shows broad application prospects in the fields of function approximation and big data processing. Artificial neural networks are parallel distributed information processors composed of neurons. They can identify patterns and relationships by learning large amounts of data to solve various complex tasks. With the development of quantum computing, quantum neural networks provide new possibilities for solving problems that classical computers cannot solve. However, despite the widespread attention paid to quantum neural networks, there is little practice on their basic quantum neuron computing mechanism.
[0004] By combining neural networks with the unique properties of quantum computing and utilizing quantum properties such as quantum entanglement, interference, and superposition, some scholars have proposed a systematic quantum neural network implementation method that can process binary strings of arbitrary length. However, due to the limited input quantum bit scale of quantum simulators, quantum neural networks are still insufficient in reflecting basic neuron computing mechanisms. Compared with the classical version, quantum neural networks have exponentially growing memory capacity, faster learning capabilities, and higher stability and reliability. Although a variety of quantum neural network models have been developed and important progress has been made in the fields of quantum communication, quantum encryption algorithms, quantum image processing, and quantum artificial intelligence, existing quantum neural network models have adopted more quantum-classical hybrid frameworks, and their normal operation often depends on traditional algorithms or computing models, and even the traditional computing part of the network contributes more to the final output of the entire quantum neural network.
[0005] Most quantum neural network models can also be called quantum-inspired neural networks, but they cannot run on quantum computers. Instead, they are classical neural networks inspired by quantum principles and with some quantum algorithms or quantum computing units added. In addition, most existing quantum neural network models use a single quantum bit to independently encode pixels to quantize image data, that is, the number of pixels in the image will be the same as the number of quantum bits input to the quantum neural network. Therefore, it fails to fully utilize the quantum superposition characteristics, resulting in more stringent requirements on the storage capacity of quantum registers, and seriously weakens the acceleration characteristics of quantum parallel computing on quantum algorithms.
[0006] In summary, the existing quantum neural network models cannot fully utilize the advantages of quantum superposition characteristics and parallel algorithms, so the quantum neural network models still have problems with large storage resources and low computing efficiency. Therefore, when using quantum neural network models to recognize handwritten numbers, there are problems with low recognition efficiency and accuracy. Summary of the invention
[0007] The purpose of this application is to provide a handwritten digit recognition method, product, medium and equipment based on quantum neural network, which can make full use of the quantum superposition characteristics and parallel computing characteristics of quantum neural network, so as to effectively improve the efficiency and accuracy of handwritten digit recognition.
[0008] To achieve the above objectives, this application provides the following solutions:
[0009] In a first aspect, the present application provides a method for handwritten digit recognition based on quantum neural network, comprising:
[0010] Get image data of handwritten digits;
[0011] The image data is input into a quantum neural network, and the handwritten digit recognition result is output; the quantum neural network is determined by a quantum optimization algorithm and with the purpose of minimizing the cross entropy loss function; the quantum neural network comprises an input layer, a quantum layer, an activation layer and an output layer connected in sequence; the input layer is provided with a multi-qubit controlled Ry gate; the input layer is used to convert the image data into a quantum image to obtain an image information qubit sequence;
[0012] The quantum layer is used for:
[0013] Obtaining a weighted quantum bit sequence according to the image information quantum bit sequence;
[0014] Obtaining output information data based on the image information quantum bit sequence and the weight quantum bit sequence;
[0015] The activation layer is used to perform nonlinear mapping on the output information data and then input it into the output layer; the output layer is used to output the handwritten digit recognition result.
[0016] In a second aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the handwritten digit recognition method based on quantum neural network.
[0017] In a third aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the handwritten digit recognition method based on quantum neural network.
[0018] In a fourth aspect, the present application provides a computer device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the handwritten digit recognition method based on quantum neural network.
[0019] According to the specific embodiments provided in this application, this application discloses the following technical effects:
[0020] The present application provides a method, product, medium and device for handwritten digit recognition based on quantum neural network. First, a quantum neural network is determined by a quantum optimization algorithm with the purpose of minimizing the cross entropy loss function. The quantum neural network can make full use of the quantum superposition property to reduce storage resources, and can also use the characteristics of quantum parallel computing to improve the calculation and training speed of the quantum neural network. Subsequently, the image data of the handwritten digit is obtained and the image data is input into the quantum neural network to obtain the handwritten digit recognition result, thereby effectively improving the efficiency and accuracy of handwritten digit recognition. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0022] Figure 1 An application environment diagram of the handwritten digit recognition method based on quantum neural network provided in this application;
[0023] Figure 2 A schematic diagram of the process of handwritten digit recognition method based on quantum neural network provided in this application;
[0024] Figure 3 A schematic diagram of the process of constructing a quantum neural network provided for this application;
[0025] Figure 4 Schematic diagram of the handwritten digit training set samples provided for this application;
[0026] Figure 5 A circuit diagram of the image information quantum bit sequence provided in this application;
[0027] Figure 6 A circuit diagram of the weighted quantum bit sequence provided in this application;
[0028] Figure 7 A circuit diagram of the switching test technology provided for this application;
[0029] Figure 8 Auxiliary structural diagram of the output state of the quantum layer neuron provided in this application;
[0030] Fig. 9 A schematic diagram of the circuit of the activation layer provided for this application;
[0031] Fig.10 A schematic diagram of the global circuit of a quantum neural network provided for this application;
[0032] Fig.11 A comparison chart of the simulation experiment provided in this application and the experimental results of the classical neural network;
[0033] Fig.12 This is a diagram of the classification results of the simulation experiment provided for this application. DETAILED DESCRIPTION
[0034] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0035] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0036] The handwritten digit recognition method based on quantum neural network provided in the embodiment of the present application can be applied to Figure 1In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be set up separately, or it can be integrated on the server 104, or it can be placed on the cloud or other servers. The terminal 102 can send the image data to be processed to the server 104. After the server 104 receives the image data to be processed, the server 104 inputs the image data to be processed into the constructed quantum neural network. The server 104 can feedback the obtained handwritten digit recognition result for the image data to the terminal 102. In addition, in some embodiments, the handwritten digit recognition method based on the quantum neural network can also be implemented separately by the server 104 or the terminal 102, such as the terminal 102 can directly input the image data to be processed into the quantum neural network, or the server 104 can obtain the image data to be processed from the data storage system and input it into the quantum neural network.
[0037] The terminal 102 may be, but is not limited to, various desktop computers, laptop computers, smart phones, tablet computers, IoT devices, and portable wearable devices. The IoT devices may be smart speakers, smart TVs, smart air conditioners, smart vehicle-mounted devices, etc. The portable wearable devices may be smart watches, smart bracelets, head-mounted devices, etc. The server 104 may be implemented as an independent server or a server cluster consisting of multiple servers, or may be a cloud server.
[0038] In an exemplary embodiment, Figure 2 As shown, a method for handwritten digit recognition based on quantum neural network is provided. The method is executed by a computer device, and can be executed by a computer device such as a terminal or a server alone, or by a terminal and a server together. In the embodiment of the present application, the method is applied to Figure 1 The server 104 in the example is used as an example to illustrate, including the following steps 1 to 2. Among them:
[0039] Step 1: Get the image data of handwritten digits.
[0040] Step 2: Input the image data into the quantum neural network and output the handwritten digit recognition result.
[0041] Among them, the quantum neural network of the present application is determined by a quantum optimization algorithm with the purpose of minimizing the cross entropy loss function; the quantum neural network includes an input layer, a quantum layer, an activation layer and an output layer connected in sequence; the input layer is provided with a multi-qubit controlled Ry gate; the input layer is used to convert image data into a quantum image to obtain an image information quantum bit sequence.
[0042] The quantum layer is used to obtain a weight quantum bit sequence according to the image information quantum bit sequence. The output information data is obtained based on the image information quantum bit sequence and the weight quantum bit sequence. The activation layer is used to perform nonlinear mapping on the output information data and then input it into the output layer; the output layer is used to output the handwritten digit recognition result.
[0043] The handwritten digit recognition method based on quantum neural network in this application focuses on using the exchange test to map the inner product of the constructed image information quantum bit sequence and the weight quantum bit sequence to the result quantum bit, so as to construct the neurons of the initial quantum neural network, and then perform image binary classification on the data with 0 / 1 labels in the MNIST data set. By optimizing the weight parameters in the initial quantum neural network multiple times, the final quantum neural network is constructed and the image data of handwritten digits is classified to obtain the optimal classification result of handwritten digits, such as Figure 3 As shown, the details are as follows:
[0044] First, an initial training set of handwritten digits is obtained and preprocessed to obtain a handwritten digit training set.
[0045] Specifically, a dataset with 0 / 1 labels is randomly selected from the MNIST dataset and divided into an initial training set and a test set, each of which has 2000 images. The image data in the randomly selected dataset is a grayscale image, each with a size of 28×28 pixels. The image sizes are adjusted to 2×2, 4×4, 8×8, and 16×16, respectively, and are generally represented by N×N, such as Figure 4 Extract the information of each pixel in each picture. Since the image data are all grayscale images, each pixel has only one image information. Then use θ=π / 2-arctan(inputs), where inputs is the input pixel value, to convert the input i-th pixel value into the corresponding angle value θ. i , i=(1,2,…,N×N), and control its range within [0,π / 2] to obtain the handwritten digit training set.
[0046] Then, a quantum neural network is constructed, which specifically includes the following steps: (1) constructing an initial quantum state in the initial quantum neural network; (2) initializing the weight quantum bit state of the initial quantum layer in the initial quantum neural network; (3) constructing neurons in the initial quantum neural network based on steps (1) and (2) using the exchange test technology; (4) constructing the activation layer part of the initial quantum neural network; (5) training the initial quantum neural network; (6) updating the weight parameters of the initial quantum neural network; (7) constructing the quantum neural network.
[0047] (1) Constructing the initial quantum state in the initial quantum neural network
[0048] The classical image (image data in the handwritten digit training set) is converted into a quantum image as the input of the initial quantum neural network, including several quantum bits with an initial state of |0>. The input layer of the initial quantum neural network consists of two types of quantum bits, one is a quantum bit used to store the corresponding position information sequence of the image pixel points, and the other is a quantum bit that stores the grayscale information of the image pixel points.
[0049] 1. According to the image size of the image data in the handwritten digit training set, the number of reusable control bit quantum bits is determined to be C, and a Hadamard gate is added to put it in a superposition state.
[0050] 2. According to the number of neurons in the initial quantum layer M, the number of quantum bit sequences of image information is determined to be M.
[0051] 3. Based on the quantum bits involved above, multi-qubit controlled Ry gates are added to construct the input layer of the initial quantum neural network. Each construction of an image information quantum bit sequence requires C control bit quantum bits and one quantum bit that stores the image information quantum bit information sequence. This combination is repeated M times.
[0052] 4. The number of multi-qubit controlled Ry gates that need to be added to an image information qubit sequence depends on the image size and number of pixels of the image data in the handwritten digit training set. C .
[0053] 5. For the multi-qubit controlled Ry gate required for the image information qubit sequence, set the input parameter value to the angle value θ i , the corresponding control bit sequence is determined by the binary sequence converted from the position information corresponding to the angle value, as shown below.
[0054] Specifically, the specific steps for constructing the initial quantum neural network input layer in step (1) are as follows:
[0055] In the first step, the classical image is converted into a quantum image through the operation mapping of the multi-qubit controlled rotation Ry gate, and the image information qubit sequence is constructed as the input of the initial quantum neural network. The number of image information qubit sequences in the input layer is closely related to the number of neurons in the initial quantum layer. To construct the initial quantum layer M neurons, a total of 3M+C qubits with an initial state of |0> are required. At this time, the state of the quantum system is in, It is the direct product symbol in quantum computing, indicating the initial state of the quantum system at this time. There are 3M+C quantum bits with the initial state of |0>.
[0056] The second step is to determine the number of control bit qubits C according to the current image size N×N, n=N×N=2 C, where n represents the total number of pixels in an image (n appears below and represents the total number of pixels). In a quantum circuit, the first C qubits are used as control bits. For these C qubits, a Hadamard gate is first added to put them in a superposition state. At this time, Hadamard gate operations are added to C quantum bits, and 3M quantum bits are empty operations, so the unitary operation corresponding to the Hadamard gate is Where C is the number of control bit quantum bits, M is the number of neurons, H represents the Hadamard gate operation, and I represents the unit quantum gate operation.
[0057] The third step is to construct an image information quantum bit sequence. There are n pixels on an image, and n multi-qubit controlled Ry gates need to be added. That is, the values of all pixels on an image converted to angles are input, and the angle values corresponding to the converted pixels are sorted from left to right and from top to bottom. If the pixel at (x, y) of the image is converted to an angle value of θ, θ is the parameter value of the quantum gate, and x and y are converted to lengths of The binary sequence of xy = b is the control sequence of the multi-qubit controlled Ry gate after splicing. C-1 b C-2 ...b1b0, where b C-1 ,b C-2 ,…,b1,b0 are binary bits, with values of 0 or 1, b C-1 ,…,b C / 2 Represents the binary representation of x, b C / 2-1 ,…,b0 represents each bit of the binary representation of y. The quantum bit sequence of a pixel in the image is |X i >=|Ry(θ i )b C-1 b C-2 …b1b0>, a sequence of image information quantum bits is represented by |X>=|x1>+...+|x n >=|Ry(θ1)00...0>+...+|Ry(θ n )11...1>, Ry(·) represents the quantum rotating gate operation.
[0058] In the circuit, with the multi-qubit controlled Ry gate as the center, the corresponding control sequence is 1 (solid circle), then the direct and Otherwise, the direct sum is performed on the right side of the equation and iterated sequentially. For the angle value θ1 corresponding to the first pixel after conversion, the corresponding unitary operation is The corresponding unitary operation of the angle value θ2 corresponding to the second pixel after conversion is Similarly, the angle value θ corresponding to the nth pixel after conversion isn The corresponding unitary operation is
[0059] The fourth step is to construct M image information qubit sequences. One image information qubit sequence requires C+1 qubits, and M image information qubit sequences require C+M qubits. The change in constructing M image information qubit sequences lies in the change in the position of the unit qubit in each sequence. All qubits are divided into two parts: the multi-qubit controlled Ry gate to the farthest control bit qubit part and the remaining unit qubit part. For the first image information qubit sequence, the multi-qubit controlled Ry gate and the nearest control bit qubit are regarded as a whole, with 0 unit qubits in the middle and 3M-1 unit qubits in the remaining part. For the first pixel value θ1 of the first image information qubit sequence, the corresponding unitary operation is: The second image information qubit sequence has 1 unit qubit in the middle and 3M-2 unit qubits in the remaining part. The corresponding unitary operation for the first pixel value θ1 of the second image information qubit sequence is Similarly, for the Mth image information qubit sequence, there are M-1 unit qubits in the middle, and the remaining unit qubits are 2M. For the angle value θ1 corresponding to the first pixel of the Mth image information qubit sequence after conversion, the corresponding unitary operation is Therefore, for the kth image information quantum bit sequence pixel conversion corresponding to the angle value θ j The corresponding unitary operation is:
[0060]
[0061] Where k = (1, 2, ..., M), j = (1, 2, ..., n), is the unitary operation corresponding to the j-th multi-qubit controlled Ry gate corresponding to the j-th pixel in the k-th image information qubit sequence, C is the number of control qubits, and M is the number of neurons. The k-th image information qubit sequence can be expressed as
[0062] (2) Initialize the weight quantum bit state of the initial quantum layer in the initial quantum neural network
[0063] 1. The image information quantum bit sequence corresponds one to one with the weight quantum bit sequence.
[0064] 2. According to the number of neurons in the quantum layer M, the number of weighted quantum bit sequences for initializing the initial quantum layer is determined to be M.
[0065] 3. According to the quantum bits involved above, multi-qubit controlled Ry gates are added to construct the weighted quantum bit sequence of the initial quantum layer. Each construction of a weighted quantum bit sequence requires C control bit quantum bits and one quantum bit for storing the weighted quantum bit information sequence. This combination is repeated M times.
[0066] 4. The number of multi-qubit controlled Ry gates required to add a weighted qubit sequence is the same as the number required to construct an image information qubit sequence.
[0067] 5. For the multi-qubit controlled Ry gates required for the weighted qubit sequence, set the required parameter values to the range The random angle of the image information quantum bit sequence is consistent with the control quantum bit sequence in the corresponding image information quantum bit sequence.
[0068] Specifically, the strategy for constructing the weighted quantum bit state of the initial quantum layer in the initial quantum neural network in step (2) is as follows:
[0069] The construction method of the weight quantum bit sequence in the initial quantum layer neurons is the same as the construction principle of the image information quantum bit sequence. The difference lies in the choice of parameters. The weight value at initialization is The random angle α i , i=(1,2,...,n). The image information qubit sequence corresponds to the weight qubit sequence one by one, in order to fully combine the pixels in the image with the corresponding weight information. Similarly, the M neurons in the initial quantum layer require M weight qubit sequences. A weight qubit sequence is expressed as:
[0070] |W>=|w1>+...+|w n >=|Ry(α1)00...0>+...+|Ry(α n )11...1> (2)
[0071] Among them, |Ry(α1)00...0> is the state of the first weight quantum bit |w1> after adding the multi-qubit controlled Ry gate with the first weight parameter α1, |Ry(α n )11...1> is to add the nth weight parameter α n After the multi-qubit Ry gate is controlled, the state of the first weighted qubit |w n >, the superposition of n states is the first weighted quantum bit sequence |W>.
[0072] Construct M weighted qubit sequences. One image information qubit sequence requires C+1 qubits, and M image information qubit sequences require C+M qubits. Similarly, all qubits are divided into two parts: the multi-qubit controlled Ry gate to the farthest control bit qubit part and the remaining unit qubit part. For the first weighted qubit sequence, grasp the number of unit qubits between the multi-qubit controlled Ry gate and the nearest control bit qubit, M, and the remaining unit qubits are 2M-1. For the first weighted qubit sequence, the first parameter value is The corresponding unitary operation is:
[0073]
[0074] The second weighted qubit sequence has M+1 interval unit qubits and 2M-2 remaining unit qubits. For the first parameter value of the second weighted qubit sequence The corresponding unitary operation is:
[0075]
[0076] Similarly, for the Mth weighted qubit sequence, the interval unit qubit is 2M-1, and the remaining unit qubits are M. For the Mth weighted qubit sequence, the first parameter value α1 M The corresponding unitary operation is:
[0077]
[0078] Therefore, for the kth image information quantum bit sequence corresponding to the kth weight quantum bit sequence parameter value The corresponding unitary operation is:
[0079]
[0080] in, is the unitary operation corresponding to the j-th multi-qubit controlled Ry gate in the k-th weighted qubit sequence. The k-th weighted qubit sequence can be expressed as:
[0081]
[0082] (3) Based on steps (1) and (2), the neurons in the initial quantum neural network are constructed using the exchange test technology
[0083] 1. Perform inner product of image information qubits and weight qubits according to the exchange test technology, and store the inner product result as the output of the initial quantum layer neurons in the initial quantum neural network.
[0084] 2. The quantum circuit of the exchange test technology consists of three quantum bits and two quantum gates, namely the Hadamard gate and the controlled exchange (CSWAP) gate.
[0085] 3. The three quantum bits of the exchange test technology are the quantum bits whose initial quantum states are the image information quantum bit sequence, the quantum bits whose initial quantum states are the weight quantum bit sequence, and the quantum bits whose initial state is |0>.
[0086] 4. In the exchange test quantum circuit part, the first Hadamard gate is used to put the quantum bit with the initial state of |0> into a superposition state. Then a controlled exchange gate is used to map the inner product result of the image information quantum bit sequence and the weight quantum bit sequence to the quantum bit. Finally, the second Hadamard gate is used to make the image information and weight parameters fully entangled as the output of the initial quantum layer of this layer.
[0087] Specifically, the strategy for constructing the neuron in the initial quantum layer using the exchange test technology in step (4) means: using the exchange test technology to fully inner-product the image information quantum bit sequence and the weight information quantum bit sequence, and mapping the result to the third quantum bit, so as to realize the output of the neuron. The specific strategy is as follows:
[0088] a) Constructing a quantum layer neuron requires an image information quantum bit sequence |X k >, a weight information qubit sequence |W k >, and the quantum bit |S with the initial state of |0> storing the mapping results of the two k >, k = (1, 2, ..., M).
[0089] b) The principle of exchange test technology is to use |X k > and |W k >Information on two bit sequences | <X k |W k >| 2 To quantify their similarity, we can derive |S k > status, |S k The probability of >=|0> is |S k The probability of >=|1> is
[0090] c) The quantum circuit of the exchange test technology consists of two quantum gates. First, a Hadamard gate operation is added to the quantum bit position |0> to put it in a superposition state. Second, a controlled exchange gate is added to the three quantum bits, and the quantum bit position |S k >Make control bit; finally in quantum bit position |S k >Add the Hadamard gate operation again.
[0091] d) In the quantum circuit of a complete neuron constructed with the exchange test technique, two unitary operations are included, where the unitary operation of adding a Hadamard gate to the kth neuron is:
[0092]
[0093] The data required in the kth neuron includes the kth image information qubit sequence and its corresponding kth weight qubit sequence. k >with a sequence of M weighted qubits |W k >One-to-one correspondence, for the unitary operation of adding a controlled exchange gate, all the qubits between the control bit and the farthest exchange bit are regarded as a whole. There are 2M-2 unit qubits centered on the exchange bit close to the control bit. The unitary operation corresponding to the distance from the control bit is M:
[0094] In the first neuron, regarding the controlled exchange gate unitary operation, there are C unit qubits and M-1 unit qubits left at the top and bottom, respectively. The corresponding unitary operation is:
[0095]
[0096] Regarding the unitary operation of the controlled exchange gate in the second neuron, there are C+1 unit qubits and M-2 unit qubits left above and below, and the corresponding unitary operation is:
[0097]
[0098] By analogy, in the Mth neuron, regarding the unitary operation of the controlled exchange gate, there are C+M-1 unit qubits and 2M-2 unit qubits left above and below, and the corresponding unitary operation is:
[0099]
[0100] Therefore, the unitary operation of the controlled exchange gate in the kth neuron is:
[0101]
[0102] SWAP is the exchange quantum gate operation in the controlled exchange gate. In the quantum layer part of the entire quantum circuit, the unitary operation for preparing the kth neuron is:
[0103]
[0104] The quantum state of the kth neuron is:
[0105]
[0106] for The probability when |1> is At this time, the neuron output state is for:
[0107]
[0108] by For example, the other three groups cosθsinα, sinθcosα, sinθsinα and so on are deduced, with the following prerequisites:
[0109]
[0110] Among them, θα is the abbreviation of cosθcosα, which can be summarized as follows:
[0111]
[0112] Where l represents the number of rounds, t represents the tth relational expression in the iterative relation, and k changes with the change of l. The number of times the internal parameters appear will also change. The following rules have been found through verification: The final output quantum state is related to the number of control bit qubits C. When there are l control bit qubits, This is the output state of the neuron.
[0113] (4) Constructing the initial quantum neural network activation layer
[0114] 1. The activation layer quantum circuit is mainly composed of exchange gates, Hadamard gates, controlled phase shift gates and multi-qubit XOR gates.
[0115] 2. The main idea of constructing the quantum layer activation circuit is to flip the quantum state output by the initial quantum layer neuron at a specified angle through a controlled phase shift gate and map it to a new quantum bit. Then, according to the relationship between the two quantum bits, it is mapped to the third quantum bit through an XOR gate to complete the nonlinear mapping of the activation layer as the output of the activation layer.
[0116] Specifically, the method for constructing the initial quantum neural network activation layer in step (4) is as follows:
[0117] The construction of quantum activation layer mainly involves four quantum gates, three quantum bits | S k >, |δ1>, |δ2>, firstly, the quantum bits |S containing the output quantum state information of the initial quantum layer neurons are exchanged through the exchange gate k > and the information of the quantum bit |δ1> with the initial state |0>, through the Hadamard gate operation, |δ1> is in a superposition state, and through the controlled phase shift gate, |S k> to adjust the phase of the quantum state in the process, and finally operate |S k >, |δ1> are control bits, |δ2> is the target bit, and a multi-qubit XOR gate is added to achieve the effect of nonlinear mapping of the quantum state of the activation layer. |δ2> is the output of the quantum activation layer.
[0118] (5) Training the initial quantum neural network
[0119] The initial quantum neural network is trained using a quantum optimization algorithm to optimize the trainable quantum parameters in the initial quantum neural network.
[0120] Specifically, first, the weight parameters of the quantum gates in the initial quantum neural network and the initial state of the quantum bits need to be initialized. Secondly, the quantum bits encoded as input data are transformed through a series of quantum gate operations to simulate the nonlinear activation function in the initial quantum neural network, thereby realizing the complex transformation of the quantum state. Finally, the transformed quantum state is measured to obtain a classical output. By training the initial quantum neural network, learning is done to extract features from the input data and make effective predictions or classifications.
[0121] (6) Initial quantum neural network weight parameter update
[0122] After updating the weight parameters in the initial quantum neural network using the cross entropy loss function, continue to execute step (1). Specifically, the key to updating the weight parameters of the initial quantum neural network in step (6) is: the first element is the loss function used to measure the gap between the current initial quantum neural network output and the true label. The cross entropy loss function is a commonly used loss function in classification tasks. It can measure the difference between the probability distribution predicted by the initial quantum neural network and the true distribution; the second element is the back propagation algorithm that calculates the gradient of the loss function with respect to the parameters of the initial quantum neural network; the third element is the optimization algorithm that updates the parameters of the initial quantum neural network with the calculated gradient. The Adam optimization algorithm maintains the adaptive learning rate of each parameter, thereby dynamically adjusting the learning rate during the training process, so that the initial quantum neural network can converge faster and improve performance. The above updates are intended to minimize the loss function, thereby improving the prediction performance of the initial quantum neural network.
[0123] (7) Constructing a quantum neural network
[0124] After constructing an initial quantum neural network of an input layer, an initial quantum layer, an activation layer and an output layer connected in sequence, a handwritten digit training set is input into the input layer to obtain an image information quantum bit sequence; the image information quantum bit sequence is input into the initial quantum layer, a quantum optimization algorithm is used to update the weight parameters in the initial quantum layer with the purpose of minimizing the cross entropy loss function to obtain a quantum layer; the activation layer is used to perform nonlinear mapping according to the output information data of the quantum layer and then input it into the output layer; the output layer is used to output the handwritten digit recognition result; the input layer, the quantum layer, the activation layer and the output layer are connected in sequence to obtain a quantum neural network.
[0125] In addition, the process of building a quantum neural network also includes: testing the training effect of the quantum neural network and outputting the classification results. Specifically, a test set and a validation set are obtained from the MNIST data set. The test set and the validation set are a set of data that are not involved in the training and can be used to simulate the performance of the quantum neural network on unknown data. Therefore, during the training process, the validation set is used regularly to evaluate the performance of the quantum neural network to ensure that the quantum neural network does not overfit. The test set is used to finally evaluate the performance of the quantum neural network. For classification tasks, the output of the quantum neural network is usually a probability distribution, which indicates the probability that the input data belongs to each category. Based on these probabilities, the category to which the input data is most likely to belong is determined, and the corresponding classification results are output to ensure the high accuracy of the classification results of the quantum neural network.
[0126] After the quantum neural network is constructed, the image data to be processed can be input into the quantum neural network to realize the recognition of handwritten digits. Specifically, as a specific embodiment, the present application verifies the effect of the handwritten digit recognition method based on the quantum neural network of the present application through a simulation experiment, as follows:
[0127] S1, extracts the 0 / 1 label data in the MNIST dataset and resizes it.
[0128] S2, construct the initial quantum state in the initial quantum neural network.
[0129] The classical image is converted into a quantum image as the input of the quantum neural network, and several quantum bits with an initial state of |0> are used. The input layer consists of two types of quantum bits, one for storing the position information sequence corresponding to the image pixel points, and the other for storing the image pixel point information. The adjusted image size determines that the number of reusable control bit quantum bits is C, and a Hadamard gate is added to make it in a superposition state. According to the number of neurons in the quantum layer, M image information quantum bit sequences are required. A multi-qubit controlled Ry gate is added to construct the input layer of the quantum neural network. Each constructed image information quantum bit sequence |X k>C control bit qubits and one qubit that stores the image information qubit information sequence are required, and this combination is repeated M times.
[0130] Reference Figure 5 The number of qubit-controlled Ry gates required to add to an image information qubit sequence depends on the number of pixels in the adjusted input image. C ,For the multi-qubit controlled Ry gate required for the image information qubit sequence, the input parameter value is set to the angle value, and the corresponding control bit sequence is determined by the binary sequence converted from the position information corresponding to the angle value.
[0131] S3, initialize the relevant weight quantum bit states of the initial quantum layer in the initial quantum neural network.
[0132] Similarly, the weighted quantum bit sequence |W of the M quantum layers to be initialized is determined according to the number of neurons in the quantum layer. k >, and the image information qubit sequence corresponds one-to-one to the weight qubit sequence; adding multi-qubit controlled Ry gates to construct the weight qubit sequence of the quantum layer, each construction of a weight qubit sequence requires C control bit qubits and a qubit that stores the weight qubit information sequence, and this combination is repeated M times.
[0133] Reference Figure 6 The number of quantum bit-controlled Ry gates required to add a weight quantum bit sequence is consistent with the number of quantum bit-controlled Ry gates required to construct an image information quantum bit sequence. For the multi-qubit controlled Ry gates required for the weight quantum bit sequence, the required parameter value is set to a random angle in the range of [0, π / 2], and its control bit sequence is consistent with the control quantum bit sequence in the corresponding image information quantum bit sequence.
[0134] S4, constructing neurons in the initial quantum layer using the exchange test technique.
[0135] Reference Figure 7 The quantum circuit of the exchange test technology consists of three quantum bits and two quantum gates, Hadamard gate and controlled exchange gate. The first Hadamard gate makes the quantum bit |S k > is in a superposition state, followed by a controlled exchange gate to make the image information quantum bit sequence |X k > and weighted qubit sequence |W k >The inner product result is mapped to the quantum bit, and the image information and weight parameters are fully entangled through the second Hadamard gate as the output of this quantum layer.
[0136] The core of the exchange test technology is to make the image information quantum bit sequence |X k >with weighted qubit sequence |Wk >Fully inner product, store the inner product result as the output of the quantum layer neuron |S k >. For the output of the quantum layer neuron |S k > is the formula for |1> Figure 8 .
[0137] S5, construct the initial quantum neural network activation layer part.
[0138] Reference Fig. 9 , the activation layer quantum circuit mainly involves four quantum gates, three quantum bits |S k >, |δ1>, |δ2>, firstly, the quantum bits |S containing the quantum state information of the quantum layer neuron output are exchanged through the exchange gate k > and the information of the quantum bit |δ1> with the initial state |0>, through the Hadamard gate operation, |δ1> is in a superposition state, and through the controlled phase shift gate, |S k > to adjust the phase of the quantum state in the process, and finally operate |S k >, |δ1> are control bits, |δ2> is the target bit, and a multi-qubit XOR gate is added to achieve the effect of nonlinear mapping of the quantum state of the activation layer. |δ2> is the output of the quantum activation layer.
[0139] S6, training the initial quantum neural network.
[0140] The initial quantum neural network consists of an input layer, a quantum layer, an activation layer, and an output layer. Fig.10 This is the global structure diagram of the quantum neural network, and the network is trained.
[0141] S7, parameter update, uses the cross entropy loss function to update the weight parameters in the initial quantum neural network and then continues to execute S2.
[0142] S8, test the training effect of the quantum neural network and output the classification results.
[0143] This application uses quantum information processing as the basic theoretical framework and combines exchange testing to construct a fully parameterized quantum neural network based on amplitude coding, which is specifically used for quantum image classification processing. This application makes full use of the characteristics of quantum parallel computing to place the quantum neural network framework under a unified quantum system, and technically strips the classical information in the existing quantum-classical combined neural network and the related technologies for processing classical information. The quantum neural network of this application covers the basic structure and implementation method of the feedforward neural network, and can effectively use the quantum superposition state to encode and process image information. The quantum bit sequence in the superposition state used to encode image information is used as the input of the quantum neural network. The quantum neural network constructed based on the quantum superposition principle greatly reduces the storage volume of the training and test data sets; the inner product of the input quantum bit sequence and the weight quantum bit sequence, both in the quantum superposition state, is mapped to the probability amplitude of the result quantum bit by using the exchange test, so as to complete the mapping of neuron input to output, and makes full use of the characteristics of quantum parallel computing to optimize the calculation process of network data, so that the calculation complexity of the gray value and the weight inner product reaches the order of O(1), thereby greatly improving the learning efficiency of the quantum neural network.
[0144] Fig.11 The comparison of the classification results of the classical neural network and quantum neural network with the same network structure after 100 rounds of training is shown under the conditions of data set size of 2×2 and 4×4. It can be seen that when the available data set is limited, the classical neural network does not show good learnability, and the classification result accuracy remains at 53.93%, while the quantum neural network model can still achieve a high level of accuracy under the condition of obtaining limited data information. Fig.12 The data comparison of quantum neural network in three cases of data set size of 2×2, 4×4, and 8×8 shows that as the available data set information increases, the quantum neural network can complete the learning optimization process of the network more quickly and efficiently, with an accuracy of up to 98%; the proposed nonlinear mapping method that can be implemented in a quantum computer effectively reduces the loss value of the quantum neural network model. Therefore, this application uses the characteristics of quantum superposition and entanglement to reduce the storage overhead of quantum neural network training data, reduce the parameter scale, and obtain better classification results based on the correlation between image data.
[0145] For the measurement part required in the quantum neural network of this application, it is set to measure the single bit containing the output information in the entire quantum neural network, thereby greatly reducing the interference with the quantum state of the neural network. The simulation results in the experimental part have proved that even with a small number of neurons, the quantum neural network still exhibits efficient learning ability. The quantum neural network proposed in this application ensures the closure and stability of the quantum system when quantum information is feedforward propagated in the neural network, thereby greatly improving the execution efficiency and quantum operability of the quantum algorithm, thereby effectively improving the efficiency and accuracy of handwritten digit recognition.
[0146] In some embodiments, the present application also provides a computer program product, including a computer program, which, when executed by a processor, implements the handwritten digit recognition method based on quantum neural network.
[0147] In some embodiments, the present application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the handwritten digit recognition method based on quantum neural network.
[0148] In some embodiments, the present application also provides a computer device, including a processor, a memory, an input / output interface (Input / Output, referred to as I / O), a communication interface, and a computer program stored in the memory and executable on the processor, and the processor executes the computer program to implement the handwritten digit recognition method based on quantum neural network.
[0149] The processor, memory and input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store pending transactions. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the handwritten digit recognition method based on quantum neural network is implemented.
[0150] It should be noted that the object information (including but not limited to object device information, object personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the object or fully authorized by all parties, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.
[0151] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ReadOnlyMemory, ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited thereto. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited thereto.
[0152] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0153] This article uses specific examples to illustrate the principles and implementation methods of this application. The description of the above embodiments is only used to help understand the method and core ideas of this application. At the same time, for those skilled in the art, according to the ideas of this application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting this application.
Claims
1. A handwritten digit recognition method based on quantum neural network, It is characterized in that include: Get image data of handwritten digits; Input the image data into the quantum neural network and output the handwritten digit recognition result; The quantum neural network is determined by a quantum optimization algorithm with the purpose of minimizing the cross entropy loss function; the quantum neural network comprises an input layer, a quantum layer, an activation layer and an output layer connected in sequence; the input layer is provided with a multi-qubit controlled Ry gate; the input layer is used to convert image data into a quantum image to obtain an image information qubit sequence; The quantum layer is used for: Obtaining a weighted quantum bit sequence according to the image information quantum bit sequence; Obtaining output information data based on the image information quantum bit sequence and the weight quantum bit sequence; The activation layer is used to perform nonlinear mapping on the output information data and then input it into the output layer; The output layer is used to output the handwritten digit recognition result.
2. The handwritten digit recognition method based on quantum neural network according to claim 1, It is characterized in that The method for determining the quantum neural network specifically includes: Obtain an initial training set of handwritten digits and perform preprocessing to obtain a handwritten digit training set; Constructing an initial quantum neural network; the initial quantum neural network comprises an input layer, an initial quantum layer, an activation layer and an output layer connected in sequence; Input the handwritten digit training set into the input layer to obtain the image information quantum bit sequence; The image information quantum bit sequence is input into the initial quantum layer, and the weight parameters in the initial quantum layer are updated by using a quantum optimization algorithm with the purpose of minimizing the cross entropy loss function to obtain a quantum layer; The activation layer is used to perform nonlinear mapping according to the output information data of the quantum layer and then input it to the output layer; the output layer is used to output the handwritten digit recognition result; The input layer, quantum layer, activation layer and output layer are connected in sequence to obtain a quantum neural network.
3. The handwritten digit recognition method based on quantum neural network according to claim 2, It is characterized in that The step of obtaining an initial training set of handwritten digits and preprocessing the training set of handwritten digits specifically includes: Get the image data of handwritten digits with 0 / 1 labels in the MNIST dataset as the initial training set; The image sizes of the image data in the initial training set are adjusted to 2×2, 4×4, 8×8 and 16×16 respectively; at the same time, the information of each pixel in the image data is extracted and the pixel value of each pixel is converted into an angle value to obtain a handwritten digit training set.
4. The handwritten digit recognition method based on quantum neural network according to claim 3, It is characterized in that The handwritten digital training set is input into the input layer to obtain the image information quantum bit sequence, which specifically includes: Input the handwritten digit training set into the input layer, and determine the number of control bit quantum bits and the number of multi-qubit controlled Ry gates according to the image size and the number of pixels of the image data in the handwritten digit training set; The image data is converted into a quantum image by performing a mapping operation through a multi-qubit controlled Ry gate; the quantum image includes a plurality of qubits whose initial state is |0>; Based on the control bit quantum bits, the multi-qubit controlled Ry gate and several quantum bits with an initial state of |0>, an image information quantum bit sequence is obtained.
5. The handwritten digit recognition method based on quantum neural network according to claim 4, It is characterized in that The weight quantum bit sequence corresponds one-to-one to the image information quantum bit sequence.
6. The method for handwritten digit recognition based on quantum neural network according to claim 5, It is characterized in that The obtaining of output information data based on the image information quantum bit sequence and the weight quantum bit sequence specifically includes: Based on the image information quantum bit sequence and the weight quantum bit sequence, an exchange test technology is used to obtain output information data.
7. The handwritten digit recognition method based on quantum neural network according to claim 1, It is characterized in that The activation layer includes an exchange gate, a Hadamard gate, a controlled phase shift gate, and a multi-qubit XOR gate.
8. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the handwritten digit recognition method based on quantum neural network described in any one of claims 1 to 7 is implemented.
9. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the handwritten digit recognition method based on quantum neural network described in any one of claims 1 to 7 is implemented.
10. A computer device, include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the handwritten digit recognition method based on quantum neural network according to any one of claims 1 to 7.
Citation Information
Patent Citations
Generation of higher-resolution datasets with a quantum computer
CA3139157A1
A handwritten picture classification method based on a quantum neural network
CN109948742A
Handwritten image recognition method based on multi-scale CNN features and quantum flora optimization KELM
CN110969086A
Image recognition system and method based on quantum convolutional neural network
CN113361664A
Handwritten numeral recognition method, system and equipment and computer readable storage medium
CN114120336A
Cited By
Model-based interaction method and system, wearable device and storage medium
CN120724211A
