Image classification methods, devices, storage media and electronic devices
By encoding and evolving image features using quantum states, the problem of quantum computing resource consumption in image classification is solved, and efficient resource utilization is achieved.
Patent Information
- Application Number
- CN202410332783.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-22
- Publication Date
- 2026-11-17
- Estimated Expiration
- 2044-03-22
AI Technical Summary
In existing technologies, image classification processes consume a significant amount of quantum computing resources on quantum computers, primarily due to the high dimensionality of image pixel data, which results in a large number of qubits required for encoding.
By acquiring image features, a quantum feature encoder based on the FRQI feature encoding algorithm is used to encode the image features into quantum states. The quantum state features are then evolved through variable quantum circuits, and finally, the quantum state is measured to determine the image category, thus reducing the consumption of quantum computing resources.
It effectively reduces the consumption of quantum computing resources in the image classification process. By encoding and evolving the quantum states of image features, it reduces the number of qubits required for encoding and improves resource utilization efficiency.
Smart Images

Figure CN118196509B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of quantum computing technology, and in particular relates to an image classification method, apparatus, storage medium and electronic device. Background Technology
[0002] A quantum computer is a physical device that performs high-speed mathematical and logical operations, stores and processes quantum information in accordance with the laws of quantum mechanics. When a device processes and calculates quantum information and runs quantum algorithms, it is a quantum computer. Because of its ability to process mathematical problems more efficiently than ordinary computers—for example, reducing the time to crack RSA keys from hundreds of years to hours—quantum computers have become a key technology under research.
[0003] Flexible Representation of Quantum Image (FRQI) is an image coding technique that achieves quantum state superposition encoding of image pixels, reducing the number of qubits required for encoding to the log n level of a qubit lattice. A quantum classifier is a classifier implemented using quantum simulations. Some works encode images using FRQI and then feed them into a quantum classifier for classification. Although the FRQI algorithm can reduce the number of qubits required for encoding to some extent, the high dimensionality of image pixel data means that achieving quantum state superposition encoding of images still requires a significant number of qubits for current quantum computers, resulting in current image classification processes consuming substantial quantum computing resources. Summary of the Invention
[0004] The purpose of this invention is to provide an image classification method, apparatus, storage medium, and electronic device, which aims to reduce the consumption of quantum computing resources during the image classification process.
[0005] To achieve the above objectives, a first aspect of the present invention provides an image classification method, the method comprising:
[0006] Obtain the image features of the image to be classified;
[0007] The image features are quantum-state encoded using a quantum feature encoder to obtain quantum state features. The quantum feature encoder is constructed based on the Flexible Representation of Quantum Images (FRQI) feature encoding algorithm.
[0008] Quantum state evolution is performed based on the quantum state characteristics obtained by encoding the quantum state using variable quantum circuits.
[0009] The quantum state of the variable quantum circuit after evolution is measured, and the image category of the image to be classified is determined based on the evolved quantum state.
[0010] In one possible implementation, the step of quantum-state encoding the image features based on the quantum feature encoder to obtain quantum state features includes:
[0011] The normalized feature values of the image features are encoded into numerical qubits, and the quantum state of the encoded numerical qubits is multiplied by the quantum state of the index qubits to obtain quantum state features. The quantum state of the index qubits is used to indicate the position of the normalized features encoded by the numerical qubits.
[0012] In one possible implementation, the quantum feature encoder includes an H gate acting on each of the index qubits and an RY gate acting on the numerical qubits, the RY gate being controlled by each of the index qubits, and the rotation parameter of the RY gate being a normalized feature value of the image feature.
[0013] In one possible implementation, before encoding the normalized feature values of the image features into numerical qubits, the method further includes:
[0014] Calculate the mean and variance of the feature values of each dimension of the image features;
[0015] The normalized feature values of each dimension of the image feature are calculated based on the mean and the variance to obtain the normalized feature values.
[0016] In one possible implementation, the normalization calculation of each dimension feature value of the image feature based on the mean and the variance to obtain the normalized feature value includes:
[0017] The layer norm of each dimension of the image feature is calculated based on the mean and the variance, and the layer norm is used to represent the normalized value of the layer.
[0018] The normalized eigenvalues are obtained by normalizing the values based on the maximum and minimum values of the layer norm.
[0019] In one possible implementation, the tensor product calculation of the quantum state of the encoded numerical qubit and the quantum state of the index qubit is specifically performed using the following formula:
[0020]
[0021] in, d represents the dimension of the image feature, |j> represents the quantum state of the index qubit, and |c j> represents the quantum state of a numerical qubit. Represents the tensor product.
[0022] In one possible implementation, obtaining the image features of the image to be classified includes:
[0023] The image to be classified is transformed to obtain high-dimensional tensor data of the image to be classified.
[0024] Feature extraction is performed on the high-dimensional tensor data using a classic feature extractor to obtain the image features of the image to be classified. The dimension of the image features of the image to be classified is smaller than that of the high-dimensional tensor data. The classic feature extractor is constructed based on a convolutional neural network or a Transformer network.
[0025] A second aspect of the present invention provides an image classification apparatus, the apparatus comprising:
[0026] The acquisition module is used to acquire the image features of the image to be classified.
[0027] The encoding module is used to perform quantum state encoding on the image features based on the quantum feature encoder to obtain quantum state features. The quantum feature encoder is constructed based on the FRQI feature encoding algorithm of the flexible representation of quantum images.
[0028] The evolution module is used to perform quantum state evolution based on the quantum state characteristics obtained by encoding the quantum state using variable quantum circuits;
[0029] The determination module is used to measure the quantum state after the evolution of the variable quantum circuit, and determine the image category of the image to be classified based on the evolved quantum state.
[0030] A third aspect of the present invention provides a storage medium storing a computer program, wherein the computer program is configured to execute the steps of the method described in any one of the first aspects above when running.
[0031] A fourth aspect of the present invention provides an electronic device including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps of the method described in any of the first aspects above.
[0032] Based on the above technical solution, image features of the image to be classified are first acquired; then, quantum state encoding of the image features is performed based on a quantum feature encoder. The quantum feature encoder is constructed based on the FRQI feature encoding algorithm, which realizes quantum state encoding of the image to be classified. Compared with the existing technology of directly encoding the image pixels into quantum states, since the dimension of the image features is much smaller than the dimension of the image pixels, encoding the image features of the image to be classified can effectively reduce the number of qubits required for encoding. Then, the quantum state evolution of the quantum state encoded image features is performed based on a variable quantum circuit; the quantum state after the evolution of the variable quantum circuit is measured, and the image category is determined based on the measurement results, which can reduce the occupation of quantum computing resources. Attached Figure Description
[0033] Figure 1 This is a network block diagram of an image classification system according to an exemplary embodiment.
[0034] Figure 2 This is a flowchart illustrating an image classification method according to an exemplary embodiment.
[0035] Figure 3 This is a schematic diagram illustrating a process for acquiring image features of an image to be classified, according to an exemplary embodiment.
[0036] Figure 4 This is a schematic diagram of a variable quantum circuit according to an exemplary embodiment.
[0037] Figure 5 This is a schematic diagram of a quantum circuit for a quantum feature encoder according to an exemplary embodiment.
[0038] Figure 6 This is a block diagram illustrating an image classification apparatus according to an exemplary embodiment.
[0039] Figure 7 This is a block diagram illustrating a computer device according to an exemplary embodiment. Detailed Implementation
[0040] The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.
[0041] Figure 1 This is a network block diagram of an image classification system provided in an embodiment of the present invention. The image classification system may include a network 110, a server 120, a wireless device 130, a client 140, storage 150, a classical computing unit 160, a quantum computing unit 170, and may also include additional memory, a classical processor, a quantum processor, and other devices not shown.
[0042] Network 110 is a medium used to provide communication links between various devices and computers connected together within an image classification system, including but not limited to the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. The connection method can be wired, wireless communication links, or fiber optic cables.
[0043] Server 120, wireless device 130, and client 140 are conventional data processing systems that may contain data and application programs or software tools that perform conventional computational processes. Client 140 may be a personal computer or a network computer, so the data may also be provided by server 120. Wireless device 130 may be a smartphone, tablet, laptop, smart wearable device, etc. Storage unit 150 may include database 151, which can be configured to store data such as qubit parameters, quantum logic gate parameters, quantum circuits, and quantum programs.
[0044] The classical computing unit 160 (quantum computing unit 170) may include a classical processor 161 (quantum processor 171) for processing classical data (quantum data) and a memory 162 (memory 172) for storing classical data (quantum data). The classical data (quantum data) may be a boot file, an operating system image, and an application program 163 (application program 173). The application program 163 (application program 173) may be used to implement a quantum algorithm compiled by the image classification method provided in the embodiment of the present invention.
[0045] Any data or information stored or generated in the classical computing unit 160 (quantum computing unit 170) can also be configured to be stored or generated in another classical (quantum) processing system in a similar manner, and any application executed therein can also be configured to be executed in another classical (quantum) processing system in a similar manner.
[0046] It should be noted that a true quantum computer has a hybrid structure, which includes at least... Figure 1 The system consists of two main parts: the classical computing unit 160, which is responsible for performing classical calculations and control; and the quantum computing unit 170, which is responsible for running quantum programs to achieve quantum computing.
[0047] The aforementioned classical computing unit 160 and quantum computing unit 170 can be integrated into a single device or distributed across two different devices. For example, a first device including the classical computing unit 160 runs a classical computer operating system, providing quantum application development tools and services, as well as the storage and network services required for quantum applications. Users develop quantum programs using the quantum application development tools and services on the second device, and send these quantum programs to a second device including the quantum computing unit 170 via the network services. The second device runs a quantum computer operating system, which parses and compiles the quantum program's code into instructions that the quantum processor 170 can recognize and execute. The quantum processor 170 then implements the quantum algorithm corresponding to the quantum program based on these instructions.
[0048] The computing units of the classic processor 161 within the classic computing unit 160 are based on CMOS transistors on a silicon chip. These computing units are not limited by time or coherence; that is, they are available at any time without time constraints. Furthermore, the number of such computing units in a silicon chip is sufficient; currently, a single classic processor 161 contains tens of thousands of computing units. Given this sufficient number of computing units and the fixed selectable computing logic of the CMOS transistors (e.g., AND logic), computational performance is achieved by combining a large number of CMOS transistors with a limited set of logic functions during operation.
[0049] In the quantum computing unit 170, the basic computing unit of the quantum processor 171 is the qubit. The input of a qubit is limited by coherence and coherence time; that is, a qubit is limited by its available usage time and is not always readily available. Making full use of qubits within their available usage time is a key challenge in quantum computing. Furthermore, the number of qubits in a quantum computer is one of the representative indicators of its performance. Each qubit performs computational functions through on-demand configured logical functions. Given the limited number of qubits and the diverse logical functions available in quantum computing, such as Hadamard gates (H gates), Pauli-X gates (X gates), Pauli-Y gates (Y gates), Pauli-Z gates (Z gates), X gates, RY gates, RZ gates, CNOT gates, CR gates, iSWAP gates, Tofoli gates, etc., quantum computing requires combining a limited number of qubits with diverse logical function combinations to achieve computational effects.
[0050] Based on these differences, the design of classical logic functions applied to CMOS transistors and the design of quantum logic functions applied to qubits are significantly and fundamentally different. The design of classical logic functions applied to CMOS transistors does not need to consider the individuality of CMOS transistors. For example, the representation of a CMOS transistor in a silicon chip is its individual identifier, location, and usable time of each CMOS transistor. Therefore, classical algorithms composed of classical logic functions only express the operational relationship of the algorithm, not the algorithm's dependence on individual CMOS transistors.
[0051] Quantum logic functions applied to qubits need to consider the individuality of each qubit, such as its position within the quantum chip, its relationship with surrounding qubits, and the duration of its usable time. Therefore, quantum algorithms composed of quantum logic functions not only express the computational relationships within the algorithm but also its dependence on the individual qubits.
[0052] For example:
[0053] Quantum Algorithm 1: H1, H2, CNOT(1,3), H3, CNOT(2,3);
[0054] Quantum Algorithm 2: H1, H2, CNOT(1,2), H3, CNOT(2,3);
[0055] Quantum Algorithm 1 and Quantum Algorithm 2 use a combination of quantum logic gates and Arabic numerals to represent the qubits that function under the quantum logic gates. The Arabic numerals 1, 2, and 3 can represent three qubits Q1, Q2, and Q3 connected in sequence or qubits Q1, Q2, and Q3 connected to each other.
[0056] An exemplary explanation of how quantum algorithms are affected by the coherence time of qubits is as follows:
[0057] Define the execution time of a single-qubit logic gate as t, and the execution time of two single-qubit logic gates operating on adjacent qubits as 2t; then:
[0058] When Q1, Q2, and Q3 are interconnected, the computation of Quantum Algorithm 1 requires 6t, which is divided into 4 time periods. The duration of each time period is t, 2t, t, and 2t, respectively. The operations performed in each time period are: H1, H2; CNOT(1,3); H3; CNOT(2,3);
[0059] The computation of Quantum Algorithm 1 requires 5t, which is divided into 3 time periods. The duration of each time period is t, 2t, and 2t respectively. The operations performed in each time period are: H1, H2, H3; CNOT(1,2); CNOT(2,3);
[0060] When Q1, Q2, and Q3 are connected sequentially, Quantum Algorithm 1 needs to be equivalent to: H1, H2; swap(1,2), CNOT(2,3), swap(1,2); H3; CNOT(2,3). The computation of the equivalent Quantum Algorithm 1 requires 10t, divided into 4 time periods, with each time period requiring durations of t, 6t, t, and 2t respectively. The operations performed in each time period are: H1, H2; swap(1,2), CNOT(2,3), swap(1,2); H3; CNOT(2,3).
[0061] Therefore, the application of quantum logic functions in the design of qubits (including the design of whether qubits are used and the design of the efficiency of each qubit) is key to improving the computational performance of quantum computers and requires special design. This is the unique characteristic of quantum algorithms based on quantum logic functions, and is fundamentally and significantly different from classical algorithms based on classical logic functions. The aforementioned design considerations for qubits are technical problems that ordinary computing devices do not need to consider or address. This invention proposes an image classification method, apparatus, storage medium, and electronic device to reduce the consumption of quantum computing resources during image classification.
[0062] See Figure 2 , Figure 2 This is a flowchart illustrating an image classification method according to an exemplary embodiment. The method includes the following steps:
[0063] S201. Obtain the image features of the image to be classified.
[0064] Specifically, it can be implemented as follows:
[0065] Step 1: Perform image transformation on the image to be classified to obtain high-dimensional tensor data of the image to be classified.
[0066] In this embodiment of the invention, a batch of images to be classified can be transformed to obtain high-dimensional tensor data data with dimensions b×c×h×w, where b is the number of images to be classified in a batch, c is the number of channels of the images to be classified, h is the height of the images to be classified, and w is the width of the images to be classified.
[0067] Step 2: Extract features from the high-dimensional tensor data using a classic feature extractor to obtain the image features of the image to be classified.
[0068] In this embodiment of the invention, the high-dimensional tensor data data obtained in step one above can be input into a classic feature extractor to extract features to obtain image features of dimension b×d, where b is the number of data in a batch and d is the dimension of the output features.
[0069] Wherein, the image feature dimension of the image to be classified is smaller than that of the high-dimensional tensor data, and the classic feature extractor is constructed based on a convolutional neural network or a Transformer network.
[0070] like Figure 3 As shown, Figure 3 This is a flowchart illustrating a process for obtaining image features of images to be classified, provided by an embodiment of the present invention. First, a batch of images to be classified are transformed to obtain high-dimensional tensor data data with dimensions b×c×h×w. Then, the high-dimensional tensor data data is input into a classic feature extractor to obtain image features features with dimensions b×d.
[0071] In existing technologies, the encoding of images to be classified is usually based on pixels. For images to be classified, the data dimension of pixels is very high. The embodiments of the present invention transform the high-dimensional pixel data into high-dimensional tensor data by performing data transformation on the images to be classified. Then, a classic feature extractor is used to extract image features with a dimension smaller than that of the high-dimensional tensor data from the high-dimensional tensor data, thereby achieving data dimensionality reduction. Subsequently, the image features can be encoded to achieve the encoding of the images to be classified, which can effectively reduce the amount of data to be encoded for the images to be classified.
[0072] S202. The image features are quantum-state encoded based on the quantum feature encoder to obtain quantum state features.
[0073] The quantum feature encoder is constructed based on the FRQI feature encoding algorithm, which is a flexible representation of quantum images.
[0074] In existing FRQI methods, the quantum state of each pixel block can be represented using any quantum state representation method, such as ground state encoding, phase encoding, etc. FRQI methods have several advantages in quantum image processing, such as the ability to perform image compression without distortion.
[0075] In existing technologies, FRQI methods mainly encode the pixels of the image to be classified. Since the pixel data of the image to be classified has a high dimensionality, the number of qubits required for encoding is large. The image features of the image to be classified are obtained through the method in S201. The above-mentioned quantum feature encoder performs quantum state encoding on the image features to obtain quantum state features, which can be specifically implemented as follows:
[0076] The normalized feature values of the image features are encoded into numerical qubits, and the quantum state of the encoded numerical qubits is multiplied by the quantum state of the index qubits to obtain quantum state features. The quantum state of the index qubits is used to indicate the position of the normalized features encoded by the numerical qubits.
[0077] In this embodiment of the invention, the normalized feature values of the image features are encoded into numerical qubits, specifically using the following formula:
[0078] |c j >=cos(θ j )|0>+sin(θ j )|1>
[0079] Where, θ j |c represents the normalized feature value of the j-th dimension in the image features. j > represents the quantum state of a numerical qubit.
[0080] The tensor product is calculated by combining the quantum state of the encoded numerical qubit with the quantum state of the index qubit, specifically using the following formula:
[0081]
[0082] in, d represents the dimension of the image feature, |j> represents the quantum state of the index qubit, and |c j > represents the quantum state of a numerical qubit. Represents the tensor product.
[0083] S203. Perform quantum state evolution on the quantum state characteristics obtained by encoding the quantum state based on the variable quantum circuit.
[0084] Variational Quantum Circuit (VQC) is a machine learning model based on quantum computing. It constructs an adjustable parameterized quantum circuit using qubits and quantum gates, and then uses classical optimization algorithms to optimize these parameters, thereby achieving learning and prediction for specific tasks.
[0085] In VQC, the parameters of the quantum circuit are considered as trainable parameters of the model. By optimizing these parameters, the model can exhibit better performance on a specific task. VQC is commonly used for classification and regression tasks, where input data is encoded as the states of qubits, and the quantum circuit processes the input data and outputs predictions.
[0086] In a specific implementation, such as Figure 4 As shown, Figure 4 This is a schematic diagram of a variable quantum circuit provided in an embodiment of the present invention. Figure 4 The variable quantum circuit shown includes a first RZ gate, a first RY gate, and a second RZ gate acting sequentially on each qubit, a CNOT gate acting on adjacent qubits, a third RZ gate, a second RY gate, and a fourth RZ gate acting on each qubit.
[0087] S204. Measure the quantum state after the evolution of the variable quantum circuit, and determine the image category based on the evolved quantum state.
[0088] In this embodiment of the invention, each index qubit and the numerical qubit jointly encodes the quantum state characteristics. The evolved quantum state can be obtained by measuring the evolution of each index qubit and the numerical qubit through a variable quantum circuit.
[0089] Specifically, the number of qubits measured is the same as the number of image categories to be classified.
[0090] For example, if the image to be classified includes three different image categories, three qubits can be selected from the index qubits and numerical qubits for measurement to obtain the evolved quantum state.
[0091] Each measured qubit corresponds to an image category. The quantum state probabilities of the three qubits are calculated using the softmax function. The image category corresponding to the qubit with the highest quantum state probability is the image category of the image to be classified.
[0092] In this embodiment of the invention, image features of the image to be classified are first acquired; then, quantum state encoding of the image features is performed based on a quantum feature encoder. The quantum feature encoder is constructed based on the FRQI feature encoding algorithm, which realizes quantum state encoding of the image to be classified. Compared with the prior art of directly encoding the quantum state of image pixels, since the dimension of image features is much smaller than the dimension of image pixels, encoding the image features of the image to be classified can effectively reduce the number of qubits required for encoding. Then, the quantum state evolution of the quantum state-encoded image features is performed based on a variable quantum circuit; the quantum state after the evolution of the variable quantum circuit is measured, and the image category is determined based on the measurement results, which can reduce the occupation of quantum computing resources.
[0093] The structure of the quantum feature encoder provided in the above embodiments is described below. The quantum feature encoder provided by the present invention includes an H gate acting on each index qubit and an RY gate acting on the numerical qubit. The RY gate is controlled by each index qubit, and the rotation parameter of the RY gate is the normalized feature value of the image feature.
[0094] Among them, the H gate is used to convert the initial quantum state of each index qubit into a superposition quantum state, and the RY gate is a multi-control gate that is controlled by the quantum state of each index qubit and acts on the numerical qubit.
[0095] like Figure 5 As shown, Figure 5This is a schematic diagram of the quantum circuit of a quantum feature encoder provided in an embodiment of the present invention. Figure 5 This includes H gates acting on each index qubit and RY gates acting on the numerical qubits. Figure 5 The rotation parameters of the three RY gates shown are θ0, θ1 and θ2, where θ0, θ1 and θ2 represent normalized feature values of the image features of the image to be classified.
[0096] In this embodiment of the invention, by applying an H gate to each index qubit, the quantum state of the index qubit is evolved into a quantum superposition state. The RY gate is controlled by each index qubit and acts on the numerical qubit. The rotation parameter of the RY gate is the normalized feature value of the image feature, thereby encoding the normalized feature value of the image feature into the numerical qubit. The quantum state of the index qubit indicates the position of the normalized feature encoded by the numerical qubit, thus realizing the quantum state encoding of the normalized feature value of the image feature.
[0097] The following describes the specific method for normalizing image features in the above embodiments. In another embodiment of the present invention, before encoding the normalized feature values of the image features into numerical qubits, the method further includes:
[0098] Step 1: Calculate the mean and variance of the feature values of each dimension of the image feature.
[0099] Step 2: Normalize the feature values of each dimension of the image feature based on the mean and the variance to obtain the normalized feature values.
[0100] Step two can be specifically implemented as follows:
[0101] The layer norm of each dimension of the image feature is calculated based on the mean and the variance. The layer norm is used to represent the normalized value of the layer. Normalization is performed based on the maximum and minimum values of the layer norm to obtain the normalized feature value.
[0102] The formula for calculating the layer norm is as follows:
[0103]
[0104] Among them, f j Let μ represent the j-th dimension feature value in the image feature, μ represent the mean of each dimension feature value in the image feature, σ represent the variance of each dimension feature value in the image feature, and γ and β represent the parameters to be learned.
[0105] In the field of image processing, the aforementioned layer norm can be expressed as LayerNorm, which is used to represent the normalized value of a layer.
[0106] The normalized eigenvalues are calculated using the following formula:
[0107]
[0108] In this embodiment of the invention, the j-th dimension feature value f of the image feature can be calculated using the above-mentioned layer norm calculation formula and normalized feature value calculation formula. j Normalization to Within the range, the normalized eigenvalue of the j-th dimension is obtained.
[0109] This invention calculates the mean and variance of the feature values of each dimension of the image features, calculates the layer norm of each feature value based on the mean and variance, and then performs normalization calculation based on the maximum and minimum values of each layer norm to obtain normalized feature values. This normalizes the magnitude of each feature value in the image features to the same range, avoiding the direct encoding of the maxima and minima in the image features into quantum state features, eliminating the influence of the maxima and minima in the image features on the image classification task, and improving the accuracy of image classification.
[0110] The training process of the classical feature extractor and variable quantum circuit in the above embodiments will be explained below with reference to specific procedures.
[0111] Step 1: Initialize the parameters in the variable quantum circuit.
[0112] Step 2: Perform FRQI quantum encoding on the input image features.
[0113] Step 3: Perform quantum state evolution on the encoded quantum state features based on variable quantum circuits.
[0114] Step 4: Perform quantum measurements on the evolution results to obtain the measurement results. The number of qubits measured corresponds to the number of image categories. Each qubit corresponds to one image category, and the number of image categories does not exceed the number of qubits.
[0115] Step 5: Calculate the loss value by comparing the measurement results with the true values using the cross-entropy function.
[0116] Step 6: Calculate the gradients of the parameters in the variable quantum circuit and the classical feature extractor using the parameter shift method and the automatic differentiation method, respectively, and then optimize the parameters using the gradient descent method.
[0117] The application process of the classic feature extractor and variable quantum circuit in the above embodiments is explained below with reference to specific procedures.
[0118] Step 1: Initialize the parameters in the variable quantum circuit.
[0119] Step 2: Perform FRQI quantum encoding on the input image features.
[0120] Step 3: Perform quantum state evolution on the encoded quantum state features based on variable quantum circuits.
[0121] Step 4: Perform quantum measurements on the quantum state evolution results to obtain the measurement results.
[0122] Step 5: Calculate the probability of each image category using the softmax function. The category with the highest probability is the image category of the image to be classified.
[0123] Based on the same inventive concept, embodiments of the present invention also provide an image classification device, such as... Figure 6 As shown, the device includes:
[0124] The acquisition module 601 is used to acquire the image features of the image to be classified.
[0125] The encoding module 602 is used to perform quantum state encoding on the image features based on the quantum feature encoder to obtain quantum state features. The quantum feature encoder is constructed based on the FRQI feature encoding algorithm, which is a flexible representation of quantum images.
[0126] Evolution module 603 is used to perform quantum state evolution based on the quantum state characteristics obtained by encoding the quantum state using variable quantum circuits.
[0127] The determination module 604 is used to measure the quantum state after the evolution of the variable quantum circuit, and determine the image category of the image to be classified based on the evolved quantum state.
[0128] The specific functions and effects of the image classification device can be explained by referring to other embodiments in this specification, and will not be repeated here. Each module in the image classification device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0129] Please see Figure 7 This specification also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the image classification method of any of the above embodiments. Please refer to... Figure 7 The computer device can be a classical computer or a quantum computer.
[0130] This specification also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a computer, causes the computer to perform the image classification method of any of the above embodiments.
[0131] This specification also provides a computer program product containing instructions that, when executed by a computer, cause the computer to perform the image classification method described in any of the above embodiments.
[0132] It is understood that the specific examples in this specification are only intended to help those skilled in the art better understand the implementation methods described herein, and are not intended to limit the scope of the invention.
[0133] It is understood that in the various embodiments of this specification, the sequence number of each process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not limit the implementation process of the embodiments of this specification in any way.
[0134] It is understood that the various implementation methods described in this specification can be implemented individually or in combination, and the implementation methods in this specification are not limited in this respect.
[0135] Unless otherwise stated, all technical and scientific terms used in the embodiments of this specification have the same meaning as commonly understood by one of ordinary skill in the art. The terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the scope of this specification. The term "and / or" as used in this specification includes any and all combinations of one or more of the associated listed items. The singular forms "a," "the," and "the" as used in the embodiments of this specification and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise.
[0136] It is understood that the processor in the embodiments of this specification can be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method embodiments can be completed by integrated logic circuits in the processor's hardware or by instructions in software form. The processor can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this specification. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this specification can be directly implemented by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory; the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above methods.
[0137] It is understood that the memory in the embodiments of this specification may be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. Non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory may be random access memory (RAM). It should be noted that the memory in the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0138] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this specification.
[0139] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the aforementioned method implementations, and will not be repeated here.
[0140] In the several embodiments provided in this specification, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0141] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0142] In addition, the functional units in the various embodiments of this specification can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0143] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of this specification, in essence, or the parts that contribute to the prior art, or parts of the technical solutions, can be embodied in the form of software products. These computer software products are stored in a storage medium and include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this specification. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0144] The above description is merely a specific embodiment of this specification, but the scope of protection of this invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this specification should be included within the scope of protection of this specification. Therefore, the scope of protection of this invention should be determined by the scope of the claims.
Claims
1. An image classification method, characterized in that, The method includes: Obtaining image features of an image to be classified includes: performing image transformation on the image to be classified to obtain high-dimensional tensor data of the image to be classified; extracting features from the high-dimensional tensor data based on a classical feature extractor to obtain image features of the image to be classified, wherein the dimension of the image features of the image to be classified is smaller than that of the high-dimensional tensor data, and the classical feature extractor is constructed based on a convolutional neural network or a Transformer network. The image features are quantum-state encoded based on a quantum feature encoder to obtain quantum state features. The quantum feature encoder is constructed based on the Flexible Representation of Quantum Images (FRQI) feature encoding algorithm, and includes: encoding the normalized feature values of the image features into numerical qubits, and performing tensor product calculation on the quantum state of the encoded numerical qubits and the quantum state of the index qubits to obtain quantum state features. The quantum state of the index qubits is used to indicate the position of the normalized features encoded by the numerical qubits. Quantum state evolution is performed based on the quantum state characteristics obtained by encoding the quantum state using variable quantum circuits. The quantum state of the variable quantum circuit after evolution is measured, and the image category of the image to be classified is determined based on the evolved quantum state.
2. The method according to claim 1, characterized in that, The quantum feature encoder includes an H gate acting on each of the index qubits and an RY gate acting on the numerical qubits. The RY gate is controlled by each of the index qubits, and the rotation parameter of the RY gate is the normalized feature value of the image feature.
3. The method according to claim 1, characterized in that, Before encoding the normalized feature values of the image features into numerical qubits, the method further includes: Calculate the mean and variance of the feature values of each dimension of the image features; The normalized feature values of each dimension of the image feature are calculated based on the mean and the variance to obtain the normalized feature values.
4. The method according to claim 3, characterized in that, The normalization calculation of each dimension feature value of the image feature based on the mean and the variance to obtain the normalized feature value includes: The layer norm of each dimension of the image feature is calculated based on the mean and the variance, and the layer norm is used to represent the normalized value of the layer. The normalized eigenvalues are obtained by normalizing the values based on the maximum and minimum values of the layer norm.
5. The method according to claim 1, characterized in that, The tensor product calculation, which involves combining the quantum states of the encoded numerical qubits with those of the index qubits, is performed using the following formula: in, , Dimensions representing image features The quantum state representing the index qubit. The quantum state representing a numerical qubit. Represents the tensor product.
6. An image classification device, characterized in that, The device includes: The acquisition module is used to acquire image features of an image to be classified, including: performing image transformation on the image to be classified to obtain high-dimensional tensor data of the image to be classified; and performing feature extraction on the high-dimensional tensor data based on a classical feature extractor to obtain image features of the image to be classified, wherein the dimension of the image features of the image to be classified is smaller than that of the high-dimensional tensor data, and the classical feature extractor is constructed based on a convolutional neural network or a Transformer network. An encoding module is used to encode the image features into quantum states based on a quantum feature encoder to obtain quantum state features. The quantum feature encoder is constructed based on the Flexible Representation of Quantum Images (FRQI) feature encoding algorithm and includes: encoding the normalized feature values of the image features into numerical qubits, and performing tensor product calculation on the quantum state of the encoded numerical qubits and the quantum state of the index qubits to obtain quantum state features. The quantum state of the index qubits is used to indicate the position of the normalized features encoded by the numerical qubits. The evolution module is used to perform quantum state evolution based on the quantum state characteristics obtained by encoding the quantum state using variable quantum circuits; The determination module is used to measure the quantum state after the evolution of the variable quantum circuit, and determine the image category of the image to be classified based on the evolved quantum state.
7. A storage medium, characterized in that, The storage medium stores a computer program, wherein the computer program is configured to execute the method described in any one of claims 1 to 5 when it is run.
8. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Quantum multichannel convolution line classification method, server, storage medium and system
CN116258886A
Method and system for performing quantum calculations in a quantum neural network and for implementing quantum neural networks
WO2023126866A1
