Image classification method and system, and electronic device and storage medium
By adopting convolutional neural network module, quantum layer module and classification layer module in the image classification model, and using multiple quantum lines to process data fragments in parallel, the problem of low efficiency and accuracy caused by quantum state decoherence in the prior art is solved, and more efficient and accurate image classification is achieved.
Patent Information
- Application Number
- PCT/CN2024/131410
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-12-20
- Filing Date
- 2024-11-11
- Publication Date
- 2025-06-26
AI Technical Summary
In image classification, existing hybrid quantum neural networks have low efficiency and accuracy due to excessive number of line bits and excessive operation of gate circuits.
The image classification model of the convolutional neural network module, quantum layer module and classification layer module is adopted. By dividing the one-dimensional feature data into multiple data segments and processing it in parallel with multiple quantum lines, the number of bits and quantum lines depth are reduced.
It improves the efficiency and accuracy of image classification, reduces the impact of quantum state decoherence, and enhances the training effect of image classification model.
Smart Images

Figure CN2024131410_26062025_PF_FP_ABST
Abstract
Description
Image classification method, system, electronic device and storage medium Technical Field
[0001] The present application relates to the field of quantum machine learning technology, and in particular to an image classification method, system, electronic device, and storage medium. Background Art
[0002] With the advancement of technology, artificial intelligence and machine learning have achieved remarkable progress in numerous fields. However, with the rapid growth of data volumes, traditional machine learning algorithms face enormous computational and time-consuming challenges in handling complex tasks. Quantum computing, as an emerging computing model, has the potential to surpass classical computing in solving certain problems. In recent years, quantum machine learning, an interdisciplinary field combining quantum computing and machine learning, has attracted widespread attention.
[0003] There are solutions in the related art that use hybrid quantum neural networks for image classification. Hybrid quantum neural networks include classical convolutional neural networks and quantum neural networks. However, the above-mentioned hybrid quantum neural network circuits have too many bits and are affected by the decoherence of quantum states caused by excessively deep gate circuit operations, resulting in low efficiency and accuracy in image classification.
[0004] Therefore, how to improve the efficiency and accuracy of image classification is a technical problem that those skilled in the art currently need to solve.
[0005] Summary of the Invention
[0006] The purpose of this application is to provide an image classification method, system, electronic device and storage medium that can improve the efficiency and accuracy of image classification.
[0007] To solve the above technical problems, the present application provides an image classification method, which is applied to an electronic device running an image classification model, wherein the image classification model includes a convolutional neural network module, a quantum layer module, and a classification layer module. The image classification method includes:
[0008] Acquire a sample image, and convert the sample image into one-dimensional feature data using the convolutional neural network module;
[0009] Slicing the one-dimensional feature data into a plurality of data segments, and processing all of the data segments in parallel using a plurality of quantum circuits in the quantum layer module;
[0010] splicing the output results of all the quantum circuits to obtain a splicing vector, and using the classification layer module to output a category prediction result corresponding to the splicing vector;
[0011] Calculating a loss function value according to the category prediction result and the category label of the sample image, and updating network parameters of the convolutional neural network module and the quantum layer module according to the loss function value to train the image classification model;
[0012] If an image recognition task is received, an unknown image corresponding to the image recognition task is determined, and the image category of the unknown image is output using the trained image classification model.
[0013] Optionally, the convolutional neural network module includes a convolution layer, a pooling layer and a linear layer;
[0014] Accordingly, the sample image is converted into one-dimensional feature data using the convolutional neural network module, including:
[0015] Using the convolution layer to extract features from the sample image, and using the pooling layer to perform a maximum pooling operation on the output result of the convolution layer to obtain image feature information;
[0016] The linear layer is used to perform dimension transformation and linear combination on the image feature information to obtain the one-dimensional feature data with a length of a preset value.
[0017] Optionally, the extracting features from the sample image using a convolutional layer includes:
[0018] Determining a pixel information matrix corresponding to the sample image;
[0019] If the number of rows and / or columns of the pixel information matrix is not an integer power of 2, padding the edges of the pixel information matrix with elements having a value of 0 to obtain a new pixel information matrix; wherein the number of rows and the number of columns of the new pixel information matrix are both integer powers of 2;
[0020] The convolutional layer is used to extract features from the new pixel information matrix.
[0021] Optionally, utilizing multiple quantum circuits in the quantum layer module to process all the data fragments in parallel includes:
[0022] Allocating all the data fragments to the plurality of quantum circuits according to a preset ratio;
[0023] Each of the quantum circuits is controlled to process the allocated data fragments; wherein each of the quantum circuits includes a data encoding layer, an entanglement layer, and a measurement layer.
[0024] Optionally, controlling each quantum circuit to process the allocated data fragment includes:
[0025] Using the data coding layer to perform a phase coding operation of a single-bit rotary gate on the allocated data fragment to obtain a coded quantum state;
[0026] The encoded quantum state is processed using the entanglement layer to obtain an entangled quantum state containing training parameters; wherein the entanglement layer includes a parameterized single-bit arbitrary rotation gate and a fully connected controlled NOT gate between two adjacent bits;
[0027] The measurement layer is used to perform full-amplitude measurement on a preset number of entangled quantum states containing training parameters to obtain a single-bit Pauli matrix average value; wherein the full-amplitude measurement is an operation of measuring the quantum state projection value along the Pauli X matrix direction, the Pauli Y matrix direction, and the Pauli Z matrix direction respectively.
[0028] Optionally, all the quantum circuits in the quantum layer module are respectively run on multiple quantum computers;
[0029] Accordingly, the process of training the image classification model also includes:
[0030] Controlling all quantum circuits running in the same quantum computer to share training parameters.
[0031] Optionally, splicing the output results of all the quantum circuits to obtain a spliced vector includes:
[0032] Determining a fragment sequence number of each of the data fragments in the one-dimensional feature data;
[0033] The output results of the quantum circuit corresponding to all the data fragments are spliced according to the fragment sequence numbers to obtain the splicing vector.
[0034] The present application also provides an image classification system, which is applied to an electronic device running an image classification model, wherein the image classification model includes a convolutional neural network module, a quantum layer module, and a classification layer module. The image classification system includes:
[0035] A feature extraction module, configured to obtain a sample image and convert the sample image into one-dimensional feature data using the convolutional neural network module;
[0036] A parallel processing module, configured to divide the one-dimensional feature data into multiple data segments, and process all the data segments in parallel using multiple quantum circuits in the quantum layer module;
[0037] A prediction module, configured to splice the output results of all the quantum circuits to obtain a spliced vector, and output a category prediction result corresponding to the spliced vector using the classification layer module;
[0038] A training module, configured to calculate a loss function value based on the category prediction result and the category label of the sample image, and update network parameters of the convolutional neural network module and the quantum layer module based on the loss function value, so as to train the image classification model;
[0039] The classification module is used to determine the unknown image corresponding to the image recognition task upon receiving the image recognition task, and output the image category of the unknown image using the trained image classification model.
[0040] The present application also provides a storage medium on which a computer program is stored. When the computer program is executed, the steps of the above-mentioned image classification method are implemented.
[0041] The present application also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above-mentioned image classification method when calling the computer program in the memory.
[0042] The present application provides an image classification method, which is applied to an electronic device running an image classification model, wherein the image classification model includes a convolutional neural network module, a quantum layer module, and a classification layer module. The image classification method includes: obtaining a sample image, and using the convolutional neural network module to convert the sample image into one-dimensional feature data; dividing the one-dimensional feature data into multiple data segments, and using multiple quantum circuits in the quantum layer module to process all the data segments in parallel; splicing the output results of all the quantum circuits to obtain a splicing vector, and using the classification layer module to output a category prediction result corresponding to the splicing vector; calculating a loss function value based on the category prediction result and the category label of the sample image, and updating the network parameters of the convolutional neural network module and the quantum layer module based on the loss function value to train the image classification model; if an image recognition task is received, determining an unknown image corresponding to the image recognition task, and using the trained image classification model to output the image category of the unknown image.
[0043] The image classification scheme provided in this application is implemented based on an image classification model consisting of a convolutional neural network module, a quantum layer module, and a classification layer module. In the process of training the image classification model, this application uses a convolutional neural network module to convert a sample image into one-dimensional feature data, divides the one-dimensional feature data into multiple data segments, and then uses multiple quantum circuits in the quantum layer module to process all the data segments in parallel. After being processed in sequence by the convolutional neural network module, the quantum layer module, and the classification layer module, this application also uses a loss function value calculated based on the category prediction result and the category label of the sample image, and updates the network parameters of the convolutional neural network module and the quantum layer module based on the loss function value to achieve training of the image classification model. The quantum layer module in this application uses multiple parallel quantum circuits to reduce the number of bits and the depth of the quantum circuit. After the image classification model obtained by training the above scheme is obtained, the image classification model is used to process image recognition tasks to improve the efficiency and accuracy of image classification. This application also provides an image classification system, a storage medium, and an electronic device with the above-mentioned beneficial effects, which will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. 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 any creative work.
[0045] FIG1 is a flow chart of an image classification method provided in an embodiment of the present application;
[0046] FIG2 is a diagram of a quantum circuit design with parameters provided in an embodiment of the present application;
[0047] FIG3 is a flow chart of an image classification solution based on a hybrid quantum neural network of full amplitude measurement provided in an embodiment of the present application;
[0048] FIG4 is a schematic diagram of the structure of an image classification model provided in an embodiment of the present application;
[0049] FIG5 is a schematic diagram of a quantum circuit module parallel software computing device provided in an embodiment of the present application;
[0050] FIG6 is a schematic diagram of the structure of an image classification system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0051] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0052] Please refer to Figure 1 below, which is a flowchart of an image classification method provided in an embodiment of the present application.
[0053] Specific steps may include:
[0054] S101: Acquire a sample image, and convert the sample image into one-dimensional feature data using the convolutional neural network module;
[0055] Among them, this embodiment can be applied to an electronic device running an image classification model, and the image classification model includes a convolutional neural network module, a quantum layer module and a classification layer module. The above-mentioned convolutional neural network module, quantum layer module and classification layer module can be arranged in an electronic device including a CPU (Central Processing Unit) and a QPU (Quantum Processing Unit); for example, the above-mentioned convolutional neural network module and classification layer module can be arranged in a classical computer including a CPU, the quantum layer module can be arranged in a quantum computer including a QPU, and the electronic device running the image classification model includes a classical computer and a quantum computer. Convolutional neural network is a type of feedforward neural network that includes convolution calculations and has a deep structure, which can be used to extract nonlinear features of images to achieve the purpose of classification.
[0056] The above-mentioned image classification model can be a classification model for handwritten digital images or a classification model for medical imaging images, which is not specifically limited here. In this embodiment, sample images for training the image classification model can be obtained, and the sample images have category labels added to them, that is, the actual category of the image.
[0057] After obtaining the sample images, a certain number of sample images can be input into the convolutional neural network module of the image classification model in batches, so that the convolutional neural network module converts the pixel information matrix of the sample images into one-dimensional feature data.
[0058] S102: Slice the one-dimensional feature data to obtain multiple data segments, and process all the data segments in parallel using multiple quantum circuits in the quantum layer module;
[0059] The quantum layer module of the image classification model includes multiple parallel quantum circuits, also known as a quantum circuit parallel module. This step divides the one-dimensional feature data into multiple data segments, assigning each data segment to each quantum circuit for processing, so that multiple quantum circuits can process all data segments in parallel. These quantum circuits are parameterized quantum circuits, computational circuits operated by a series of quantum logic gates with adjustable parameters, and their computational rules conform to the principles of tensor index expansion, contraction, and merging.
[0060] As a feasible implementation, this embodiment can equally divide a one-dimensional feature into multiple data segments of equal length. Each data segment is one-dimensional data, i.e., a portion of the one-dimensional feature data. This embodiment can allocate all data segments according to preset rules. The preset rules are: all data segments have allocations, the same data segment is allocated only once, and the difference in the number of data segments allocated between any two quantum circuits is less than or equal to a preset value (e.g., 1 or 2).
[0061] S103: splicing the output results of all the quantum circuits to obtain a splicing vector, and using the classification layer module to output a category prediction result corresponding to the splicing vector;
[0062] After each data segment is processed by a quantum circuit, a corresponding output result is obtained. In this application, the output results corresponding to all data segments output by all quantum circuits can be spliced together to obtain a splicing vector. After obtaining the splicing vector, the splicing vector can be input into the classification layer module of the image classification model to obtain the corresponding category prediction result.
[0063] As a feasible implementation, this embodiment can determine the fragment sequence number of each data fragment in the one-dimensional feature data; and splice the output results of the quantum circuit corresponding to all the data fragments according to the fragment sequence number to obtain the splicing vector.
[0064] S104: Calculating a loss function value according to the category prediction result and the category label of the sample image, and updating network parameters of the convolutional neural network module and the quantum layer module according to the loss function value, so as to train the image classification model;
[0065] After obtaining the category prediction result of the image classification model for the sample image, the loss function value can be calculated in combination with the category label of the sample image, and then the network parameters of the convolutional neural network module and the quantum layer module can be updated based on the loss function value to realize the training of the image classification model.
[0066] This embodiment allows for iterative training of the image classification model, i.e., looping through operations S101 to S104, determining a new sample image each time the loop is entered. When the number of iterations reaches a preset value or the loss function value reaches a preset value, the loop ends and the image classification model training is determined to be complete. All of the quantum circuits in the quantum layer module run on multiple quantum computers; accordingly, during the training of the image classification model, all of the quantum circuits running on the same quantum computer can be controlled to share training parameters to improve training efficiency.
[0067] S105: If an image recognition task is received, an unknown image corresponding to the image recognition task is determined, and the image category of the unknown image is output using the trained image classification model.
[0068] After the image classification model is trained, if an image recognition task is received, an unknown image corresponding to the image recognition task is determined, and the unknown image is input into the trained image classification model so that the image classification model outputs the image category of the unknown image.
[0069] If the image classification model is for handwritten digits, the output image category is the handwritten digits in the unknown image, enabling image and text recognition. If the image classification model is for medical images, the output image category is the type of medical image in the unknown image, enabling accurate classification of medical images.
[0070] The image classification scheme provided in this embodiment is implemented based on an image classification model consisting of a convolutional neural network module, a quantum layer module, and a classification layer module. In the process of training the image classification model, this embodiment uses a convolutional neural network module to convert a sample image into one-dimensional feature data, divides the one-dimensional feature data into multiple data segments, and then uses multiple quantum circuits in the quantum layer module to process all the data segments in parallel. After being processed in sequence by the convolutional neural network module, the quantum layer module, and the classification layer module, this embodiment also uses a loss function value calculated based on the category prediction result and the category label of the sample image, and updates the network parameters of the convolutional neural network module and the quantum layer module based on the loss function value to achieve training of the image classification model. The quantum layer module in this embodiment uses multiple parallel quantum circuits to reduce the number of bits and the depth of the quantum circuit. After the image classification model is trained by the above scheme, using the image classification model to process image recognition tasks can improve the efficiency and accuracy of image classification.
[0071] As a further introduction to the embodiment corresponding to Figure 1, the convolutional neural network module may include a sequentially connected convolutional layer, a ReLU activation function, a pooling layer, and a linear layer, wherein the linear layer includes a normalization operation and a hidden linear connection layer. The convolutional neural network module can design a characteristic classic convolutional neural network based on the difficulty coefficient of the image classification task in the dataset, thereby constructing the convolutional neural network required for complex image classification.
[0072] Correspondingly, the process of the convolutional neural network module processing the sample image is as follows: using the convolution layer to extract features of the sample image, using the pooling layer to perform a maximum pooling operation on the output result of the convolution layer to obtain image feature information; using the linear layer to perform dimensional transformation and linear combination on the image feature information to obtain the one-dimensional feature data with a preset length.
[0073] Furthermore, since the convolutional layer needs to process the pixel information matrix of the sample image, if the size of the pixel information matrix does not meet the optimal processing size for the convolutional layer, the edges of the pixel information matrix can be padded with elements with a value of 0. One feasible processing method is as follows: determining the pixel information matrix corresponding to the sample image; if the number of rows and / or columns of the pixel information matrix is not an integer power of 2, padded with elements with a value of 0 at the edges of the pixel information matrix to obtain a new pixel information matrix; wherein the number of rows and columns of the new pixel information matrix are both integer powers of 2; and using the convolutional layer to extract features from the new pixel information matrix.
[0074] Taking handwritten digit recognition as an example, the above process is illustrated:
[0075] The sample images in the image set are normalized and preprocessed in batches, and the sample size of each batch of sample images can be set to: 1, 32, 64 and 128, etc. The input data information of each sample image includes the pixel values of a matrix of size n×n and a classification identifier (i.e., category label) of the image length of 1. The specific numbers marked in all the legends in this embodiment are examples of MNIST (Mixed National Institute of Standards and Technology database, a handwritten digit recognition data set). The training sample set contains 10 categories of handwritten digits 0-9. The pixel information matrix size of each digital image is 28×28, and the number of samples in each batch is 64. The MNIST data set is a binary image data set of handwritten digits from 0 to 9 used to train various image processing systems. It contains a training set of 60,000 sample images and a test set of 10,000 sample images.
[0076] In this embodiment, the data stream of the sample image can be input into the convolutional neural network module for processing. The convolutional neural network module mainly includes a convolutional layer, a pooling layer, the activation function ReLU, and a linear layer. Since the convolutional neural network required to complete more complex image classification is relatively complex, the convolutional neural network module can design a characteristic classical convolutional neural network according to the difficulty coefficient of the image classification task in the dataset. After the sample image passes through the convolutional layer and the pooling layer, the pixel information matrix with the original size of n×n will be elongated, and finally output as a one-dimensional feature data with a length of m (m < n×n) to the next layer module, that is, the quantum layer module.
[0077] Specifically, the implementation process of the convolutional neural network module designed for identifying the set of handwritten digits is as follows:
[0078] For the pixel information matrix of the sample image with an input size of 28×28, after padding with a padding circle number of 2 (the padded number is 0), the pixel information matrix becomes 32×32. In this embodiment, the number of features of the selected convolutional layer is 20, each convolutional kernel size is 5×5, and the stride is 1. The role of the convolutional kernel is to extract the local features of the original image. After the action of the convolutional layer, the matrix size is 20×28×28. Each convolutional kernel is a linear combination y = w T x + b of the square matrix of the sample image containing training parameters, where x is the small square matrix of the padded sample image, w T is the weight parameter to be trained in the convolutional kernel, b is the bias parameter inside each neuron in the convolutional kernel, and y is the output result of the convolutional layer.
[0079] In order to imitate the working nature of neurons in living organisms, when the input signal in the neuron exceeds a certain threshold, the signal will be transmitted to the next layer. The expression of the activation function ReLU is as follows:
[0080] In order to reduce the number of training parameters in the convolutional layer and maximize the retention of the feature information in the sample image, this embodiment uses the pooling layer to select the representative information in the matrix, so that the above information can effectively participate in the training of the next layer of neural network. In this embodiment, the max pooling layer method is used, that is, only the maximum value in the 2×2 matrix of the pooling layer is retained. After the action of the convolutional layer containing the ReLU activation function, the matrix size is 20×28×28. After passing through the max pooling layer with a stride of 2, the matrix size becomes 20×14×14, and the matrix size is 1 / 4 of that after passing through the convolutional layer.
[0081] After processing through the convolutional and pooling layers, the feature information of each sample image is extracted into a high-order matrix with a length, width, and height of (20, 14, 14). The linear layer straightens the high-order matrix into a one-dimensional vector of length 3920 without changing the total length of its elements. To further reduce the complexity of training parameters, the 3920-length vector is shortened to a vector of length 30 using linear combination, resulting in one-dimensional feature data of a fixed length. The one-dimensional feature data ultimately output by the linear layer serves as the input data for the quantum layer module. Therefore, when designing the algorithm, the size of the one-dimensional feature data can be determined based on the number of computable bits of existing quantum computer hardware and the number of available quantum computer devices.
[0082] As a further introduction to the embodiment corresponding to FIG1 , after the one-dimensional feature data is segmented to obtain multiple data segments, all of the data segments can be distributed to the multiple quantum circuits according to a preset ratio; and each of the quantum circuits is controlled to process the distributed data segments.
[0083] Each quantum circuit comprises a data encoding layer, an entanglement layer, and a measurement layer, wherein the entanglement layer comprises a parameterized single-bit arbitrary rotation gate and a fully connected controlled NOT gate between two adjacent bits. The quantum circuit processes each data segment as follows: the data encoding layer performs a phase encoding operation using a single-bit rotation gate on the assigned data segment to obtain an encoded quantum state; the entanglement layer processes the encoded quantum state to obtain an entangled quantum state containing training parameters; and the measurement layer performs full-amplitude measurement on a preset number (the preset number can be less than the total number of entangled quantum states) of the entangled quantum states containing training parameters to obtain a single-bit Pauli matrix average value. The full-amplitude measurement is the operation of measuring the quantum state projection values along the Pauli X matrix direction, the Pauli Y matrix direction, and the Pauli Z matrix direction, i.e., the operation of measuring the quantum state projection values in the X, Y, and Z directions. Pauli matrices are mathematical matrices used to describe two-level quantum state systems. They have the following properties: 1) Multiplying a Pauli matrix with itself yields the identity matrix, and 2) multiplying a Pauli matrix with the identity matrix yields the Pauli matrix itself. The most basic Pauli matrices are the single-bit Pauli X matrix, the Pauli Y matrix, and the Pauli Z matrix.
[0084] Taking handwritten digit recognition as an example, the above process is illustrated:
[0085] In this embodiment, the one-dimensional feature data with a length of m of 30 obtained by processing the convolutional neural network module can be input into the quantum layer module. In order to adapt to the experimental accuracy of small and medium-sized quantum computer devices containing noise, the number of quantum bits used in the quantum circuit in the quantum algorithm must be as small as possible, and the depth of the quantum gate circuit must be shallow, so as to ensure relatively reliable quantum experimental results. In order to improve the computational efficiency of quantum computing and make full use of existing quantum computing resources, the idea of "divide and conquer" can be adopted. First, the large block of one-dimensional feature data is divided into several data fragments, and the quantum computer is used to process the independent data fragments in parallel; the above-mentioned process of parallel processing of data fragments can be carried out in different connected configuration bit areas of the same quantum hardware device, that is, to achieve parallel processing within the same quantum computing node; the above-mentioned process of parallel processing of data fragments can also be carried out in the connected areas of different quantum hardware device bits, that is, to achieve distributed parallel processing between different quantum computers (i.e., quantum nodes). Through the above process, each independent quantum circuit returns the measured results to the electronic computing device in turn, and the combination constitutes the input of the fully connected layer of the classification layer module.
[0086] Specifically, each independent quantum circuit is divided into three parts: data encoding layer, entanglement layer and measurement layer (i.e., local full-amplitude measurement layer).
[0087] For example, in the case of three quantum circuits, the linear layer of the convolutional neural network module outputs one-dimensional feature data of length 30, which is evenly distributed to the three quantum circuits according to the vector index positions 0 to 9, 10 to 19, and 20 to 29. Each independent quantum circuit will receive a data segment of a certain length output by the linear layer. Due to the small amount of data segments, the data encoding layer can directly use the phase encoding method of a single-bit rotation gate, such as the rotation gate R around the x-axis. x (πθ), where θ corresponds to a single classical data point assigned to a single bit in the quantum circuit. The phase encoding method for the aforementioned single-bit quantum rotation gate is an encoding method that loads classical data onto the angle of the single-bit rotation gate that controls the quantum state.
[0088] After processing by the data encoding layer, the classical data information has been loaded into the quantum state. The design of the entanglement layer in this embodiment includes a parameterized single-bit arbitrary rotation gate R (ɑ, β, γ) and a controlled non-gate (CNOT gate) between two adjacent bits that are fully connected. In this way, a shallower quantum circuit gate operation depth can be used to achieve the global entanglement of the bit space. The ɑ and γ in the above-mentioned single-bit arbitrary rotation gate R (ɑ, β, γ) represent the rotation angles around different rotation axes, respectively, and β represents the global phase of the quantum state. In order to save the amount of parameters during training, the same set of training parameters can be shared between different quantum circuits.
[0089] After the entanglement layer is processed, the bits in the quantum circuit are highly entangled. The measurement layer selects the projection of the quantum circuit entangled state in the subspace of several bits along the Pauli X, Y and Z matrices. Multiple measurements can return the average value of the Pauli matrix of a single bit. i represents the serial number of a single bit, i = 0, 1, 2, .... Please refer to Figure 2, which is a design diagram of a parameter-containing quantum circuit provided in an embodiment of the present application. In Figure 2, for example, the subspace selected is the bits marked as 0 and 1 in the quantum circuit. Each quantum circuit will return a vector of length 6: In the figure, q0~q9 represent quantum bits, R x (θ0)~R x (θ9) represents the x-axis rotation gate, and R(α0,β0,γ0) to R(α9,β9,γ9) represent single-bit arbitrary rotation gates.
[0090] Furthermore, the classification layer module receives the measurement values of each quantum circuit in the quantum layer module and concatenates them sequentially to form a concatenated vector of length 18. This concatenated vector of length 18 is then linearly connected to the classification layer of length 10. The normalized exponential function Softmax is used to output the probabilities of belonging to each of the 10 categories. The index subscript of the output maximum probability value corresponds to the specific category of the sample.
[0091] The process described in the above embodiment is explained below through an embodiment in actual application.
[0092] In the current era of artificial intelligence and big data, traditional computing hardware and algorithms are no longer able to meet the demands of processing and analyzing the massive amounts of data generated in human life and social production activities. Quantum computers, based on the principles of quantum mechanics' superposition and the entanglement of quantum states, theoretically offer exponentially higher data parallel processing capabilities and storage capacity, along with rapid execution speeds. However, because the quantum states generated by quantum computers are easily perturbed by environmental noise, quantum computer hardware is still in its early stages and has yet to fully replace classical computers. Therefore, to adapt to current quantum computer hardware conditions, it is essential to explore algorithms that combine quantum and classical computing. In particular, traditional neural network machine learning has achieved remarkable success in image classification and has been successfully implemented. In the new field of quantum machine learning, research on the application of hybrid quantum neural networks in image classification is a highly valuable and promising area.
[0093] Please refer to Figure 3, which is a flow chart of an image classification scheme based on a hybrid quantum neural network with full amplitude measurement provided by an embodiment of the present application. After starting, the number of iterations epoch is set to 1, the image training data set is input and preprocessed, and the sample images in the image training data set are processed in sequence by the convolutional neural network module, the quantum layer module, and the classification layer module. After setting the number of iterations epoch to +1, it is determined whether the number of iterations epoch is greater than or equal to 100. If so, the training is terminated and the model is output. Otherwise, the error in the neural network is calculated, the error gradient is obtained, and the weights are updated. The process of training a hybrid quantum neural network includes a forward propagation process and a backpropagation process.
[0094] This embodiment provides an image classification solution based on a hybrid quantum neural network with full amplitude measurement, which may include the following steps:
[0095] Step 1: Pack the sample images in the image collection into batches and perform normalization preprocessing.
[0096] This step can be implemented based on an image data loading module, which processes the image set to be classified through standardization, determines the number of image samples in each batch, and packages the data samples in batches.
[0097] Step 2: Input the sample images of the current batch into the convolutional neural network module to obtain one-dimensional feature data.
[0098] Step 3: Divide the one-dimensional feature data into multiple data segments, and input the data segments into multiple quantum circuits of the quantum layer module for calculation.
[0099] The quantum layer module can implement a parallel structured design for large blocks of data across different quantum computer nodes or across different bit processor regions within the same quantum computer. The quantum output layer of the quantum layer module can adopt a local full-amplitude measurement method.
[0100] This embodiment employs the concept of segmenting large data into data segments, enabling parallel processing of data segments across and within quantum computers. Quantum circuit data loading utilizes direct argument encoding; parameters in the quantum circuit layer can be configured to be shared within the same quantum computer, but not across different quantum computers, based on training requirements. The quantum measurement layer utilizes a localized bit full-amplitude measurement method, allowing the selection of measurement bit locations to be autonomously configured based on the dimensionality of the quantum layer's input data.
[0101] Step 4: Concatenate the output results of multiple quantum circuits to obtain a concatenated vector, and use the classification layer module to output the category prediction result corresponding to the concatenated vector.
[0102] Among them, the classification layer module is the fully connected layer classification module, which is used to define the loss function to iteratively optimize the training network parameters.
[0103] Step 5: In each round of training, the batch average cross entropy function is calculated based on the category prediction results and category labels where n bs is the size of the batch images in each round of training data, y i is the true classification label of the i-th image sample in the batch in each round of training, p i The probability that the image sample belongs to the true label, as predicted by the hybrid quantum neural network. From a theoretical analysis, the closer the cross entropy is to 0, the higher the prediction accuracy of the hybrid neural network. Iterate the rounds based on the cross entropy, return to step 1 to input the next round of batched image samples, and gradually update the parameters in the hybrid quantum neural network. Here, the backward propagation iteration parameters are selected. In this step, the gradient of the loss function with respect to each parameter (weight and bias) in the neural network is calculated. This is done by using the chain rule to propagate the error backward along each connection in the network. The error signal gradually propagates from the output layer back to the input layer. After updating the parameters and returning to the input layer, a new batch of training images is input, and the hybrid quantum neural network (i.e., image classification model) in steps 2-4 is repeated to obtain a new round of cross entropy until the maximum number of rounds set by the program is reached and the cross entropy value decreases and converges to a minimum value. The program ends, and finally, all parameter values in the hybrid quantum neural network are saved.
[0104] Step 6: Enter a test dataset independent of the training dataset, initialize a hybrid quantum neural network model identical to the training dataset, substitute the training parameter values obtained in Step 5 into the model, and obtain the classification corresponding to the maximum predicted probability value for the input image. Compare the predicted classification with the true classification; if the two are the same, the image classification is correct; otherwise, it is incorrect. Traverse all samples in the test dataset, record the number of correctly predicted samples, and divide by the total number of test samples to obtain the accuracy of the model's prediction of the samples. Using this scheme, for predicting test samples in the MNIST dataset of size 10,000, the accuracy is 98.50%, with an average cross-entropy of 0.0077, which is higher than the 94.1% classification accuracy mentioned in the related art.
[0105] Please refer to Figure 4, which is a structural diagram of an image classification model provided in an embodiment of the present application. The image classification model includes an input layer module, a convolutional neural network module, a quantum layer module, and a classification layer module. In the convolutional neural network module, after the image is input, a two-dimensional convolution operation, a maximum pooling operation, and a linear layer processing can be performed on the convolutional layer. After the output result of the convolutional neural network module enters the convolutional neural network module, it is processed using quantum circuit (1), quantum circuit (2), and quantum circuit (3). The numbers 1×28×28, 20×28×28, 20×14×14, 3920, 30, 10, 6, 18, and 10 in Figure 4 represent the size of the features.
[0106] In this embodiment, the convolutional neural network module may have relatively few convolutional layers and linear layers. The quantum layer module of this embodiment fully considers the current characteristics of quantum computer hardware: 1) Based on the number of bits of current quantum computing devices, a method of data splitting is proposed, and a method of parallel processing and calculation of quantum circuits with a small number of bits of multiple devices is adopted. This method can effectively reduce the influence of the decoherence factors of the quantum state caused by the excessive number of circuit bits and the excessive depth of gate circuit operations, thereby reducing the error of the final experimental measurement data, and can also improve the utilization rate of quantum computing device resources; 2) Based on the characteristics of quantum state entanglement and the experimental means of quantum measurement, a few single-bit full-amplitude spaces are selected for sampling measurement. The advantage is that while ensuring as much projection information as possible of the overall entangled state in the subspace, it can effectively avoid the reading error caused by the interference of the crosstalk signal when reading multiple bits at the same time.
[0107] In this embodiment, the convolutional neural network module and the classification layer module run on a classical computer, and the quantum layer module runs on a quantum computer. Please refer to Figure 5, which is a schematic diagram of a quantum circuit module parallel software computing device provided in an embodiment of the present application. The figure shows that after the sample image is processed by the convolutional neural network module of the classical computer, data is input into the quantum computer, and the quantum circuits 1 to n of the quantum layer module in the quantum computer are processed and the processing results are returned to the classification layer module of the classical computer.
[0108] This embodiment can be applied to the classification of the MNIST handwritten digit set and can also be ported to other image datasets. This embodiment uses a parallelized parameter-sharing quantum circuit layer within the convolutional neural network module, significantly improving data processing capabilities and efficiency while also significantly reducing the number of parameters required for training. This embodiment's "divide and conquer" approach of slicing large data blocks into smaller ones is of great significance for the era of noisy, medium-scale quantum computers. It not only addresses the current pain point of data requiring ultra-large bit counts, but also effectively reduces the depth of quantum circuits for ultra-large bit counts. The quantum layer module uses local full-amplitude measurements as output, demonstrating that globally entangled state information can be effectively projected and compressed into a subspace after being characterized by trained parameters, further proving that the quantum circuit layer is a highly entangled network. Compared to measuring the projection of bits in only one direction, local full-amplitude measurements in this embodiment effectively reduce the dimensionality of the quantum circuit output layer data while maintaining accuracy. From the perspective of quantum hardware readout, this embodiment's localized bit readout operation results in lower readout errors than reading all bits, as evidenced by fewer reads and fewer bit positions that need to be read simultaneously.
[0109] Please refer to Figure 6, which is a schematic diagram of the structure of an image classification system provided in an embodiment of the present application. The system can be applied to an electronic device running an image classification model, wherein the image classification model includes a convolutional neural network module, a quantum layer module, and a classification layer module. The image classification system includes:
[0110] A feature extraction module 601 is used to obtain a sample image and convert the sample image into one-dimensional feature data using the convolutional neural network module;
[0111] A parallel processing module 602 is configured to divide the one-dimensional feature data into multiple data segments and process all the data segments in parallel using multiple quantum circuits in the quantum layer module;
[0112] A prediction module 603 is configured to splice the output results of all the quantum circuits to obtain a spliced vector, and output a category prediction result corresponding to the spliced vector using the classification layer module;
[0113] A training module 604 is configured to calculate a loss function value based on the category prediction result and the category label of the sample image, and update network parameters of the convolutional neural network module and the quantum layer module based on the loss function value, so as to train the image classification model;
[0114] The classification module 605 is configured to, upon receiving an image recognition task, determine an unknown image corresponding to the image recognition task, and output an image category of the unknown image using the trained image classification model.
[0115] The image classification scheme provided in this embodiment is implemented based on an image classification model consisting of a convolutional neural network module, a quantum layer module, and a classification layer module. In the process of training the image classification model, this embodiment uses a convolutional neural network module to convert a sample image into one-dimensional feature data, divides the one-dimensional feature data into multiple data segments, and then uses multiple quantum circuits in the quantum layer module to process all the data segments in parallel. After being processed in sequence by the convolutional neural network module, the quantum layer module, and the classification layer module, this embodiment also uses a loss function value calculated based on the category prediction result and the category label of the sample image, and updates the network parameters of the convolutional neural network module and the quantum layer module based on the loss function value to achieve training of the image classification model. The quantum layer module in this embodiment uses multiple parallel quantum circuits to reduce the number of bits and the depth of the quantum circuit. After the image classification model is trained by the above scheme, using the image classification model to process image recognition tasks can improve the efficiency and accuracy of image classification.
[0116] Furthermore, the convolutional neural network module includes a convolutional layer, a pooling layer and a linear layer;
[0117] Correspondingly, the process in which the feature extraction module 601 uses the convolutional neural network module to convert the sample image into one-dimensional feature data includes: using the convolution layer to extract features from the sample image, and using the pooling layer to perform a maximum pooling operation on the output result of the convolution layer to obtain image feature information; and using the linear layer to perform dimensional transformation and linear combination on the image feature information to obtain the one-dimensional feature data with a preset length.
[0118] Furthermore, the process of the feature extraction module 601 using a convolutional layer to extract features from the sample image includes: determining the pixel information matrix corresponding to the sample image; if the number of rows and / or columns of the pixel information matrix is not an integer power of 2, filling the edges of the pixel information matrix with elements with a value of 0 to obtain a new pixel information matrix; wherein the number of rows and columns of the new pixel information matrix are both integer powers of 2; and using a convolutional layer to extract features from the new pixel information matrix.
[0119] Furthermore, the parallel processing module 602 utilizes multiple quantum circuits in the quantum layer module to process all the data fragments in parallel, including: distributing all the data fragments to the multiple quantum circuits according to a preset ratio; controlling each of the quantum circuits to process the distributed data fragments; wherein each of the quantum circuits includes a data encoding layer, an entanglement layer, and a measurement layer.
[0120] Furthermore, the parallel processing module 602 controls each quantum circuit to process the assigned data segment, including: using the data encoding layer to perform a phase encoding operation of a single-bit rotation gate on the assigned data segment to obtain an encoded quantum state; using the entanglement layer to process the encoded quantum state to obtain an entangled quantum state containing training parameters; wherein the entanglement layer includes a parameterized single-bit arbitrary rotation gate and a controlled NOT gate between two adjacent bits that are fully connected; and using the measurement layer to perform full-amplitude measurement on a preset number of the entangled quantum states containing the training parameters to obtain a single-bit Pauli matrix average value; wherein the full-amplitude measurement is an operation of measuring the quantum state projection value along the Pauli X matrix direction, the Pauli Y matrix direction, and the Pauli Z matrix direction respectively.
[0121] Furthermore, all the quantum circuits in the quantum layer module are respectively run on multiple quantum computers;
[0122] Correspondingly, it also includes:
[0123] A parameter sharing module is used to control all the quantum circuits running in the same quantum computer to share training parameters during the training of the image classification model.
[0124] Furthermore, the process of the prediction module 603 splicing the output results of all the quantum circuits to obtain the splicing vector includes: determining the fragment sequence number of each data fragment in the one-dimensional feature data; and splicing the output results of the quantum circuits corresponding to all the data fragments according to the fragment sequence number to obtain the splicing vector.
[0125] Since the embodiments of the system part correspond to the embodiments of the method part, please refer to the description of the embodiments of the method part for the embodiments of the system part, and will not be repeated here.
[0126] The present application also provides a storage medium having a computer program stored thereon, which, when executed, can implement the steps provided in the above embodiments. The storage medium may include: a USB flash drive, a mobile hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, among other media capable of storing program code.
[0127] The present application also provides an electronic device that may include a memory and a processor, wherein the memory stores a computer program, and when the processor calls the computer program in the memory, the steps provided in the above embodiment can be implemented. Of course, the electronic device may also include various network interfaces, a power supply, and other components.
[0128] The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referred to each other. For the system disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of this application, several improvements and modifications can be made to this application, and these improvements and modifications also fall within the scope of protection of the claims of this application.
[0129] It should also be noted that, in this specification, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus comprising the element.
Claims
1. An image classification method, characterized in that: Applied to an electronic device running an image classification model, the image classification model includes a convolutional neural network module, a quantum layer module and a classification layer module, and the image classification method includes: Acquire a sample image, and convert the sample image into one-dimensional feature data using the convolutional neural network module; The one-dimensional feature data is divided into multiple data segments, and all the data segments are processed in parallel using multiple quantum circuits in the quantum layer module; splicing the output results of all the quantum circuits to obtain a splicing vector, and using the classification layer module to output a category prediction result corresponding to the splicing vector; Calculating a loss function value according to the category prediction result and the category label of the sample image, and updating network parameters of the convolutional neural network module and the quantum layer module according to the loss function value, so as to train the image classification model; If an image recognition task is received, an unknown image corresponding to the image recognition task is determined, and the image category of the unknown image is output using the trained image classification model.
2. The image classification method according to claim 1, characterized in that: The convolutional neural network module includes a convolutional layer, a pooling layer and a linear layer; Accordingly, the sample image is converted into one-dimensional feature data using the convolutional neural network module, including: Using the convolution layer to extract features from the sample image, and using the pooling layer to perform a maximum pooling operation on an output result of the convolution layer to obtain image feature information; The linear layer is used to perform dimension transformation and linear combination on the image feature information to obtain the one-dimensional feature data with a length of a preset value.
3. The image classification method according to claim 2, characterized in that: The extracting features of the sample image by using a convolutional layer includes: Determine a pixel information matrix corresponding to the sample image; If the number of rows and / or columns of the pixel information matrix is not an integer power of 2, fill the edge of the pixel information matrix with elements having a value of 0 to obtain a new pixel information matrix; wherein the number of rows and the number of columns of the new pixel information matrix are both integer powers of 2; The convolutional layer is used to extract features from the new pixel information matrix.
4. The image classification method according to claim 1, characterized in that: Utilizing multiple quantum circuits in the quantum layer module to process all the data fragments in parallel includes: Allocating all the data fragments to the plurality of quantum circuits according to a preset ratio; Each of the quantum circuits is controlled to process the allocated data fragments; wherein each of the quantum circuits includes a data encoding layer, an entanglement layer and a measurement layer.
5. The image classification method according to claim 4, characterized in that: Controlling each of the quantum circuits to process the allocated data fragments, comprising: Using the data coding layer to perform a phase coding operation of a single-bit rotary gate on the allocated data fragment to obtain a coded quantum state; The encoded quantum state is processed by using the entanglement layer to obtain an entangled quantum state containing training parameters; wherein the entanglement layer includes a parameterized single-bit arbitrary rotation gate and a fully connected controlled NOT gate between two adjacent bits; The measurement layer is used to perform full amplitude measurement on a preset number of entangled quantum states containing training parameters to obtain a single-bit Pauli matrix average value; wherein the full amplitude measurement is an operation of measuring the quantum state projection value along the Pauli X matrix direction, the Pauli Y matrix direction and the Pauli Z matrix direction respectively.
6. The image classification method according to claim 1, characterized in that: All the quantum circuits in the quantum layer module are respectively run on multiple quantum computers; Accordingly, the process of training the image classification model also includes: Controlling all the quantum circuits running in the same quantum computer to share training parameters.
7. The image classification method according to any one of claims 1 to 6, characterized in that: The output results of all the quantum circuits are spliced to obtain a spliced vector, including: Determine a fragment sequence number of each of the data fragments in the one-dimensional feature data; The output results of the quantum circuits corresponding to all the data fragments are spliced according to the fragment sequence numbers to obtain the splicing vector.
8. An image classification system, characterized in that: Applied to an electronic device running an image classification model, the image classification model includes a convolutional neural network module, a quantum layer module and a classification layer module, and the image classification system includes: A feature extraction module, used to obtain a sample image and convert the sample image into one-dimensional feature data using the convolutional neural network module; A parallel processing module, used for dividing the one-dimensional feature data into multiple data segments, and using multiple quantum circuits in the quantum layer module to process all the data segments in parallel; A prediction module, used for splicing the output results of all the quantum circuits to obtain a splicing vector, and using the classification layer module to output a category prediction result corresponding to the splicing vector; A training module, used to calculate a loss function value according to the category prediction result and the category label of the sample image, and update the network parameters of the convolutional neural network module and the quantum layer module according to the loss function value, so as to train the image classification model; The classification module is used to determine the unknown image corresponding to the image recognition task if an image recognition task is received, and output the image category of the unknown image using the trained image classification model.
9. An electronic device, characterized in that: include: A memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the image classification method according to any one of claims 1 to 7 when calling the computer program in the memory.
10. A storage medium, characterized in that: The storage medium stores computer executable instructions, and when the computer executable instructions are loaded and executed by the processor, the steps of the image classification method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Quantum image recognition method and device
CN114792378A
Image recognition method and device based on quantum classical hybrid neural network
CN114821217A
Picture classification method and device, electronic equipment and storage medium
CN116912556A
Image classification method and system, electronic equipment and storage medium
CN117437494A
Category learning neural networks
US20200027002A1
Cited By
Quantum-classical hybrid network for data classification and task processing method
CN120598069A
Image processing method and device, equipment, medium and product
CN120747545A
Mixed quantum ensemble learning and MedMama collaborative medical image classification method
CN120912982A