Quantum neural network classifier training method and apparatus, electronic device, and medium

By generating second sample data that simulates noise and attacks, the quantum neural network classifier is trained and optimized, which solves the problem of noise and attack influence during the training process and improves classification accuracy and resistance to attacks.

CN122368552APending Publication Date: 2026-07-10ORIGIN QUANTUM COMPUTING TECH (HEFEI) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411949871.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-27
Publication Date
2026-07-10

AI Technical Summary

Technical Problem

Existing quantum neural network classifiers are susceptible to noise and attacks during training, leading to biased classification results and reduced classification accuracy and resistance to attacks.

Method used

By generating second sample data based on the original data and preset perturbation coefficients, noise or attack scenarios are simulated to train and optimize the classifier to be trained. The classifier parameters are adjusted using the first and second sample data until convergence, thereby improving classification accuracy and resistance to attacks.

Benefits of technology

It effectively improves the classification accuracy and attack resistance of the trained quantum neural network classifier, and enhances its robustness against noise and attacks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122368552A_ABST
    Figure CN122368552A_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a quantum neural network classifier training method and device, electronic equipment and medium. The scheme is as follows: obtaining a training data set and a to-be-trained classifier; for each training sample data, classifying the training sample data by using the to-be-trained classifier to obtain a first predicted label; calculating a first loss value of the to-be-trained classifier according to a sample label corresponding to each training sample data and the first predicted label; when the to-be-trained classifier has not converged, adjusting the classifier parameters based on the first loss value, and returning to execute the step of classifying each training sample data by using the to-be-trained classifier to obtain the first predicted label corresponding to the training sample data until the to-be-trained classifier converges at the current time. Through the technical scheme provided by the embodiments of the present application, the optimization of the quantum neural network classifier is realized, and the classification accuracy and attack resistance of the quantum neural network classifier are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of quantum computing technology, and in particular to a method, apparatus, electronic device and medium for training a quantum neural network classifier. Background Technology

[0002] In the field of quantum computing, quantum neural network classifiers combine quantum computing with neural network classifiers, specifically utilizing qubits and quantum gate operations for data identification and classification. Currently, due to noise or attacks, the classification results of well-trained quantum neural network classifiers may be biased, thus affecting their classification accuracy. Summary of the Invention

[0003] The purpose of this application is to provide a method, apparatus, electronic device, and medium for training a quantum neural network classifier, so as to optimize the quantum neural network classifier and improve its classification accuracy and resistance to attacks. The specific technical solution is as follows:

[0004] This application provides a method for training a quantum neural network classifier, the method comprising:

[0005] Acquire a training dataset and a classifier to be trained. The training dataset includes multiple training sample data and a sample label corresponding to each training sample data. The training sample data includes first sample data and second sample data. The first sample data is quantum data generated based on the original data. The second sample data is generated based on the original data / first sample data and a preset perturbation coefficient. The original data is original image data or original initial state. The classifier to be trained is a quantum neural network classifier trained based on the first sample data.

[0006] For each training sample data, the training sample data is classified using the classifier to be trained to obtain the first predicted label corresponding to the training sample data.

[0007] The first loss value of the classifier to be trained is calculated based on the sample label and the first predicted label corresponding to each training sample data.

[0008] When the classifier to be trained has not converged, the classifier parameters of the classifier to be trained are adjusted based on the first loss value, and the process of classifying the training sample data using the classifier to be trained for each training sample data to obtain the first predicted label corresponding to the training sample data is returned, until the classifier to be trained converges at the current time.

[0009] This application embodiment also provides a quantum neural network classifier training device, the device comprising:

[0010] The acquisition module is used to acquire a training dataset and a classifier to be trained. The training dataset includes multiple training sample data and a sample label corresponding to each training sample data. The training sample data includes first sample data and second sample data. The first sample data is quantum data generated based on the original data. The second sample data is generated based on the original data / first sample data and a preset perturbation coefficient. The original data is original image data or original initial state. The classifier to be trained is a quantum neural network classifier trained based on the first sample data.

[0011] The classification module is used to classify each training sample data using the classifier to be trained, and obtain the first predicted label corresponding to the training sample data.

[0012] The calculation module is used to calculate the first loss value of the classifier to be trained based on the sample label and the first predicted label corresponding to each training sample data.

[0013] The adjustment module is used to adjust the classifier parameters of the classifier to be trained based on the first loss value when the classifier to be trained has not converged, and return to execute the step of classifying the training sample data using the classifier to be trained for each training sample data to obtain the first predicted label corresponding to the training sample data, until the classifier to be trained converges at the current time.

[0014] This application also provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;

[0015] Memory, used to store computer programs;

[0016] When a processor executes a program stored in memory, it implements any of the steps of the quantum neural network classifier method described above.

[0017] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of any of the quantum neural network classifier methods described above.

[0018] This application also provides a computer program product containing instructions that, when run on a computer, cause the computer to execute any of the quantum neural network classifier training methods described above.

[0019] Beneficial effects of the embodiments in this application:

[0020] The technical solution provided in this application embodiment can, after obtaining the training dataset and the classifier to be trained, classify each training sample data using the classifier to be trained to obtain the first predicted label corresponding to each training sample data. Then, based on the sample label and the first predicted label corresponding to each training sample data, calculate the first loss value of the classifier to be trained. If the classifier to be trained has not converged, adjust the classifier parameters of the classifier to be trained based on the first loss value, and continue to train and optimize the classifier to be trained based on the training sample data and sample labels until the classifier to be trained converges.

[0021] In the training process of the aforementioned classifier to be trained, the classifier to be trained is pre-trained based on the first sample data. On this basis, the second sample data in the training sample data is generated based on the preset perturbation coefficient and the original data / first sample data. Compared with the first sample data generated based on the original data, the second sample data can better simulate the existence of noise or attacks. Therefore, by using the training sample data including the first sample data and the second sample data to train the classifier to be trained, the classifier to be trained can be optimized, improving the classification accuracy and anti-attack resistance of the trained classifier to be trained.

[0022] Of course, implementing any product or method of this application does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description

[0023] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0024] Figure 1 A schematic diagram of the first flowchart of a quantum neural network classifier training method provided in an embodiment of this application;

[0025] Figure 2 A schematic diagram of the original image data provided in the embodiments of this application;

[0026] Figure 3-a This is a schematic diagram of a first structure of a classifier to be trained provided in an embodiment of this application;

[0027] Figure 3-b This is a schematic diagram of a second structure of a classifier to be trained provided in an embodiment of this application;

[0028] Figure 4-a This is a first schematic diagram of the test results of the model to be trained provided in an embodiment of this application;

[0029] Figure 4-b This is a second schematic diagram of the test results of the model to be trained provided in the embodiments of this application;

[0030] Figure 5 A flowchart illustrating a method for obtaining training datasets provided in an embodiment of this application;

[0031] Figure 6 A schematic diagram of a preset quantum circuit provided in an embodiment of this application;

[0032] Figure 7 This is a second flowchart illustrating the quantum neural network classifier training method provided in an embodiment of this application.

[0033] Figure 8 A schematic diagram of a quantum neural network classifier device provided in an embodiment of this application;

[0034] Figure 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0035] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0036] To address the problems in related technologies, embodiments of this application provide a method for training a quantum neural network classifier. For example... Figure 1 As shown, Figure 1 This is a schematic diagram of a first flowchart of a quantum neural network classifier training method provided in an embodiment of this application. The method includes the following steps.

[0037] Step S101: Obtain the training dataset and the classifier to be trained. The training dataset includes multiple training sample data and the sample label corresponding to each training sample data. The training sample data includes first sample data and second sample data. The first sample data is quantum data generated based on the original data. The second sample data is generated based on the original data / first sample data and a preset perturbation coefficient. The original data is the original image data or the original initial state. The classifier to be trained is a quantum neural network classifier trained based on the first sample data.

[0038] Step S102: For each training sample data, the training sample data is classified using the classifier to be trained to obtain the first predicted label corresponding to the training sample data.

[0039] Step S103: Calculate the first loss value of the classifier to be trained based on the sample label and the first predicted label corresponding to each training sample data.

[0040] Step S104: When the classifier to be trained has not converged, adjust the classifier parameters of the classifier to be trained based on the first loss value, and return to execute the step of classifying the training sample data using the classifier to be trained for each training sample data to obtain the first predicted label corresponding to the training sample data, until the classifier to be trained converges at the current time.

[0041] pass Figure 1 The method shown allows for the following steps after obtaining the training dataset and the classifier to be trained: classifying each training sample data using the classifier to obtain the first predicted label for each training sample data; calculating the first loss value of the classifier to be trained based on the sample label and the first predicted label for each training sample data; adjusting the classifier parameters based on the first loss value when the classifier to be trained has not converged; and continuing to train and optimize the classifier based on the training sample data and sample labels until the classifier to be trained converges.

[0042] In the training process of the aforementioned classifier to be trained, the classifier to be trained is pre-trained based on the first sample data. On this basis, the second sample data in the training sample data is generated based on the preset perturbation coefficient and the original data / first sample data. Compared with the first sample data generated based on the original data, the second sample data can better simulate the existence of noise or attacks. Therefore, by using the training sample data including the first sample data and the second sample data to train the classifier to be trained, the classifier to be trained can be optimized, improving the classification accuracy and anti-attack resistance of the trained classifier to be trained.

[0043] The embodiments of this application will be described below through specific examples.

[0044] Regarding step S101 above, namely obtaining the training dataset and the classifier to be trained, the training dataset includes multiple training sample data and the sample label corresponding to each training sample data. The training sample data includes first sample data and second sample data. The first sample data is quantum data generated based on the original data, and the second sample data is generated based on the original data / first sample data and a preset perturbation coefficient. The original data is the original image data or the original initial state. The classifier to be trained is a quantum neural network classifier trained based on the first sample data.

[0045] In this step, the electronic device can generate first sample data based on the original data (i.e., original image data or original initial state), and generate second sample data based on the original data and preset perturbation coefficients. The first and second sample data together constitute the training sample data. For each training sample data, the electronic device can determine the sample label corresponding to that training sample data. All training sample data and their corresponding sample labels together constitute the training dataset.

[0046] In an optional embodiment, the first sample data and the second sample data mentioned above are both quantum data, which can be represented in the form of quantum states.

[0047] In an optional embodiment, the sample labels described above can be used to indicate the category of the corresponding training sample data.

[0048] For example, when the first sample data is quantum data (denoted as first quantum data) generated from the original image data, the original image data carries classification information. Accordingly, the sample label (denoted as first label) corresponding to the first quantum data can be used to indicate the category of the classification information in the original image data corresponding to the first quantum data.

[0049] For ease of understanding, combined with Figure 2 Let's take an example to illustrate. Figure 2 This is a schematic diagram of the raw image data provided in an embodiment of this application. The raw image data described above can be a series of images including classification information, such as... Figure 2 The handwritten "Q" in image 201 and the handwritten "T" in image 202. The electronic device, according to... Figure 2 After generating the first sample data from the original image data shown, sample labels corresponding to the first sample data are generated based on the classification information in the original image data.

[0050] For example, when the first sample data is quantum data generated from the original initial state (denoted as the second quantum data), the sample label (i.e. the first label) corresponding to the second quantum data (i.e. the first sample data) can be determined based on the second quantum data. For details, please refer to the description below, which will not be specifically limited here.

[0051] The sample label (denoted as the second label) corresponding to the second sample data can be determined based on the first label of the corresponding first sample data, which will not be explained in detail here.

[0052] In this embodiment of the application, the number of training sample data can be multiple, that is, the number of first sample data can be multiple, and the number of second sample data can be multiple. Here, there is no specific limitation on the number of training sample data included in the above training dataset.

[0053] In an optional embodiment, in order to improve the classification accuracy and resistance to attacks of the training classifier obtained through training, the ratio of the number of first sample data and second sample data included in the above training sample data can be 1:1.

[0054] After obtaining the aforementioned first sample data, the electronic device can use the first sample data to train the quantum neural network classifier, thereby obtaining a trained quantum neural network classifier. The electronic device can then use the trained quantum neural network classifier as a classifier to be trained.

[0055] In an optional embodiment, the quantum neural network classifier described above includes a variational circuit. This variational circuit is represented as a product of multiple unitary matrices.

[0056] For ease of understanding, combined with Figure 3-a Let's take an example to illustrate. Figure 3-a This is a schematic diagram of the first structure of the classifier to be trained provided in an embodiment of this application. Figure 3-a The classifier to be trained shown includes a variational circuit, which consists of L-layer unitary matrices U(θ) (not shown in Figure-a). Figure 3-a As shown, the unitary matrix U(θ) includes local single-qubit rotation gates. and the two-qubit entanglement gate V ent , represented as:

[0057]

[0058] Where θ is the set of all classifier parameters in the classifier to be trained, ∏ is the cumulative multiplication sign, L is the number of layers in the unitary matrix of the classifier to be trained, and i is the i-th layer in L layers. For direct product operation, R() is the rotation gate, and j is the j-th row in the i-th layer.

[0059] For each U(θ), ​​as described above Figure 3-a The diagram on the right shows the structure of layer U(θ) in the classifier to be trained. This U(θ) consists of multiple arbitrary single-qubit logic gates (i.e., U3 gates) and multiple two-qubit entanglement gates (such as...). Figure 3-a (Door 301 shown).

[0060] In the above embodiments, only the example of a classifier to be trained including a variational circuit is used for illustration. Besides this, the classifier to be trained may also include other components. For ease of understanding, [further details are provided]. Figure 3-b Let's take an example to illustrate. Figure 3-b This is a schematic diagram of a second structure of a classifier to be trained provided in an embodiment of this application.

[0061] In the above Figure 3-bThe classifier to be trained shown may include, in addition to the variational circuit mentioned above, a state preparation circuit U as shown in 3-b. e (x), Measurement basis line U basis .

[0062] The above-mentioned state preparation circuit U e (x) can act on n qubits (e.g., ... Figure 3-b The initial state of (Q1-Q20) shown The above is used to map the original d-dimensional image data vector to Hilbert space. Middle 2 n The density matrix of dimension, i.e. The above measurement basis line U basis The measurement basis vectors used to transform the output of the above variational circuit.

[0063] In this embodiment of the application, when the first sample data is the first quantum data, the classifier to be trained may include... Figure 3-b The state preparation circuit U shown e (x). At this point, the electronic device can directly input the image data into the classifier to be trained, and use the state preparation circuit in the classifier to generate the first sample data or the second sample data mentioned above.

[0064] Alternatively, the above-mentioned classifiers to be trained may not include the aforementioned ones. Figure 3-b The measurement basis line U shown basis At this point, when the electronic device measures the output results, it defaults to measuring on the Z-axis of the Bloch sphere.

[0065] In this embodiment, the structure of the classifier to be trained is not specifically limited. For ease of understanding, the following description assumes that the classifier to be trained only includes the variational circuit described above.

[0066] For step S102 above, that is, for each training sample data, the training sample data is classified using the classifier to be trained to obtain the first predicted label corresponding to the training sample data.

[0067] In an optional embodiment, step S102 above can specifically be expressed as:

[0068] For each training sample data, the electronic device inputs the training sample data into the classifier to be trained to obtain the confidence vector corresponding to the training sample data; based on the confidence vector, the first predicted label corresponding to the training sample data is determined using the maximum likelihood algorithm.

[0069] In this embodiment, for each training sample data, the electronic device can input the training sample data into the classifier to be trained. Through the processing of the L-layer unitary matrix U(θ) in the variational circuit and the measurement of the processing result, the electronic device can obtain the confidence vector output by the classifier to be trained. This confidence vector can be expressed as:

[0070] y(x,θ)=(p1,p2,…,p K ) T

[0071] Where x represents the training sample data, θ represents the classifier parameters of the classifier to be trained, K represents the dimension of y(x,θ), and T represents the transpose operation. Tr() is the trace operator. For measurement operators, B represents subsystem B in the quantum system, and ρ(θ,x) is the quantum state output by the classifier to be trained under x and θ.

[0072] In an optional embodiment, during the above measurement process, the electronic device can measure the... A quantum subsystem consisting of n output qubits, and discarding the remaining n in the classifier to be trained. A n qubits. At this time, the measured n B The subsystem consisting of the output qubits is the aforementioned subsystem B.

[0073] For step S103 above, that is, to calculate the first loss value of the classifier to be trained based on the sample label and the first predicted label corresponding to each training sample data.

[0074] In an optional embodiment, the electronic device can calculate the first loss value J(θ) of the classifier to be trained based on the sample label and the first predicted label corresponding to each training sample data, using the following formula. ′ ):

[0075]

[0076] Where, θ ′ The classifier parameters are those of the classifier to be trained. For the expected calculation, Let y(x,θ) be the loss function, c be the vector representation of the sample labels, and θ be the loss function. ′ ) for x and θ ′ The confidence vector output by the classifier to be trained is given below, where ρ(x) is the quantum state corresponding to x, and x is the training sample data. Let x be the gradient. ∈ represents the preset perturbation coefficient. Let x be the gradient, and sign() be the sign function. For partial derivative calculation, x i For the i-th first sample data, w i For a predefined binary vector W = (w1, w2, ..., w m ) T The i-th vector element in the vector, where T is the transpose operation and m is the dimension of W. α is a preset threshold, N is the number of the first sample data, and x j,i Let be the i-th component of the j-th x.

[0077] In this embodiment of the application, the loss function of the classifier to be trained can be expressed as:

[0078]

[0079] For the loss function Performing a Taylor expansion, we get:

[0080]

[0081] Therefore, the first loss value J(θ) can be obtained as described above. ′ The loss function is shown in the figure.

[0082] In the above embodiments, x, θ, θ ′ Parameters such as x and c are represented in vector form, meaning each parameter contains multiple vector elements, as shown above. j,i The i-th component in the equation is denoted as x. j The i-th vector element in the vector.

[0083] Regarding step S104 above, that is, when the classifier to be trained has not converged, the classifier parameters of the classifier to be trained are adjusted based on the first loss value, and the process is returned to execute the step of classifying the training sample data using the classifier to be trained for each training sample data to obtain the first predicted label corresponding to the training sample data, until the classifier to be trained converges at the current time.

[0084] After calculating the first loss value, the electronic device can determine whether the classifier to be trained has converged based on the first loss value at the current moment or the number of iterations.

[0085] For example, when determining whether a classifier to be trained has converged based on the number of iterations, the electronic device can compare the current number of iterations with a preset number of iterations. If the current number of iterations is less than the preset number of iterations, the electronic device can determine that the classifier to be trained has not converged; if the current number of iterations is equal to the preset number of iterations, the electronic device can determine that the classifier to be trained has converged.

[0086] For example, when determining whether the classifier to be trained has converged based on the first loss value, the electronic device can compare the first loss value at the current time with a preset threshold. If the first loss value at the current time is greater than the preset threshold, the electronic device can determine that the classifier to be trained has not converged; if the first loss value at the current time is less than or equal to the preset threshold, the electronic device can determine that the classifier to be trained has converged.

[0087] When the electronic device determines that the classifier to be trained has not converged, it can continue training the classifier. At this time, the electronic device can adjust the classifier parameters in the classifier to be trained based on the first loss value, and according to the adjusted classifier parameters, return to execute the above step S102, that is, return to execute the step of classifying the training sample data using the classifier to be trained for each training sample data to obtain the first predicted label corresponding to the training sample data, until the classifier to be trained converges at the current time, thus completing the training process of the classifier to be trained.

[0088] The classifier parameters in the aforementioned classifier to be trained can be adjusted using methods such as gradient descent. For details, please refer to the method for adjusting classifier parameters in the quantum neural network classifier below; it will not be elaborated upon here.

[0089] In this embodiment of the application, the loss function J(θ) of the classifier to be trained is... ′ Based on the training of the quantum neural network classifier described above, a regularization term was added, namely... As the perturbation intensity increases, the output confidence of the classifier to be trained will also change.

[0090] For ease of understanding, combined with Figure 4-a and Figure 4-b Let's take an example to illustrate. Figure 4-a This is a first schematic diagram of the test results of the model to be trained provided in an embodiment of this application. Figure 4-b This is a second schematic diagram of the test results of the model to be trained provided in the embodiments of this application. The horizontal axis represents the perturbation intensity, and the vertical axis represents the probability value corresponding to the predicted label output by the classifier to be trained. Figure 4-a This was obtained through testing with the original image data described above as the source data. Figure 4-b It was obtained by testing under the original initial state described above.

[0091] When the above R(θ) ′ When )>0, such as Figure 4-a Left image and Figure 4-bAs shown in curves 401 and 403, the curves represent the probability changes corresponding to label 1, and curves 402 and 404 represent the probability changes corresponding to label 0. When the above-mentioned classifier to be trained is used for testing, as shown in curves 401 and 402, the accuracy of the classification results of the classifier to be trained gradually decreases with the increase of perturbation intensity, and even errors occur. For example, in curve 401, the probability value drops below 0.5 when the horizontal axis is 7. When the trained classifier to be trained is used for testing, as shown in curves 403 and 404, although the accuracy of the classification results of the classifier to be trained also gradually decreases with the increase of perturbation intensity, no errors occur. That is, compared with the untrained classifier to be trained, the trained classifier to be trained has a certain robustness against noise or attacks, and improves the resistance to attacks of the quantum neural network classifier to a certain extent.

[0092] When the above R(θ) ′ When ) < 0, such as Figure 4-a As shown in the right figure, when a trained classifier is used for testing, the accuracy of the classification results gradually increases with the increase of perturbation intensity, as indicated by curves 403 and 404 in the right figure. This means that the trained classifier, compared to the untrained classifier, exhibits better robustness against noise or attacks, and the output results of the quantum neural network classifier have higher confidence, effectively improving the attack resistance of the quantum neural network classifier.

[0093] Therefore, in the training process of the aforementioned classifier to be trained, by minimizing R(θ) ′ That is, minimizing J(θ) ′ This can effectively improve the robustness of the trained classifier, increase the confidence of the classification results of the trained classifier, and thus improve the resistance to attacks of the trained classifier.

[0094] In an optional embodiment, when the classifier to be trained converges, the electronic device can determine that the training process of the classifier to be trained is complete. At this time, the electronic device can obtain a test dataset by referring to the above-described method for obtaining the training dataset, and use the data in the test dataset to test the trained classifier to be trained.

[0095] In another optional embodiment, after training the classifier described above is completed, the electronic device can use the trained classifier for classification and recognition. For example, the electronic device can acquire data to be classified and input the data to be classified into the trained classifier to obtain the classification result corresponding to the data to be classified.

[0096] In an optional embodiment, according to the above... Figure 1 The method shown in this application embodiment also provides a method for training a quantum neural network classifier. For example... Figure 5 As shown, Figure 5 This is a flowchart illustrating a method for obtaining a training dataset provided in an embodiment of this application. The method includes the following steps.

[0097] Step S501: Obtain multiple first sample data and the first label corresponding to each first sample data based on the original data.

[0098] In one optional embodiment, the electronic device can acquire multiple first sample data and a first label corresponding to each first sample data based on the original image data. In this case, the first sample data is a multidimensional density matrix mapped to Hilbert space.

[0099] Specifically, the electronic device can acquire multiple raw image data; based on the classification information carried in each raw image data, determine the third label corresponding to each raw image data; for each raw image data, use the state preparation circuit to map the raw image data into a multidimensional density matrix in Hilbert space to obtain the first sample data corresponding to the raw image data, and determine the third label corresponding to the raw image data as the first label corresponding to the first sample data.

[0100] For ease of understanding, in conjunction with the above Figure 2 Let's take an example. For each piece of raw image data, the electronic device can utilize the above... Figure 3-b The state preparation circuit maps the original image data into a multidimensional density matrix in Hilbert space, thus obtaining the first sample image corresponding to the original image data.

[0101] Since each raw image data contains classification information, the electronic device can determine the label (denoted as the third label) corresponding to each raw image information based on the classification information in each raw image data. For ease of understanding, the raw image data shown in Figure 3 above will still be used as an example for explanation. Figure 2 Given the handwritten "Q" in image 201 and the handwritten "T" in image 202, the electronic device can determine that the third label corresponding to image 201 can be 1, and the third label corresponding to image 202 can be 0. After generating the aforementioned first sample data, the electronic device can determine the third label as the first label corresponding to the first sample data based on the third label of the original image data corresponding to each first sample data.

[0102] In this embodiment, the quantity of the original image data and the classification information within the original image data can be set according to user needs. Furthermore, the third label and the first label will differ depending on the classification information carried in the original image data. Here, no specific limitations are made on the quantity of the original image data, the classification information, the third label, and the first label.

[0103] In another optional embodiment, the electronic device can acquire multiple first sample data and a first tag corresponding to each first sample data based on the initial state. In this case, the first sample data can be a linear cluster state or a topological phase.

[0104] The aforementioned linear cluster state is a class of quantum states with high entanglement. The aforementioned topological phase refers to the phase of the quantum system under different parameters. For ease of understanding, the acquisition of the aforementioned first sample data and the first tag will be explained below using the aforementioned linear cluster state as an example of the first sample data.

[0105] The electronic device can input the original initial state into a preset quantum circuit and obtain the linear cluster state output by the preset quantum circuit as the first sample data. The preset quantum circuit includes rotating gates corresponding to different rotation angles. For each first sample data, the first tag corresponding to the first sample data is determined according to the rotation angle corresponding to the first sample data.

[0106] For ease of understanding, combined with Figure 6 Let's take an example to illustrate. Figure 6 This is a schematic diagram of a preset quantum circuit provided in an embodiment of this application. Figure 6 The preset quantum circuit shown includes Hadamard (H) gates and rotation gates (Rx gates). H gates are used to generate linear cluster states, and Rx gates are used to rotate qubits around the X-axis of a Bloch sphere in the range [0, π]. Different Rx gates have different rotation angles, such as... Figure 6 The θ1-θ shown 20 Through such Figure 6 The preset quantum circuit shown can convert the input original initial state into a linear cluster state to obtain the first sample data, and then determine the first label corresponding to the first sample data based on the rotation angle of the first sample data.

[0107] In an optional embodiment, since the X-axis around the Bloch sphere rotates between [0, π], when the rotation angle is sufficiently large (e.g., between [π / 2, π] or [5π / 8, π]), the linear cluster state can be identified as an excited cluster state. In this case, the electronic device can determine the first label corresponding to the first sample data as 1. When the rotation angle is relatively small (e.g., between [0, π / 2] or [0, 3π / 8]), the linear cluster state can be identified as an unexcited cluster state. In this case, the electronic device can determine the first label corresponding to the first sample data as 0.

[0108] In the process of determining the first label, if [5π / 8,π] and [0,3π / 8] are used for the determination of the first label, then by removing [3π / 8,5π / 8], the possibility of misjudgment can be reduced and the accuracy of the determined first label can be improved.

[0109] In an optional embodiment, the aforementioned preset quantum circuit is used to transform the input initial state into the aforementioned linear cluster state, specifically as follows:

[0110]

[0111] Among them, |LC n > represents the quantum state corresponding to the first sample data output by the preset quantum circuit, and n represents the number of CZ gates in the preset quantum circuit. i,i+1 Let |+> represent the CZ gate operations on the quantum circuit corresponding to the i-th qubit and the (i+1)-th qubit, and let |+> represent the quantum state obtained by processing the preset initial state through the H gate. This is the symbol for the direct product.

[0112] In the above embodiments, if the first sample data is the linear cluster state, the above Figure 3-b The state preparation circuit U in the classifier to be trained is shown. e (x) can be replaced with the above. Figure 6 The preset quantum circuit shown.

[0113] In this embodiment, the example of using the aforementioned classifier to be trained and the quantum neural network classifier for binary classification is provided. However, the classifier to be trained and the quantum neural network classifier can also be used for multi-class classification, such as three-class classification. In this case, the representation of the sample labels (i.e., the first label and the second label) will be different.

[0114] In an optional embodiment, to facilitate accurate representation of the sample labels, the sample labels can be represented in vector form. For example, without loss of generality, if there are K categories (K≤2^32), ... n The sample label 1≤k≤K can be represented by a vector using one-hot encoding: ck =(c1,c2,…,c K ) T , where c i=k =1 and c i≠k =0.

[0115] Step S502: Based on the original data / first sample data and the preset perturbation coefficient, generate second sample data, and determine the first label corresponding to the first sample data as the second label corresponding to the second sample data.

[0116] In this embodiment of the application, since the above-mentioned original data are original image data and original initial state, when generating second sample data based on preset perturbation coefficient, the electronic device can generate second sample data based on the original data and preset perturbation coefficient, or it can generate second sample data based on the first sample data and preset perturbation coefficient.

[0117] In an optional embodiment, when generating the second sample data, the electronic device can obtain the second loss value corresponding to the original data based on the original data / first sample data, the first label of the original data corresponding to the first sample data, and the second predicted label generated by the classifier to be trained for the original data corresponding to the first sample data; and generate the second sample data based on the second loss value and the preset perturbation coefficient.

[0118] For example, when the aforementioned original data is the aforementioned original image data, the electronic device can generate second sample data based on the original image data and a preset perturbation coefficient. For example, the electronic device can obtain a second loss value corresponding to the original image data based on the original image data, the first label of the first sample data corresponding to the original image data, and the second predicted label of the classifier to be trained for the first sample data corresponding to the original image data. Then, it can generate noisy image data based on the second loss value, the preset perturbation coefficient, and the original image data. Finally, it can use the aforementioned state preparation circuit to map the noisy image data into a multidimensional density matrix in Hilbert space to obtain the second sample data corresponding to the original image data.

[0119] For example, when the original data is the original initial state, the electronic device can obtain the second loss value corresponding to the original data based on the first sample data, the first label corresponding to the first sample data, and the second predicted label generated by the classifier to be trained for the first sample data, and then directly generate the second sample image based on the second loss value, the preset perturbation coefficient and the first sample data.

[0120] In an optional embodiment, the electronic device can generate second sample data based on the second loss value and a preset perturbation coefficient using the following formula:

[0121]

[0122] Where x ′ Here, x represents the original data / the first sample data, and ∈ represents the preset perturbation coefficient. Let x be the gradient. For loss function, This is represented as the gradient of the loss function with respect to x, where sign() is the sign function. For partial derivative calculation, x i For the i-th first sample data, w i For a predefined binary vector W = (w1, w2, ..., w m ) T The i-th vector element in the vector, where T is the transpose operation and m is the dimension of W. α is a preset threshold, N is the number of the first sample data, and x j,i Let y(x,θ) be the i-th component of the j-th x, y(x,θ) be the confidence vector output by the quantum neural network classifier under x and θ, θ be the parameters of the quantum neural network classifier, ρ(x) be the quantum state corresponding to x, and c be the vector representation of the sample label.

[0123] Steps S501-S502 above are a refinement of the acquisition of training sample data in step S101 above.

[0124] Through the above steps S501-S502, after obtaining the first sample data, the electronic device can generate corresponding second sample data for each original data / first sample data by combining a preset perturbation coefficient, and determine the first label corresponding to the original data / first sample data as the second label of the corresponding second sample data, thereby realizing the acquisition of training sample data and sample labels. Noise interference is introduced into the second sample data, so that the second sample data can well simulate the scenario where noise or attack exists.

[0125] In the above Figure 5 In the illustrated embodiment, the acquisition of the first sample data is explained using only the example of a linear cluster state as the first sample data. Otherwise, when the first sample data is other quantum data, such as the topological phase described above, the electronic device can input the original initial state into the quantum circuit to obtain the corresponding quantum data, referring to methods in related technologies. Here, the method for acquiring the first sample data is not specifically limited.

[0126] In an optional embodiment, according to the above... Figure 1 The method shown in this application embodiment also provides a method for training a quantum neural network classifier. For example... Figure 7 As shown, Figure 7This is a second flowchart illustrating a quantum neural network classifier training method provided in an embodiment of this application. The method includes the following steps.

[0127] Step S701: For each first sample data, the quantum neural network classifier is used to classify the first sample data to obtain the third predicted label corresponding to the first sample data.

[0128] In this step, after obtaining the first sample data, the electronic device can input each first sample data into the quantum neural network classifier, which will then classify each first sample data to obtain the label (denoted as the third predicted label) corresponding to each first sample data.

[0129] The structure of the aforementioned quantum neural network classifier can refer to the structure of the classifier to be trained described above. Furthermore, the method for obtaining the third predicted label can also refer to the method for obtaining the first predicted label described above. Here, no specific limitations are made regarding the structure of the aforementioned quantum neural network classifier and the method for obtaining the third predicted label.

[0130] Step S702: Calculate the third loss value of the quantum neural network classifier based on the first label and the third predicted label corresponding to each first sample data.

[0131] In one optional embodiment, for each first sample data, there exists a corresponding first label and a third predicted label. Based on the first label and the third predicted label corresponding to each first sample data, a loss value (denoted as the third loss value) of the quantum neural network classifier is calculated using a preset loss function.

[0132] The aforementioned preset loss function can be a loss function such as the cross-entropy function, i.e., the above. Here, no specific limitations are made on the aforementioned preset loss function.

[0133] Step S703: When the quantum neural network classifier has not converged, adjust the classifier parameters of the quantum neural network classifier according to the third loss value, and return to execute the step of classifying the first sample data using the quantum neural network classifier for each first sample data to obtain the third predicted label corresponding to the first sample data, until the quantum neural network classifier converges at the current time to obtain the classifier to be trained.

[0134] The electronic device can determine whether the quantum neural network classifier has converged at the current moment based on the number of training iterations or the aforementioned third loss value. If it is determined that the quantum neural network classifier has converged at the current moment, the electronic device can adjust the classifier parameters in the quantum neural network classifier based on the aforementioned third loss value. These classifier parameters include the initial parameters and biases of the quantum neural network classifier.

[0135] After adjusting the classifier parameters in the quantum neural network classifier, the electronic device can continue training the quantum neural network classifier at the current moment based on the aforementioned first sample data. That is, based on the adjusted classifier parameters, it returns to step S701, whereby the quantum neural network classifier classifies each first sample data point to obtain the third predicted label, until the quantum neural network classifier at the current moment converges. At this point, the electronic device can determine the quantum neural network classifier at the current moment as the classifier to be trained.

[0136] In an optional embodiment, when determining whether the quantum neural network classifier has converged, the electronic device can determine the minimum empirical risk value of the quantum neural network classifier based on the third loss value, and determine that the quantum neural network classifier has converged when the minimum empirical risk value is reached.

[0137] The above-mentioned minimized empirical risk value can be expressed as:

[0138]

[0139] Where min represents the minimization operation, θ represents the classifier parameters of the quantum neural network classifier, and K represents the number of classes corresponding to the first sample data. Let y(x,θ) be the loss function, y(x,θ) be the confidence vector output by the quantum neural network classifier under x and θ, x be the first sample data, ρ(x) be the quantum state corresponding to x, and c be the vector representation of the sample label.

[0140] In an optional embodiment, during the above iteration process, in order to improve the training speed of the quantum neural network classifier, the electronic device can adjust the classifier parameters based on a third loss value using a mini-batch stochastic gradient descent and adaptive moment estimation (Adam) optimization algorithm.

[0141] In the mini-batch stochastic gradient descent process, a small subset B is randomly selected from all the first sample data. The gradient corresponding to subset B is used to approximate the gradient corresponding to all the first sample data. Specifically, it can be expressed as:

[0142]

[0143] Correspondingly, the classifier parameter update rule of the quantum neural network classifier can be expressed as: θ t =θ t-1 -ηg t .

[0144] Where g is the gradient, and B is the number of the first sample data included in subset B. Let θ be the gradient of θ, y be the confidence vector output by the quantum neural network classifier, and c be the vector representation of the first label corresponding to the first sample data. t Let θ be the classifier parameters corresponding to the t-th iteration. t-1 Let η be the classifier parameters for the (t-1)th iteration, and η be the learning rate.

[0145] Considering the challenges of the mini-batch stochastic gradient descent method, such as setting the learning rate without prior knowledge and the tendency to get trapped in suboptimal local minima for non-convex objective functions, the Adam optimization algorithm is introduced based on the mini-batch stochastic gradient descent method. The parameter update rule for the aforementioned quantum neural network classifier is then updated as follows:

[0146]

[0147] Where, θ t Let θ be the classifier parameters corresponding to the t-th iteration. t-1 Here are the classifier parameters for the (t-1)th iteration, where η is the learning rate, ∈ ′ For non-zero perturbations, m t Let v be the second moment of the momentum corresponding to the t-th iteration. t Let be the second moment of the gradient corresponding to the t-th iteration, and β1 and β2 be non-negative weighting parameters, m t =β1m t-1 +(1-β1)g t , m t-1 Let v be the second moment of momentum corresponding to the (t-1)th iteration. t-1 Let be the second moment of the gradient corresponding to the (t-1)th iteration. For g t The product of itself and its own Hadama.

[0148] Through the above steps S701-S703, the electronic device can use the first sample data and the first label corresponding to the first sample data to train the quantum neural network classifier, ensuring the accuracy of the trained classifier.

[0149] Based on the same inventive concept, and according to the quantum neural network classifier training method provided in the above embodiments of this application, this application also provides a quantum neural network classifier device. For example... Figure 8 As shown, Figure 8 This is a schematic diagram of a quantum neural network classifier device provided in an embodiment of this application. The device includes the following modules.

[0150] The acquisition module 801 is used to acquire the training dataset and the classifier to be trained. The training dataset includes multiple training sample data and the sample label corresponding to each training sample data. The training sample data includes first sample data and second sample data. The first sample data is quantum data generated based on the original data. The second sample data is generated based on the original data / first sample data and a preset perturbation coefficient. The original data is the original image data or the original initial state. The classifier to be trained is a quantum neural network classifier trained based on the first sample data.

[0151] The classification module 802 is used to classify each training sample data using the classifier to be trained, and obtain the first predicted label corresponding to the training sample data.

[0152] The calculation module 803 is used to calculate the first loss value of the classifier to be trained based on the sample label and the first predicted label corresponding to each training sample data.

[0153] The adjustment module 804 is used to adjust the classifier parameters of the classifier to be trained based on the first loss value when the classifier to be trained has not converged, and return to execute the step of classifying the training sample data using the classifier to be trained for each training sample data to obtain the first predicted label corresponding to the training sample data, until the classifier to be trained converges at the current time.

[0154] Optionally, the aforementioned acquisition module 801 may specifically include:

[0155] The acquisition submodule is used to acquire multiple first sample data and the first label corresponding to each first sample data based on the raw data.

[0156] The generation submodule is used to generate second sample data based on the original data / first sample data and a preset perturbation coefficient, and to determine the first label corresponding to the first sample data as the second label corresponding to the second sample data.

[0157] Optionally, the above-mentioned acquisition submodule can be used to acquire multiple original image data if the original data is original image data.

[0158] Based on the classification information carried in each original image data, determine the third label corresponding to each original image data;

[0159] For each original image data, the state preparation circuit is used to map the original image data into a multidimensional density matrix in Hilbert space to obtain the first sample data corresponding to the original image data, and the third label corresponding to the original image data is determined as the first label corresponding to the first sample data.

[0160] Optionally, the above-mentioned acquisition submodule can be used to input the original initial state into a preset quantum circuit if the first sample data is a linear cluster state, and to acquire the linear cluster state output by the preset quantum circuit as the first sample data. The preset quantum circuit includes rotating gates corresponding to different rotation angles.

[0161] For each first sample data, determine the first label corresponding to the first sample data based on the rotation angle corresponding to the first sample data.

[0162] Optionally, if the preset quantum circuit includes H-gates and CZ-gates, then the above preset quantum circuit can be represented as:

[0163]

[0164] Among them, |LC n > represents the quantum state corresponding to the first sample data output by the preset quantum circuit, and n represents the number of CZ gates in the preset quantum circuit. i,i+1 Let |+> represent the CZ gate operations on the quantum circuit corresponding to the i-th qubit and the (i+1)-th qubit, and let |+> represent the quantum state obtained by processing the preset initial state through the H gate. This is the symbol for the direct product.

[0165] Optionally, the above-mentioned generation submodule can be used to obtain the second loss value corresponding to the original data based on the original data / first sample data, the first label of the original data corresponding to the first sample data, and the second predicted label generated by the classifier to be trained for the original data corresponding to the first sample data.

[0166] The second sample data is generated based on the second loss value and the preset perturbation coefficient.

[0167] Optionally, the above-mentioned generation submodule can be used to generate second sample data based on the second loss value and the preset perturbation coefficient using the following formula;

[0168]

[0169] Where, x ′ Here, x represents the original data / the first sample data, and ∈ represents the preset perturbation coefficient. Let x be the gradient. Here, `sign()` is the loss function, and `sign()` is the sign function. For partial derivative calculation, x i For the i-th first sample data, w i For a predefined binary vector W = (w1, w2, ..., w m ) T The i-th vector element in the vector, where T is the transpose operation and m is the dimension of W. α is a preset threshold, N is the number of the first sample data, and x j,i Let y(x,θ) be the i-th component of the j-th x, y(x,θ) be the confidence vector output by the quantum neural network classifier under x and θ, θ be the parameters of the quantum neural network classifier, ρ(x) be the quantum state corresponding to x, and c be the vector representation of the sample label.

[0170] Optionally, the acquisition module 801 described above can be used to classify each first sample data using a quantum neural network classifier to obtain the third predicted label corresponding to the first sample data.

[0171] Calculate the third loss value of the quantum neural network classifier based on the first label and the third predicted label corresponding to each first sample data;

[0172] When the quantum neural network classifier has not converged, the classifier parameters of the quantum neural network classifier are adjusted according to the third loss value, and the process is returned to perform the step of classifying the first sample data using the quantum neural network classifier for each first sample data to obtain the third predicted label corresponding to the first sample data, until the quantum neural network classifier converges at the current time to obtain the classifier to be trained.

[0173] Optionally, the classification module 802 described above can be used to input the training sample data into the classifier to be trained for each training sample data to obtain the confidence vector corresponding to the training sample data.

[0174] Based on the confidence vector, the first predicted label corresponding to the training sample data is determined using the maximum likelihood algorithm.

[0175] Optionally, the aforementioned calculation module 803 can be specifically used to calculate the first loss value J(θ) of the classifier to be trained based on the sample label and the first predicted label corresponding to each training sample data, using the following formula. ′ ):

[0176]

[0177] Where, θ ′ The classifier parameters are those of the classifier to be trained. For the expected calculation, Let y(x,θ) be the loss function, c be the vector representation of the sample labels, and θ be the loss function. ′ ) for x and θ v The confidence vector output by the classifier to be trained is given below, where ρ(x) is the quantum state corresponding to x, and x is the training sample data. Let x be the gradient. ∈ represents the preset perturbation coefficient. Let x be the gradient, and sign() be the sign function. For partial derivative calculation, x i For the i-th first sample data, w i For a predefined binary vector W = (w1, w2, ..., w m ) T The i-th vector element in the vector, where T is the transpose operation and m is the dimension of W. α is a preset threshold, N is the number of the first sample data, and x j,i Let be the i-th component of the j-th x.

[0178] The apparatus provided in this application embodiment can, after obtaining the training dataset and the classifier to be trained, classify each training sample data using the classifier to be trained to obtain the first predicted label corresponding to each training sample data. Then, based on the sample label and the first predicted label corresponding to each training sample data, calculate the first loss value of the classifier to be trained. If the classifier to be trained has not converged, adjust the classifier parameters of the classifier to be trained based on the first loss value, and continue to train and optimize the classifier to be trained based on the training sample data and sample labels until the classifier to be trained converges.

[0179] In the training process of the aforementioned classifier to be trained, the classifier to be trained is pre-trained based on the first sample data. On this basis, the second sample data in the training sample data is generated based on the preset perturbation coefficient and the original data / first sample data. Compared with the first sample data generated based on the original data, the second sample data can better simulate the existence of noise or attacks. Therefore, by using the training sample data including the first sample data and the second sample data to train the classifier to be trained, the classifier to be trained can be optimized, improving the classification accuracy and anti-attack resistance of the trained classifier to be trained.

[0180] Based on the same inventive concept, and according to the quantum neural network classifier training method provided in the above embodiments of this application, this application also provides an electronic device, such as... Figure 9 As shown, it includes a processor 901, a communication interface 902, a memory 903, and a communication bus 904, wherein the processor 901, the communication interface 902, and the memory 903 communicate with each other through the communication bus 904.

[0181] Memory 903 is used to store computer programs;

[0182] When the processor 901 executes the program stored in the memory 903, it implements the steps of the quantum neural network classifier training method described above.

[0183] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.

[0184] The communication interface is used for communication between the aforementioned electronic devices and other devices.

[0185] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.

[0186] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0187] Based on the same inventive concept, and according to the quantum neural network classifier training method provided in the above embodiments of this application, this application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of any of the above quantum neural network classifier training methods.

[0188] Based on the same inventive concept, and according to the quantum neural network classifier training method provided in the above embodiments of this application, this application also provides a computer program product containing instructions, which, when run on a computer, causes the computer to execute any of the quantum neural network classifier training methods in the above embodiments.

[0189] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).

[0190] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0191] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, embodiments such as apparatuses, electronic devices, computer-readable storage media, and computer program products are basically similar to the method embodiments, and therefore the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0192] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.

Claims

1. A method for training a quantum neural network classifier, characterized in that, The method includes: Acquire a training dataset and a classifier to be trained. The training dataset includes multiple training sample data and a sample label corresponding to each training sample data. The training sample data includes first sample data and second sample data. The first sample data is quantum data generated based on the original data. The second sample data is generated based on the original data / first sample data and a preset perturbation coefficient. The original data is original image data or original initial state. The classifier to be trained is a quantum neural network classifier trained based on the first sample data. For each training sample data, the training sample data is classified using the classifier to be trained to obtain the first predicted label corresponding to the training sample data. The first loss value of the classifier to be trained is calculated based on the sample label and the first predicted label corresponding to each training sample data. When the classifier to be trained has not converged, the classifier parameters of the classifier to be trained are adjusted based on the first loss value, and the process of classifying the training sample data using the classifier to be trained for each training sample data to obtain the first predicted label corresponding to the training sample data is returned, until the classifier to be trained converges at the current time.

2. The method according to claim 1, characterized in that, The steps to obtain the training dataset include: Based on the original data, obtain multiple first sample data and the first label corresponding to each first sample data; Based on the original data / first sample data and the preset perturbation coefficient, second sample data is generated, and the first label corresponding to the first sample data is determined as the second label corresponding to the second sample data.

3. The method according to claim 2, characterized in that, If the original data is original image data, then the step of obtaining multiple first sample data and the first label corresponding to each first sample data based on the original data includes: Acquire multiple raw image data; Based on the classification information carried in each original image data, determine the third label corresponding to each original image data; For each original image data, the state preparation circuit is used to map the original image data into a multidimensional density matrix in Hilbert space to obtain the first sample data corresponding to the original image data, and the third label corresponding to the original image data is determined as the first label corresponding to the first sample data.

4. The method according to claim 2, characterized in that, If the first sample data is a linear cluster, then the step of obtaining multiple first sample data and the first label corresponding to each first sample data based on the original data includes: The initial state is input into a preset quantum circuit, and the linear cluster state output by the preset quantum circuit is obtained as the first sample data. The preset quantum circuit includes rotating gates corresponding to different rotation angles. For each first sample data, determine the first label corresponding to the first sample data based on the rotation angle corresponding to the first sample data.

5. The method according to claim 4, characterized in that, If the preset quantum circuit includes H-gates and CZ-gates, then the preset quantum circuit is represented as follows: Among them, |LC n > represents the quantum state corresponding to the first sample data output by the preset quantum circuit, and n represents the number of CZ gates in the preset quantum circuit. i,i+1 Let |+> represent the CZ gate operations on the quantum circuit corresponding to the i-th qubit and the (i+1)-th qubit, and |+> represent the quantum state obtained by processing the preset initial state through the H gate. This is the symbol for the direct product.

6. The method according to claim 2, characterized in that, The step of generating second sample data based on the original data / first sample data and a preset perturbation coefficient includes: Based on the original data / first sample data, the first label corresponding to the first sample data, and the second predicted label generated by the classifier to be trained for the first sample data, the second loss value corresponding to the original data is obtained. The second sample data is generated based on the second loss value and the preset perturbation coefficient.

7. The method according to claim 6, characterized in that, The step of generating second sample data based on the second loss value and the preset perturbation coefficient includes: Based on the second loss value and the preset disturbance coefficient, the second sample data is generated using the following formula; Where, x ′ Here, x represents the original data / first sample data, and ∈ represents the preset perturbation coefficient. Let x be the gradient. Here, `sign()` is the loss function, and `sign()` is the sign function. For partial derivative calculation, x i For the i-th first sample data, w i For a predefined binary vector W = (w1, w2, ..., w m ) T The i-th vector element in the vector, where T is the transpose operation and m is the dimension of W. α is a preset threshold, N is the number of the first sample data, and x j,i Let y(x,θ) be the i-th component of the j-th x, y(x,θ) be the confidence vector output by the quantum neural network classifier under x and θ, θ be the parameters of the quantum neural network classifier, ρ(x) be the quantum state corresponding to x, and c be the vector representation of the sample label.

8. The method according to claim 2, characterized in that, The steps to obtain the classifier to be trained include: For each first sample data, the quantum neural network classifier is used to classify the first sample data to obtain the third predicted label corresponding to the first sample data; The third loss value of the quantum neural network classifier is calculated based on the first label and the third predicted label corresponding to each first sample data. When the quantum neural network classifier fails to converge, the classifier parameters of the quantum neural network classifier are adjusted according to the third loss value, and the process returns to the step of classifying each first sample data using the quantum neural network classifier to obtain the third predicted label corresponding to the first sample data, until the quantum neural network classifier converges at the current time to obtain the classifier to be trained.

9. The method according to claim 1, characterized in that, The step of classifying each training sample data using the classifier to be trained to obtain the first predicted label corresponding to the training sample data includes: For each training sample data, the training sample data is input into the classifier to be trained to obtain the confidence vector corresponding to the training sample data; Based on the confidence vector, the first predicted label corresponding to the training sample data is determined using the maximum likelihood algorithm.

10. The method according to claim 1, characterized in that, The step of calculating the first loss value of the classifier to be trained based on the sample label and the first predicted label corresponding to each training sample data includes: Based on the sample label and the first predicted label corresponding to each training sample data, the first loss value J(θ) of the classifier to be trained is calculated using the following formula. ′ ): Where, θ ′ The classifier parameters are those of the classifier to be trained. For the expected calculation, Let y(x,θ) be the loss function, c be the vector representation of the sample labels, and y(x,θ) be the loss function. ′ ) for x and θ ′ The confidence vector output by the classifier to be trained is given below, where ρ(x) is the quantum state corresponding to x, and x is the training sample data. Let x be the gradient. ∈ represents the preset perturbation coefficient. Let x be the gradient, and sign() be the sign function. For partial derivative calculation, x i For the i-th first sample data, w i For a predefined binary vector W = (w1, w2, ..., w m ) T The i-th vector element in the vector, where T is the transpose operation and m is the dimension of W. α is a preset threshold, N is the number of the first sample data, and x j,i Let be the i-th component of the j-th x.

11. A quantum neural network classifier training device, characterized in that, The device includes: The acquisition module is used to acquire a training dataset and a classifier to be trained. The training dataset includes multiple training sample data and a sample label corresponding to each training sample data. The training sample data includes first sample data and second sample data. The first sample data is quantum data generated based on the original data. The second sample data is generated based on the original data / first sample data and a preset perturbation coefficient. The original data is original image data or original initial state. The classifier to be trained is a quantum neural network classifier trained based on the first sample data. The classification module is used to classify each training sample data using the classifier to be trained, and obtain the first predicted label corresponding to the training sample data. The calculation module is used to calculate the first loss value of the classifier to be trained based on the sample label and the first predicted label corresponding to each training sample data. The adjustment module is used to adjust the classifier parameters of the classifier to be trained based on the first loss value when the classifier to be trained has not converged, and return to execute the step of classifying the training sample data using the classifier to be trained for each training sample data to obtain the first predicted label corresponding to the training sample data, until the classifier to be trained converges at the current time.

12. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the steps of the method described in any one of claims 1-10.

13. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method described in any one of claims 1-10.