A method for constructing an adversarial sample generation model and its application
By constructing an adversarial sample generation model based on singular value decomposition and reinforcement learning, we solve the problems of low computational efficiency and gradient-dependent adversarial sample generation in the existing technology, and achieve efficient and concealed adversarial sample generation, which is suitable for a variety of computers. Visual tasks.
Patent Information
- Application Number
- CN202210693348.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-17
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2042-06-17
AI Technical Summary
Existing gradient-based adversarial sample generation methods have low computational efficiency, repeated queries when generating adversarial samples, and need to know the gradient of the target model in advance, and the accuracy of adversarial samples is low.
Construct an adversarial sample generation model, including a cascaded perturbation module and a reward calculation module. It perturbs image samples through singular value decomposition and reinforcement learning models, maximizes the cumulative reward value of image samples, and generates adversarial samples without relying on the target. The gradient of the model.
The calculation efficiency is improved, and the generated adversarial samples are more concealed, suitable for real-life applications, and have a wider scope of application. There is no need to know the gradient of the target model in advance, and the generated adversarial samples are of higher quality.
Smart Images

Figure CN115019102B
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of artificial intelligence security, and more specifically, to a method for constructing an adversarial sample generation model and its application. Background Art
[0002] With the large-scale application of artificial intelligence, the security issue of artificial intelligence has gradually become a bottleneck limiting the scale of artificial intelligence application. The adversarial sample problem in artificial intelligence security is a key issue in ensuring the security of artificial intelligence. Fully and efficiently realizing the generation of adversarial samples is the premise and essence of achieving artificial intelligence security.
[0003] In order to generate adversarial samples in neural networks more efficiently, some algorithms are needed to modify the input samples. Among them, the gradient-based method is an effective adversarial sample generation algorithm. The generation process of adversarial samples is guided by the gradient direction of the target model until the generated model can output samples that cause the target model to misclassify but are visually similar to the input, that is, adversarial samples. This method of generating adversarial samples has the following problems. First, since the gradient-based method needs to iteratively modify the sample along the gradient direction to achieve the escape purpose, there are a large number of repeated queries when generating adversarial samples, which takes a long time to calculate and has low computational efficiency. Second, this method requires the gradient of the target model to be known in advance and is highly dependent on the gradient of the model. In real applications, the gradient of the target model is not available. Third, this method ignores the situation that different categories of images have different constraint values in the process of discovering adversarial samples. The difference in the norm constraint of adversarial samples is too small and the accuracy is low. Summary of the invention
[0004] In view of the above defects or improvement needs of the prior art, the present invention provides a method for constructing an adversarial sample generation model and its application, so as to solve the technical problem of low computational efficiency in the prior art.
[0005] In order to achieve the above objectives, in a first aspect, the present invention provides a method for constructing an adversarial sample generation model, comprising the following steps:
[0006] S1. Build an adversarial sample generation model; the adversarial sample generation model includes a cascaded perturbation module and a reward calculation module;
[0007] The perturbation module is used to perturb the image sample to obtain the perturbed image;
[0008] The reward calculation module is used to input the images before and after the disturbance into the neural network for target detection, and obtain the target categories and their corresponding classification confidences in the images before and after the disturbance; and calculate the changes in the target categories and corresponding classification confidences in the images before and after the disturbance, as well as the ratio of the image pixel differences before and after the current disturbance and before and after the last disturbance, to obtain the reward corresponding to the image sample;
[0009] S2. Input the image sample set into the adversarial sample generation model, and train the adversarial sample generation model by maximizing the cumulative value of the rewards corresponding to all image samples in the image sample set; when the adversarial sample generation model is trained, the perturbed image output by the perturbation module is the adversarial sample generated based on the image sample;
[0010] The image sample set includes several image samples of different categories and their corresponding real categories.
[0011] Further preferably, the perturbation module comprises a cascaded singular value decomposition module, a reinforcement learning model and an integration module;
[0012] The singular value decomposition module is used to perform singular value decomposition on the image samples to obtain the left singular matrix U, the singular value matrix Σ and the right singular matrix V of the image samples;
[0013] The reinforcement learning model is used to obtain the perturbation values of the singular value matrix Σ;
[0014] The integration module is used to perturb the singular value matrix Σ based on the perturbation value of the singular value matrix Σ to obtain the perturbed singular value matrix Σ'; calculate UΣ'V T , and get the perturbed image.
[0015] Further preferably, the singular value decomposition module is used to perform singular value decomposition on the image samples according to channels to obtain a left singular matrix, a singular value matrix and a right singular matrix under different channels of the image samples;
[0016] The above reinforcement learning model is used to obtain the perturbation values of the singular value matrix under different channels of the image samples;
[0017] The above integration module is used to perturb the singular value matrix under the corresponding channel based on the perturbation value of the singular value matrix under different channels of the image sample, and obtain the perturbed singular value matrix under different channels; calculate Get the perturbed image;
[0018] Where P is the number of channels of the image sample; U i is the left singular matrix of the image sample under the i-th channel; Σ i ' is the singular value matrix of the image sample after perturbation under the i-th channel; V iis the right singular matrix under the i-th channel of the image sample.
[0019] Further preferably, the perturbation module comprises a cascaded target extraction module, a singular value decomposition module, a reinforcement learning model and an integration module;
[0020] The target extraction module is used to extract the target area in the image sample to obtain the target sample;
[0021] The singular value decomposition module is used to perform singular value decomposition on the target sample to obtain the left singular matrix U of the target sample. t , singular value matrix Σ t and the right singular matrix V t ;
[0022] The reinforcement learning model is used to obtain the singular value matrix Σ t The disturbance value of
[0023] The integration module is used to calculate the singular value matrix Σ t The perturbation value of the singular value matrix Σ t Perform perturbation to obtain the perturbed singular value matrix Σ' t ; Calculate U t Σ t 'V t T After that, the target area in the image sample is replaced to obtain the perturbed image.
[0024] Further preferably, the singular value decomposition module is used to perform singular value decomposition on the target sample according to the channel to obtain a left singular matrix, a singular value matrix and a right singular matrix under different channels of the target sample;
[0025] The above reinforcement learning model is used to obtain the perturbation values of the singular value matrix of the target sample under different channels;
[0026] The above integration module is used to perturb the singular value matrix under the corresponding channel based on the perturbation value of the singular value matrix under different channels of the target sample, and obtain the perturbed singular value matrix under different channels; calculate and obtain After that, the target area in the target sample is replaced to obtain the disturbed image;
[0027] Where P is the number of channels of the target sample; U t_i is the left singular matrix of the target sample under the i-th channel; Σ t_i ' is the singular value matrix of the target sample after perturbation under the i-th channel; V t_i is the right singular matrix under the i-th channel of the target sample.
[0028] Further preferably, the rewards corresponding to the image samples include:
[0029] r1=P1w1
[0030] r2=P2w2
[0031]
[0032]
[0033] Among them, r1 is the reward when the target category in the image before and after the current perturbation is inconsistent; P1 is the total number of inconsistent target categories in the image before and after the current perturbation; w1 is the weight value when the target category in the image before and after the current perturbation is inconsistent; r2 is the reward when there is an unrecognized target in the image after the current perturbation; P2 is the number of unrecognized targets in the image after the current perturbation; w2 is the weight value when there is an unrecognized target in the image after the current perturbation; r3 is the reward when the classification confidence of the target in the image after the current perturbation decreases compared with the current pre-perturbation; K is the number of targets in the image sample; w3 is the weight value when the classification confidence of the target in the image after the current perturbation decreases compared with the current pre-perturbation; Conf j is the classification confidence of the jth target in the current perturbation image; Conf j ' is the classification confidence of the jth target in the image before the current disturbance; r4 is the hidden constraint penalty term; t is the disturbance round corresponding to the current disturbance; X t-1 is the image before the current disturbance; X t is the image after the current disturbance; X t-2 is the image before the last disturbance before the current disturbance; ||·|| p represents the p-norm.
[0034] Further preferably, step S2 includes: inputting the image sample set into the adversarial sample generation model, and training the adversarial sample generation model by maximizing the cumulative value of the rewards corresponding to all image samples in the image sample set, under the condition that the perturbation value of the image sample does not exceed the perturbation upper bound of its true category.
[0035] Further preferably, the method for obtaining the perturbation upper bound of category L includes: repeatedly perturbing the singular values of an image whose true category is category L until a pixel-level difference appears in the image before and after the perturbation, and at this time, calculating the difference value of the image pixels before and after the current perturbation as the perturbation upper bound of category L.
[0036] Further preferably, the method for obtaining the upper perturbation bound of category L comprises: performing the following operations on a plurality of images whose true category is category L respectively: repeatedly perturbing the singular values of the image until a pixel-level difference appears in the image before and after the perturbation, at which time, calculating the difference value of the image pixels before and after the current perturbation as the upper perturbation bound of the image;
[0037] The perturbation upper bounds of each image are summarized to obtain the perturbation upper bound of category L.
[0038] In a second aspect, the present invention provides an adversarial sample generation method, comprising: inputting an image into an adversarial sample generation model constructed using the above-mentioned adversarial sample generation model construction method to obtain an adversarial sample corresponding to the image.
[0039] In a third aspect, the present invention provides an adversarial sample generation system, comprising: a memory and a processor, wherein the memory stores a computer program, and the processor executes the adversarial sample generation method provided in the second aspect of the present invention when executing the computer program.
[0040] In a fourth aspect, the present invention provides a method for defending against adversarial samples, comprising:
[0041] Calculate the similarity between the current input image and each adversarial sample in the adversarial sample set respectively. If the similarity is less than a preset threshold, the current input image is determined to be an adversarial sample, and the original image category of the adversarial sample corresponding to the minimum similarity is output as the category of the current input image;
[0042] Among them, the method for obtaining the above-mentioned adversarial sample set includes: using the above-mentioned adversarial sample generation method to generate adversarial samples corresponding to original images of different categories.
[0043] In a fifth aspect, the present invention provides an adversarial sample defense system, comprising: a memory and a processor, wherein the memory stores a computer program, and the processor executes the adversarial sample defense method provided in the fourth aspect of the present invention when executing the computer program.
[0044] In a sixth aspect, the present invention further provides a computer-readable storage medium, comprising a stored computer program, wherein when the computer program is executed by a processor, the device where the storage medium is located is controlled to execute one or more of the method for constructing an adversarial sample generation model provided in the first aspect of the present invention, the method for generating adversarial samples provided in the second aspect of the present invention, and the method for defending against adversarial samples provided in the fourth aspect of the present invention.
[0045] In general, the above technical solutions conceived by the present invention can achieve the following beneficial effects:
[0046] 1. The present invention provides a method for constructing an adversarial sample generation model, constructs an adversarial sample generation model based on reinforcement learning, calculates the reward corresponding to the image sample by taking into account the changes in classification performance and pixel differences before and after disturbance, and trains the adversarial sample generation model by maximizing the cumulative value of the rewards corresponding to all image samples in the image sample set. By continuously optimizing the disturbance value during the training process of the adversarial sample generation model, the query is directed toward the desired goal, avoiding a large number of repeated queries, with short calculation time and high calculation efficiency.
[0047] 2. The adversarial sample generation model constructed by the adversarial sample generation model construction method provided by the present invention does not require prior knowledge of the gradient of the target model. It can efficiently generate adversarial samples for neural networks of various computer vision tasks including target detection and image recognition. It is suitable for real-world applications, has stronger practicality, and has a wider range of applications.
[0048] 3. The method for constructing the adversarial sample generation model provided by the present invention realizes the perturbation of the input image by perturbing the singular value matrix, and obtains structured features based on singular value decomposition, so as to generate more concealed adversarial samples, and the quality of the generated adversarial samples is higher.
[0049] 4. The method for constructing the adversarial sample generation model provided by the present invention, when perturbing an image, first extracts the target area in the image sample through the target extraction module, and then performs targeted perturbations on the singular value matrix of the target area, thereby reducing the number of iterations required to generate adversarial samples, and at the same time avoiding the situation where the change in the overall singular value of the image has no effect on some small targets.
[0050] 5. The method for constructing an adversarial sample generation model provided by the present invention takes into account that different categories of images have different constraint values in the process of discovering adversarial samples, and preferentially obtains the perturbation upper bounds of different categories of images. Under the condition that the perturbation value of the image sample does not exceed the perturbation upper bound of its true category, the adversarial sample generation model is trained by maximizing the cumulative value of the rewards corresponding to all image samples in the image sample set. This method can filter out images that are obviously not adversarial samples, increase the accuracy of the adversarial sample generation model, and also improve the training efficiency of the adversarial sample generation model.
[0051] 6. The present invention provides an adversarial sample defense method. Through the adversarial sample generation method based on the above-mentioned adversarial sample generation model provided by the present invention, adversarial samples corresponding to original images of different categories are generated, and then the current input image is compared with each adversarial sample in the adversarial sample set for similarity, so as to determine whether the current input image is an adversarial sample, and the defense efficiency is high. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] Figure 1 Flow chart of the method for constructing an adversarial sample generation model provided in Example 1 of the present invention. DETAILED DESCRIPTION
[0053] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0054] Embodiment 1,
[0055] A method for constructing an adversarial sample generation model, such as Figure 1 As shown, the following steps are included:
[0056] S1. Build an adversarial sample generation model; the adversarial sample generation model includes a cascaded perturbation module and a reward calculation module;
[0057] The perturbation module is used to perturb the image sample to obtain the perturbed image;
[0058] The reward calculation module is used to input the images before and after the disturbance into a neural network (preferably a convolutional neural network in this embodiment) for target detection, and obtain each target category and its corresponding classification confidence in the images before and after the disturbance; and calculate the changes in each target category and corresponding classification confidence in the images before and after the disturbance, as well as the ratio of the image pixel difference before and after the current disturbance and before and after the last disturbance, to obtain the reward corresponding to the image sample;
[0059] S2. Input the image sample set into the adversarial sample generation model, and train the adversarial sample generation model by maximizing the cumulative value of the rewards corresponding to all image samples in the image sample set; when the adversarial sample generation model is trained, the perturbed image output by the perturbation module is the adversarial sample generated based on the image sample;
[0060] The image sample set includes several image samples of different categories and their corresponding real categories.
[0061] The optimized perturbation strategy learned by the above method continuously optimizes the perturbation value during the training process of the adversarial sample generation model, so that the query is directed towards the desired target, avoiding a large number of repeated queries, with short calculation time and high calculation efficiency; in addition, the adversarial sample generation model can efficiently generate adversarial samples for neural networks of various computer vision tasks including target detection, image recognition, etc. without the need for target model gradients.
[0062] Specifically, the rewards corresponding to the image samples include:
[0063] r1=P1w1
[0064] r2=P2w2
[0065]
[0066]
[0067] Among them, r1 is the reward when the target category in the image before and after the current perturbation is inconsistent; P1 is the total number of inconsistent target categories in the image before and after the current perturbation; w1 is the weight value when the target category in the image before and after the current perturbation is inconsistent; r2 is the reward when there is an unrecognized target in the image after the current perturbation; P2 is the number of unrecognized targets in the image after the current perturbation; w2 is the weight value when there is an unrecognized target in the image after the current perturbation; r3 is the reward when the classification confidence of the target in the image after the current perturbation decreases compared with the current pre-perturbation; K is the number of targets in the image sample; w3 is the weight value when the classification confidence of the target in the image after the current perturbation decreases compared with the current pre-perturbation; Conf j is the classification confidence of the jth target in the current perturbation image; Conf j ' is the classification confidence of the jth target in the image before the current disturbance; r4 is the hidden constraint penalty term; t is the disturbance round corresponding to the current disturbance; X t-1 is the image before the current disturbance; X t is the image after the current disturbance; X t-2 is the image before the last disturbance before the current disturbance; ||·|| p represents the p-norm; the p-norm here can be the 0-norm, the 2-norm and the infinity-norm, preferably the 2-norm.
[0068] It should be noted that r1 and r2 are two direct ways to discover adversarial samples, that is, the original classification and the target classification are inconsistent or the target classification does not exist; r3 is a potential way to discover adversarial samples, that is, when the confidence of the original classification decreases; r4 is the hidden constraint penalty term of the adversarial sample, that is, the p-norm of the discovered adversarial sample and the original sample is used as a negative reward value.
[0069] It should be noted that the perturbation module obtains the structural features of the image sample based on singular value decomposition, and perturbs the image sample by perturbing the singular value matrix of the image sample or the target sample on it; wherein the specific perturbation target of the adversarial sample generation model can be the complete image sample or the target part contained in the image sample (i.e., the target sample).
[0070] In an optional implementation, the perturbation module includes a cascaded singular value decomposition module, a reinforcement learning model and an integration module; wherein the singular value decomposition module is used to perform singular value decomposition on the image sample to obtain the left singular matrix U, the singular value matrix Σ and the right singular matrix V of the image sample; the reinforcement learning model is used to obtain the perturbation value of the singular value matrix Σ; the integration module is used to perturb the singular value matrix Σ based on the perturbation value of the singular value matrix Σ to obtain the perturbed singular value matrix Σ'; calculate UΣ'V T , and obtain the perturbed image. Preferably, in the above optional implementation mode, when performing singular value decomposition and integration on the image samples, the above singular value decomposition module is used to perform singular value decomposition on the image samples according to channels, and obtain the left singular matrix, singular value matrix and right singular matrix under different channels of the image samples. The above reinforcement learning model is used to obtain the perturbation value of the singular value matrix under different channels of the image samples. The above integration module is used to perturb the singular value matrices under corresponding channels based on the perturbation values of the singular value matrices under different channels of the image samples, and obtain the perturbed singular value matrices under different channels; calculate Get the perturbed image; where P is the number of channels of the image sample; U i is the left singular matrix of the image sample under the i-th channel; Σ i ' is the singular value matrix of the image sample after perturbation under the i-th channel; V i is the right singular matrix under the i-th channel of the image sample.
[0071] In another optional implementation mode 2, in order to strengthen the targeted perturbation of the target object, reduce the number of iterations required to generate adversarial samples, and avoid the situation where the overall singular value change of the image has no effect on some small targets, the perturbation module includes a cascaded target extraction module, a singular value decomposition module, a reinforcement learning model and an integration module; wherein the target extraction module is used to extract the target area in the image sample to obtain the target sample; the singular value decomposition module is used to perform singular value decomposition on the target sample to obtain the left singular matrix U of the target sample. t , singular value matrix Σ t and the right singular matrix V t ; The reinforcement learning model is used to obtain the singular value matrix Σ t The integration module is used to calculate the disturbance value based on the singular value matrix Σ t The perturbation value of the singular value matrix Σt Perform perturbation to obtain the perturbed singular value matrix Σ' t ; Calculate U t Σ t 'V t T After that, the target area in the image sample is replaced to obtain the perturbed image. It should be noted that the above-mentioned target extraction module can calibrate the size and position of the target sample through a known label or a target detector to extract the target area in the image sample. Specifically, in the case of a given label, the position and size of the target sample are obtained by the position and size calibrated by the label; in the case of no given label, the size and position of the target sample can be obtained by detecting the image sample through an existing pre-trained target detector. Preferably, under the above-mentioned optional implementation mode 2, when performing singular value decomposition and integration on the image samples, the above-mentioned singular value decomposition module is used to perform singular value decomposition on the image samples according to channels to obtain the left singular matrix, singular value matrix and right singular matrix under different channels of the image samples. The singular value decomposition module is used to perform singular value decomposition on the target sample according to the channel, and obtain the left singular matrix, singular value matrix and right singular matrix of the target sample under different channels; the reinforcement learning model is used to obtain the perturbation value of the singular value matrix of the target sample under different channels; the integration module is used to perturb the singular value matrix under the corresponding channel based on the perturbation value of the singular value matrix under different channels of the target sample, and obtain the perturbed singular value matrix under different channels; the calculation is obtained After that, the target area in the target sample is replaced to obtain the perturbed image; where P is the number of channels of the target sample; U t_i is the left singular matrix of the target sample under the i-th channel; Σ t_i ' is the singular value matrix of the target sample after perturbation under the i-th channel; V t_i is the right singular matrix under the i-th channel of the target sample.
[0072] Preferably, in order to filter out images that are obviously not adversarial samples, increase the accuracy of the adversarial sample generation model, and improve the training efficiency of the adversarial sample generation model; the above-mentioned step S2 includes: inputting the image sample set into the adversarial sample generation model, and training the adversarial sample generation model by maximizing the cumulative value of the rewards corresponding to all image samples in the image sample set, under the condition that the perturbation value of the image sample does not exceed the perturbation upper bound of its true category.
[0073] Specifically, in an optional implementation, a method for obtaining the upper bound of the perturbation of category L includes: repeatedly perturbing the singular values of an image whose true category is category L until a pixel-level difference appears in the image before and after the perturbation, and at this time, calculating the difference value of the image pixels before and after the current perturbation as the upper bound of the perturbation of category L.
[0074] In another optional implementation, the method for obtaining the upper perturbation bound of category L includes: performing the following operations on several images whose true category is category L respectively: repeatedly perturbing the singular values of the image until a pixel-level difference appears in the image before and after the perturbation, at which time, calculating the difference between the image pixels before and after the current perturbation as the upper perturbation bound of the image; summarizing the perturbation bounds of each image obtained to obtain the upper perturbation bound of category L. Specifically, the average value of the upper perturbation bounds of each image obtained can be used as the upper perturbation bound of category L, and the upper perturbation bounds of each image obtained can also be first subjected to the Grubbs test to remove outliers, and then the average value is taken as the upper perturbation bound of category L. When measuring the perturbation bound of the input image, this specific implementation measured more than 100,000 images, and obtained appropriate perturbation bound values through control experiments and extreme value filtering methods.
[0075] In the above two optional implementations, the p-norm, that is, the difference between each element in the input image and the iteratively perturbed image, is calculated during the perturbation process, and then a loop is used to find the critical point of the perturbation value, so that the classification result of the perturbed image is inconsistent with the classification detection result of the original image.
[0076] It should be noted that the constraint formula of the p-norm is ||x-x'|| p ; where x and x' represent the input image and the image generated after perturbation, respectively, and p represents the calculation method of the norm, which can be 0, 2, or infinity. In the second optional implementation, not only the constraints of a single modification are considered, but also the cumulative constraints of continuous modifications. The larger the norm, the greater the visual gap between it and the original sample, and the lower the threat of becoming a potential adversarial sample.
[0077] In order to further illustrate the training process of the adversarial sample generation model provided by the present invention, a three-dimensional image (P value is 3) is taken as an example for detailed description below, and a reinforcement learning agent (i.e., an adversarial sample generation model) is constructed. Its environment is defined as the concatenation of the perturbed image pixel matrix and the perturbed singular value matrix. Its action is to perturb the three-channel singular value matrix of the input image, and the input image singular value matrix is continuously perturbed by the agent.
[0078] The reinforcement learning agent is used to generate perturbed images, and its exploration and discovery method is as follows:
[0079]
[0080] The optimized perturbation strategy is P * , by calculating the expected maximum reward R, the optimized action generated for a given state s under the current strategy p. For the input three-dimensional image x∈R m×n×3, since the computational complexity and time complexity of the direct decomposition method of three-dimensional data are relatively high, this embodiment performs SVD decomposition on the three-dimensional image according to the channels. Specifically, the input three-channel image is subjected to singular value decomposition according to the channels to obtain the singular value matrices of the three channels respectively; the image x of the i-th channel of the original image is i , whose size is m×n; its singular value decomposition is: x i =U i Σ i V i T , i = 1, 2, 3; by calculating the three-channel singular value matrix, we get Σ i =[x i v i (1) / u i (1) ,…,x i v i (r) / u i (r) ]; where r is x i The rank, u i is the left singular vector of the i-th channel of the image (u i (r) for u i The rth value in i is the right singular vector of the i-th channel of the image (v i (r) v i The rth value in ); then generate the reinforcement learning action A = [a1, a2, a3], where a1, a2 and a3 are the perturbation values of the singular value matrix corresponding to different channels of the three-dimensional image; add the singular value matrix and its corresponding perturbation value according to the channel to obtain Σ' = [Σ1', Σ2', Σ3']; through the inverse operation of singular value decomposition, the new image is obtained That is the state after disturbance.
[0081] The above reinforcement learning agent is updated according to the value function network ν(·) and Q network contained in it:
[0082]
[0083] Where λ is the discount factor, which is usually set to 0.99, and r t is the reward value obtained by the agent at time t, s t+1 is the state of the reinforcement learning agent at time t+1. The update method of the value function network ν(·) is:
[0084]
[0085] The value function is the expected reward for performing action a in state s at time step t+1. Therefore, the loss function used to optimize the strategy is calculated as:
[0086]
[0087] Among them, H0 is the entropy threshold, usually -2; α is the temperature hyperparameter used to optimize the randomness of the strategy.
[0088] In this embodiment, the strategy network P is updated in sequence. Φ Sum value function network Q Λ To update the deep reinforcement learning agent. When the iteration round of the deep reinforcement learning agent exceeds a certain threshold (set to 1000 in this embodiment), the iteration is terminated.
[0089] Embodiment 2,
[0090] A method for generating an adversarial sample comprises: inputting an image into an adversarial sample generation model constructed by adopting the method for constructing an adversarial sample generation model provided by Embodiment 1 of the present invention, and obtaining an adversarial sample corresponding to the image.
[0091] The relevant technical solution is the same as that in Example 1 and will not be described in detail here.
[0092] Embodiment 3,
[0093] An adversarial sample generation system includes: a memory and a processor, wherein the memory stores a computer program, and the processor executes the adversarial sample generation method provided in Embodiment 2 of the present invention when executing the computer program.
[0094] The relevant technical solution is the same as that in Example 2 and will not be described in detail here.
[0095] Embodiment 4,
[0096] A method for defending against adversarial samples, comprising:
[0097] Calculate the similarity between the current input image and each adversarial sample in the adversarial sample set respectively. If the similarity is less than a preset threshold, the current input image is determined to be an adversarial sample, and the current input image is marked and rejected from entering the target system. At the same time, the original image category of the adversarial sample corresponding to the minimum similarity is output as the category of the current input image; otherwise, the current input image is input into the neural network for target detection; in this embodiment, the preset threshold value is 0.1;
[0098] Among them, the method for obtaining the above-mentioned adversarial sample set includes: using the adversarial sample generation method provided by Example 2 of the present invention to generate adversarial samples corresponding to original images of different categories.
[0099] It should be noted that there are many methods for calculating the similarity between the current input image and each adversarial sample in the adversarial sample set. In this embodiment, the cosine similarity between the current input image and each adversarial sample in the adversarial sample set is calculated to measure the similarity between the two. Specifically, the measurement formula of cosine similarity is: Where x1 and x2 are the current input image and an adversarial sample in the adversarial sample set. The defense against adversarial samples is achieved by calculating the cosine similarity between the new input image and the existing adversarial samples.
[0100] The relevant technical solution is the same as that in Example 2 and will not be described in detail here.
[0101] Embodiment 5,
[0102] An adversarial sample defense system includes: a memory and a processor, wherein the memory stores a computer program, and the processor executes the adversarial sample defense method provided in Embodiment 4 of the present invention when executing the computer program.
[0103] The relevant technical solution is the same as that in Example 4 and will not be described in detail here.
[0104] Embodiment 6,
[0105] The present invention also provides a computer-readable storage medium, which includes a stored computer program, wherein when the computer program is executed by a processor, the device where the storage medium is located is controlled to execute one or more of the method for constructing an adversarial sample generation model provided in Example 1 of the present invention, the method for generating adversarial samples provided in Example 2 of the present invention, and the method for defending against adversarial samples provided in Example 4 of the present invention.
[0106] The relevant technical solutions are the same as those in Example 1, Example 2 and Example 4, and will not be described in detail here.
[0107] In summary, it can be seen from Examples 1 to 6 of the present invention that when measuring the disturbance boundary of an image category, the present invention obtains appropriate disturbance boundary values through control experiments and extreme value filtering methods. When the input image is singular value decomposed, the input of the three channels is decomposed three times respectively, and the obtained singular values are stored, which effectively enhances the discovery of adversarial samples with strong visual concealment. When the singular value matrix of the cyclic perturbation image is used, an optimized perturbation strategy is obtained by deep reinforcement learning training, thereby reducing the number of queries required for each adversarial sample to be discovered. When generating and defending adversarial samples, a suitable reward function is set to optimize the generation process, and the discovered samples are defended by the similarity comparison method of the singular value matrix. Theory and experiments have proved that compared with existing methods such as DPatch, AutoAttacker, and ZOO, the adversarial sample generation model provided by the present invention has better performance in terms of adversarial sample generation accuracy, sample migration ability, and number of queries.
[0108] It will be easily understood by those skilled in the art that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for constructing an adversarial sample generation model, characterized in that: The following steps are involved: S1. Building an adversarial sample generation model; the adversarial sample generation model includes a cascaded perturbation module and a reward calculation module; The perturbation module is used to perturb the image sample to obtain a perturbed image; The reward calculation module is used to input the images before and after the disturbance into the neural network for target detection, and obtain the target categories and their corresponding classification confidences in the images before and after the disturbance; and calculate the changes in the target categories and corresponding classification confidences in the images before and after the disturbance, as well as the ratio of the image pixel differences before and after the current disturbance and before and after the last disturbance, to obtain the reward corresponding to the image sample; S2, inputting the image sample set into the adversarial sample generation model, and training the adversarial sample generation model by maximizing the cumulative value of the rewards corresponding to all image samples in the image sample set; when the adversarial sample generation model is trained, the perturbed image output by the perturbation module is the adversarial sample generated based on the image sample; The image sample set includes image samples of several different categories and their corresponding real categories.
2. The method for constructing an adversarial sample generation model according to claim 1, characterized in that: The perturbation module includes a cascaded singular value decomposition module, a reinforcement learning model and an integration module; The singular value decomposition module is used to perform singular value decomposition on the image samples to obtain the left singular matrix U, the singular value matrix Σ and the right singular matrix V of the image samples; The reinforcement learning model is used to obtain the perturbation value of the singular value matrix Σ; The integration module is used to perturb the singular value matrix Σ based on the perturbation value of the singular value matrix Σ to obtain the perturbed singular value matrix Σ'; calculate UΣ'V T , and get the perturbed image.
3. The method for constructing an adversarial sample generation model according to claim 2, characterized in that: The singular value decomposition module is used to perform singular value decomposition on the image samples according to the channels to obtain the left singular matrix, singular value matrix and right singular matrix under different channels of the image samples; The reinforcement learning model is used to obtain the perturbation value of the singular value matrix under different channels of the image sample; The integration module is used to perturb the singular value matrices under the corresponding channels based on the perturbation values of the singular value matrices under different channels of the image samples, and obtain the perturbed singular value matrices under different channels; calculate Get the perturbed image; Where P is the number of channels of the image sample; U i is the left singular matrix of the image sample under the i-th channel; Σ i ' is the singular value matrix of the image sample after perturbation under the i-th channel; V i is the right singular matrix under the i-th channel of the image sample.
4. The method for constructing an adversarial sample generation model according to claim 1, characterized in that: The disturbance module includes a cascaded target extraction module, a singular value decomposition module, a reinforcement learning model and an integration module; The target extraction module is used to extract the target area in the image sample to obtain the target sample; The singular value decomposition module is used to perform singular value decomposition on the target sample to obtain the left singular matrix U of the target sample t , singular value matrix Σ t and the right singular matrix V t ; The reinforcement learning model is used to obtain the singular value matrix Σ t The disturbance value of The integration module is used to integrate the singular value matrix Σ t The perturbation value of the singular value matrix Σ t Perform perturbation to obtain the perturbed singular value matrix Σ' t ; Calculate U t Σ t 'V t T Then, the target area in the image sample is replaced to obtain a disturbed image.
5. The method for constructing an adversarial sample generation model according to any one of claims 1 to 4, characterized in that: The rewards corresponding to the image samples include: r1=P1w1 r2=P2w2 Among them, r1 is the reward when the target category in the image before and after the current perturbation is inconsistent; P1 is the total number of inconsistent target categories in the image before and after the current perturbation; w1 is the weight value when the target category in the image before and after the current perturbation is inconsistent; r2 is the reward when there is an unrecognized target in the image after the current perturbation; P2 is the number of unrecognized targets in the image after the current perturbation; w2 is the weight value when there is an unrecognized target in the image after the current perturbation; r3 is the reward when the classification confidence of the target in the image after the current perturbation decreases compared with the current pre-perturbation; K is the number of targets in the image sample; w3 is the weight value when the classification confidence of the target in the image after the current perturbation decreases compared with the current pre-perturbation; Conf j is the classification confidence of the jth target in the current perturbation image; Conf j ' is the classification confidence of the jth target in the image before the current disturbance; r4 is the hidden constraint penalty term; t is the disturbance round corresponding to the current disturbance; X t-1 is the image before the current disturbance; X t is the image after the current disturbance; X t-2 is the image before the last disturbance before the current disturbance; ||·|| p represents the p-norm.
6. The method for constructing an adversarial sample generation model according to any one of claims 1 to 4, characterized in that: The step S2 comprises: inputting the image sample set into the adversarial sample generation model, and training the adversarial sample generation model by maximizing the cumulative value of rewards corresponding to all image samples in the image sample set, under the condition that the perturbation value of the image sample does not exceed the perturbation upper bound of its true category.
7. The method for constructing an adversarial sample generation model according to claim 6, characterized in that: Methods for obtaining the upper bound of the perturbation of category L include: method 1 and method 2; The first method comprises: repeatedly perturbing the singular values of an image whose true category is category L until a pixel-level difference appears in the image before and after the perturbation, and at this time, calculating the difference value of the image pixels before and after the current perturbation as the perturbation upper bound of category L; The second method comprises: performing the following operations on a plurality of images whose true category is category L respectively: repeatedly perturbing the singular values of the image until a pixel-level difference appears in the image before and after the perturbation, at which time, calculating the difference value of the image pixels before and after the current perturbation as the perturbation upper bound of the image; The perturbation upper bounds of each image are summarized to obtain the perturbation upper bound of category L.
8. A method for generating adversarial samples, characterized in that: include: The image is input into the adversarial sample generation model constructed by the method for constructing an adversarial sample generation model described in any one of claims 1 to 7 to obtain the adversarial sample corresponding to the image.
9. A method for defending against adversarial samples, characterized in that: include: Calculate the similarity between the current input image and each adversarial sample in the adversarial sample set respectively. If the similarity is less than a preset threshold, the current input image is determined to be an adversarial sample, and the original image category of the adversarial sample corresponding to the minimum similarity is output as the category of the current input image; The method for acquiring the adversarial sample set comprises: using the adversarial sample generation method according to claim 8 to generate adversarial samples corresponding to original images of different categories.
10. A computer-readable storage medium, the computer-readable storage medium comprising a stored computer program, wherein: When the computer program is executed by the processor, the device where the storage medium is located is controlled to execute one or more of the method for constructing an adversarial sample generation model described in any one of claims 1 to 7, the method for generating adversarial samples described in claim 8, and the method for defending against adversarial samples described in claim 9.
