Adversarial sample generation method and system based on self-attention mechanism

Through the adversarial sample generation method based on the self-attention mechanism, the problem of the impact of deep neural network on the adversarial sample is solved, the robustness and security of the model are improved, the generated adversarial samples are more concealed, and the discriminator model judgment ability is more accurate , enhancing security in the field of computer vision.

CN119089973AActive Publication Date: 2024-12-06NANJING UNIV OF AERONAUTICS & ASTRONAUTICS
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202410963646.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-18
Publication Date
2024-12-06
Estimated Expiration
2044-07-18

AI Technical Summary

Technical Problem

Deep neural networks are easily affected by adversarial samples, resulting in safety hazards. Especially in safety-critical systems, such as autonomous driving systems, it is difficult to correctly identify traffic signs or detect pedestrians, traditional software testing methods are difficult to directly apply to deep learning models, and computer vision Domain confrontation samples are threatening, affecting the robustness and interpretability of the model.

Method used

Adopting an adversarial sample generation method based on self-attention mechanism, by constructing a generator model and a multi-convolution discriminator model, the design loss function includes misjudgment loss, adversarial loss and hinge loss, and using the self-attention layer to capture the long distance of image features. Dependencies generate effective adversarial perturbations, and dynamic balance is achieved through alternate optimization of training models, generator models and discriminator models.

Benefits of technology

Improve the robustness and security of the deep learning model, the generated adversarial samples are more concealed, and the discriminator model is more accurate when judging the authenticity of the input data, balances feature extraction capabilities and computing resource requirements, and enhances the capability of the model. Explanation and security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119089973A_ABST
    Figure CN119089973A_ABST
Patent Text Reader

Abstract

The invention discloses an adversarial sample generation method and system based on a self-attention mechanism. The method comprises the following steps: constructing a generator model by using a convolutional neural network; constructing a multi-convolution discriminator model; designing a loss function, wherein the loss function is composed of a misjudgment loss function, an adversarial loss function and a hinge loss function; the misjudgment loss function is used for guiding the generator model to train in the adversarial sample direction, the adversarial loss function is used for maintaining dynamic balance of the performance of the generator and the discriminator, and the hinge loss function is used for limiting the adversarial disturbance output by the generator model; carrying out alternative optimization and adversarial training on the generator model and the multi-convolution discriminator model by adopting the training data set under the guidance of the loss function, and finally storing the trained generator model after the performances of the generator model and the multi-convolution discriminator model reach dynamic balance; and inputting the original sample into the trained generator model to generate adversarial disturbance, and superposing the generated adversarial disturbance with the original sample to obtain an adversarial sample.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of artificial intelligence security, and specifically relates to a method and system for generating adversarial samples based on a self-attention mechanism. Background Art

[0002] Deep neural networks are vulnerable to adversarial examples, which are difficult to distinguish with the naked eye but may cause deep neural networks to produce incorrect outputs, thus posing serious safety risks. The existence of adversarial examples hinders the practical application of deep learning in safety-critical systems. For example, in autonomous driving systems, adversarial examples in input images may prevent the model from correctly identifying traffic signs or detecting pedestrians, leading to serious traffic accidents. Therefore, in systems with higher safety requirements, more robust neural network models are needed.

[0003] Due to the black-box nature of deep neural networks, traditional software testing methods are difficult to directly apply to deep learning models. Adversarial testing is a testing method suitable for deep neural networks. This method intentionally introduces perturbations to the input data and observes the changes in the model's output before and after the perturbations are added, thereby evaluating the model's stability and robustness to small changes in the input data and helping to identify potential vulnerabilities in the model.

[0004] Computer vision is one of the fields that currently relies heavily on deep learning. More and more deep learning technologies are being applied to image recognition tasks, and adversarial samples with perturbations have become the primary threat. In terms of image classification, adversarial samples refer to image samples that are intentionally synthesized by attackers who add tiny perturbations that are difficult for the human eye to distinguish to the original image. Attackers use such synthesized images as input to the classifier, causing it to misjudge and achieve the purpose of the attack.

[0005] In recent years, many scholars have begun to pay attention to the problem of adversarial samples in image neighborhoods. The research on adversarial samples in image classification is very important: first, the research on adversarial samples helps to deeply understand the working principle and prediction mechanism of deep learning models. By analyzing the generation process of adversarial samples, the weak links in the decision-making process of the model can be revealed, thereby improving the interpretability of the model; second, because computer vision is large in scale, developing rapidly, and has a wide range of application scenarios, the risk of adversarial attacks is greater. Therefore, the research on adversarial samples helps to improve the robustness, security, and interpretability of deep learning models, and provide security for their application in the real world. Summary of the invention

[0006] Purpose of the invention: In order to ensure the security, reliability and robustness of deep learning models in real-world applications, the present invention proposes a method and system for generating adversarial samples based on a self-attention mechanism.

[0007] Technical solution: A method for generating adversarial samples based on a self-attention mechanism, comprising the following steps:

[0008] A generator model is constructed, the generator model comprising an encoder and a decoder; the encoder comprises a first input layer, unit one, unit two, unit three and unit four which are connected in sequence; unit one is composed of a first convolutional layer, a first batch normalization layer and a first Leaky Relu layer, unit two is composed of a second convolutional layer, a second batch normalization layer and a second Leaky Relu layer, unit three is composed of a third convolutional layer, a third batch normalization layer and a third Leaky Relu layer, and unit four is composed of a fourth convolutional layer, a first self-attention layer, a fourth batch normalization layer and a fourth Leaky Relu layer; the output of unit one is connected to the output of unit three through a residual connection module; the decoder comprises a fifth unit, a sixth unit, a seventh unit and a eighth unit which are connected in sequence; unit five is composed of a fifth convolutional layer, a second self-attention layer, a fifth batch normalization layer and a fifth Leaky Relu layer, unit five is composed of a first deconvolutional layer, a sixth batch normalization layer and a sixth Leaky Relu layer, unit six is ​​composed of a second deconvolutional layer, a seventh batch normalization layer and a seventh Leaky Relu layer The Relu layer constitutes unit seven, and the third deconvolution layer, the seventh batch normalization layer and the seventh LeakyRelu layer constitute unit seven;

[0009] Constructing a multi-convolution discriminator model, the multi-convolution discriminator model comprising a second input layer, a sixth convolution layer, a seventh convolution layer, an eighth convolution layer and a ninth convolution layer connected in sequence; the second input layer is used to input the original data sample and the adversarial sample generated by the generator model;

[0010] Designing a loss function, wherein the loss function is composed of a misjudgment loss function, an adversarial loss function, and a hinge loss function; the misjudgment loss function is used to guide the generator model to train in the direction of adversarial samples, the adversarial loss function is used to maintain a dynamic balance between the performance of the generator and the discriminator, and the hinge loss function is used to limit the adversarial perturbation size output by the generator model;

[0011] Under the guidance of the loss function, the training data set is used to alternately optimize the generator model and the multi-convolution discriminator model, and adversarial training is performed. After the performance of the final generator model and the multi-convolution discriminator model reaches a dynamic balance, the trained generator model is saved;

[0012] The original sample is input into the trained generator model to generate adversarial perturbations, and the generated adversarial perturbations are superimposed on the original sample to obtain adversarial samples.

[0013] Furthermore, the mapping process from the convolution feature map output by the convolution layer to the self-attention feature map output by the self-attention layer is expressed as:

[0014] The convolution feature map output by the convolution layer is X = (x1, x2, x3, ..., x n ), X∈R C×N , where C and N are the number of channels and feature positions of the input feature map respectively;

[0015] First, a convolution kernel of size 1x1 is used to linearly transform the values ​​of the C channels of each pixel, and the image features are transformed into two feature spaces f and g respectively, where f(x) = W f x,g(x)=W g x, transpose the feature operation output of the i-th position and multiply it with the feature space output of the j-th position, and then normalize it to get the attention weight between the two positions, which is specifically expressed as:

[0016]

[0017] In the formula, β j,i Indicates the degree of dependence of the model on the i-th position in the process of synthesizing the j-th region of the image under the self-attention framework; s ij Represents the weight between the i-th position and the j-th position in the image, which is used for subsequent attention weight calculation;

[0018] After the above operation, we get the attention map, which is multiplied by the feature map in the feature space h, and then passed through the weight matrix W v The final output is O = (O1, O2, ..., O j ,...,O N ),in:

[0019]

[0020] Where W h and W v is the weight matrix obtained by 1x1 convolution kernel operation, v represents the weight matrix of x i Using the weight matrix W v The transformation operation performed, h(x i ) represents x i Through the weight matrix W h The transformed value;

[0021] Finally, O j Multiplying by a learnable scalar λ and superimposing the original input feature map, we get the feature map that incorporates attention:

[0022] y i =λO i +x i .

[0023] Furthermore, the misjudgment loss function is expressed as:

[0024] L adv =E x λ f (x+G(x),t)

[0025] Among them, f is the target attack model, t is the true label of the input data x, and λ f It reflects the recognition ability of the target attack model f on the synthetic samples, E x It represents the expected value of the input data x, and G(x) represents the adversarial perturbation generated by the generator model.

[0026] Furthermore, the adversarial loss function is expressed as:

[0027] L GAN =E x logD(x)+E x log(1-D(x+G(x)))

[0028] Among them, E x It represents the expected value of the input data x, G(x) represents the adversarial perturbation generated by the generator model, and D(x) represents the probability that the discriminator model judges that the sample is true.

[0029] Furthermore, the hinge loss function is expressed as:

[0030] L hinge =E x max(0,||G(x)||2-c)

[0031] Among them, the constant c is the optimization boundary of the perturbation, G(x) represents the adversarial perturbation generated by the generator model, and ||·||2 represents the l2 norm of the adversarial perturbation.

[0032] The present invention discloses an adversarial sample generation system based on a self-attention mechanism, comprising:

[0033] The trained generator model is used to generate adversarial perturbations of the original samples;

[0034] The adversarial sample generation module is used to superimpose the generated adversarial perturbation with the original sample to obtain the adversarial sample;

[0035] The trained generator model is obtained by following the steps below:

[0036] A generator model is constructed, the generator model comprising an encoder and a decoder; the encoder comprises a first input layer, unit one, unit two, unit three and unit four which are connected in sequence; unit one is composed of a first convolutional layer, a first batch normalization layer and a first Leaky Relu layer, unit two is composed of a second convolutional layer, a second batch normalization layer and a second Leaky Relu layer, unit three is composed of a third convolutional layer, a third batch normalization layer and a third Leaky Relu layer, and unit four is composed of a fourth convolutional layer, a first self-attention layer, a fourth batch normalization layer and a fourth Leaky Relu layer; the output of unit one is connected to the output of unit three through a residual connection module; the decoder comprises a fifth unit, a sixth unit, a seventh unit and a eighth unit which are connected in sequence; unit five is composed of a fifth convolutional layer, a second self-attention layer, a fifth batch normalization layer and a fifth Leaky Relu layer, unit five is composed of a first deconvolutional layer, a sixth batch normalization layer and a sixth Leaky Relu layer, unit six is ​​composed of a second deconvolutional layer, a seventh batch normalization layer and a seventh Leaky Relu layer The Relu layer constitutes unit seven, and the third deconvolution layer, the seventh batch normalization layer and the seventh LeakyRelu layer constitute unit seven;

[0037] Constructing a multi-convolution discriminator model, the multi-convolution discriminator model comprising a second input layer, a sixth convolution layer, a seventh convolution layer, an eighth convolution layer and a ninth convolution layer connected in sequence; the second input layer is used to input the original data sample and the adversarial sample generated by the generator model;

[0038] Designing a loss function, wherein the loss function is composed of a misjudgment loss function, an adversarial loss function, and a hinge loss function; the misjudgment loss function is used to guide the generator model to train in the direction of adversarial samples, the adversarial loss function is used to maintain a dynamic balance between the performance of the generator and the discriminator, and the hinge loss function is used to limit the adversarial perturbation size output by the generator model;

[0039] Under the guidance of the loss function, the training data set is used to alternately optimize the generator model and the multi-convolution discriminator model, and conduct adversarial training. Finally, when the performance of the generator model and the multi-convolution discriminator model reaches a dynamic balance, the trained generator model is obtained.

[0040] Furthermore, the mapping process from the convolution feature map output by the convolution layer to the self-attention feature map output by the self-attention layer is expressed as:

[0041] The convolution feature map output by the convolution layer is X = (x1, x2, x3, ..., x n ), X∈R C×N , where C and N are the number of channels and feature positions of the input feature map respectively;

[0042] First, a convolution kernel of size 1x1 is used to linearly transform the values ​​of the C channels of each pixel, and the image features are transformed into two feature spaces f and g respectively, where f(x) = W f x,g(x)=W g x, transpose the feature operation output of the i-th position and multiply it with the feature space output of the j-th position, and then normalize it to get the attention weight between the two positions, which is specifically expressed as:

[0043]

[0044] In the formula, β j,i Indicates the degree of dependence of the model on the i-th position in the process of synthesizing the j-th region of the image under the self-attention framework; s ij Represents the weight between the i-th position and the j-th position in the image, which is used for subsequent attention weight calculation;

[0045] After the above operation, we get the attention map, which is multiplied by the feature map in the feature space h, and then passed through the weight matrix W v The final output is O = (O1, O2, ..., O j ,...,O N ),in:

[0046]

[0047] Where W h and W v is the weight matrix obtained by 1x1 convolution kernel operation, v represents the weight matrix of x i Using the weight matrix W v The transformation operation performed, h(x i ) represents x i Through the weight matrix W h The transformed value;

[0048] Finally, O j Multiplying by a learnable scalar λ and superimposing the original input feature map, we get the feature map that incorporates attention:

[0049] y i =λO i +x i .

[0050] Furthermore, the misjudgment loss function is expressed as:

[0051] L adv =E x λ f (x+G(x),t)

[0052] Among them, f is the target attack model, t is the true label of the input data x, and λ f It reflects the recognition ability of the target attack model f on the synthetic samples, E x It represents the expected value of the input data x, and G(x) represents the adversarial perturbation generated by the generator model.

[0053] Furthermore, the adversarial loss function is expressed as:

[0054] L GAN =E x logD(x)+E x log(1-D(x+G(x)))

[0055] Among them, E x It represents the expected value of the input data x, G(x) represents the adversarial perturbation generated by the generator model, and D(x) represents the probability that the discriminator model judges that the sample is true.

[0056] Furthermore, the hinge loss function is expressed as:

[0057] L hinge =E x max(0,||G(x)||2-c)

[0058] Among them, the constant c is the optimization boundary of the perturbation, G(x) represents the adversarial perturbation generated by the generator model, and ||·||2 represents the l2 norm of the adversarial perturbation.

[0059] Beneficial effects: Compared with the prior art, the present invention has the following advantages:

[0060] (1) The present invention uses a convolutional neural network to construct a generator model, which can effectively process image data; and introduces a self-attention mechanism into the generator model to capture long-distance dependencies and high-dimensional features in the latent space, thereby improving the concealment of adversarial samples;

[0061] (2) The present invention uses four convolutional layers to construct a discriminator model, so that the discriminator model is more accurate in judging the authenticity of input data; at the same time, the four-layer convolutional structure can better balance the feature extraction capability and computing resource requirements without excessively increasing the complexity of the model. BRIEF DESCRIPTION OF THE DRAWINGS

[0062] Figure 1 This is the structure diagram of the generator model;

[0063] Figure 2 This is the structure diagram of the discriminator model;

[0064] Figure 3 Diagram of the mapping process from convolutional feature map to self-attention feature map. DETAILED DESCRIPTION

[0065] The method of the present invention is further described below in conjunction with the accompanying drawings and embodiments.

[0066] Embodiment 1:

[0067] This embodiment proposes a method for generating adversarial samples based on a self-attention mechanism, which mainly includes the following steps:

[0068] A convolutional neural network is used to construct a generator model, which includes: a convolutional layer, a self-attention layer, and a deconvolution layer; the convolutional layer is used to encode the input image and capture the local features and high-dimensional features in the image; the self-attention layer is used to capture the long-distance dependencies and high-dimensional features of the latent space; the deconvolution layer is used to reconstruct the low-dimensional features, gradually enlarge the feature map, and restore its spatial dimension. The generator model constructed in this embodiment learns the feature distribution of the original data, outputs adversarial perturbations, and constructs fake image samples; the generator model constructed in this step introduces a self-attention mechanism in the structure of the generator model compared to the previous generator model, which can capture the long-distance dependencies and high-dimensional features of the latent space and improve the concealment of the adversarial samples. The specific construction details and parameters are described as follows.

[0069] The generator model structure is as follows Figure 1 As shown in the figure, it includes an input layer, five convolutional layers (Conv-2D 1, Conv-2D 2, Conv-2D 3, Conv-2D 4, and Conv-2D 5), a residual connection module Residual Block, two self-attention layers (Self-Attention Layer1 and Self-Attention Layer2), and three deconvolution layers (DeConv-2D 1, DeConv-2D 2, DeConv-2D 3). The convolution layer extracts input features and captures long-distance dependencies and high-dimensional features in the latent space through the self-attention layer to improve the authenticity of the generated adversarial samples. The residual connection module Residual Block helps alleviate the gradient vanishing problem and enhances the learning ability of the network. Finally, the deconvolution layer restores the image to its original spatial resolution.

[0070] Specifically, the mapping process from the convolutional feature map to the self-attention feature map is as follows: Figure 3 As shown, for the convolutional feature map X=(x1,x2,x3,...,x n ), X∈R C×N, where C and N are the number of channels and feature positions of the input feature map, respectively. First, a 1x1 convolution kernel is used to linearly transform the values ​​of the C channels of each pixel, transforming the image features into two feature spaces f and g. Where f(x) = W f x,g(x)=W g x, transpose the feature operation output of the i-th position and multiply it with the feature space output of the j-th position, and then normalize it to get the attention weight between the two positions. The specific process of capturing global dependencies can be expressed as:

[0071]

[0072] In the formula, β j,i It represents the degree of dependence of the model on the i-th position in the process of synthesizing the j-th region of the image under the self-attention framework. After the above operation, the attention map is obtained, multiplied by the feature map in the feature space h, and then passed through the weight matrix W v The final output is O = (O1, O2, ..., O j ,...,O N ),in:

[0073]

[0074] W in the above formula h and W v is the weight matrix obtained by 1x1 convolution kernel operation, and is continuously optimized and learned as the network is trained. In order to improve memory usage efficiency, a strategy of reducing the number of channels was adopted in the experiment, reducing the number of channels of the intermediate weight matrix to one eighth of the original number of channels. j Multiplying with a learnable scalar and superimposing the original input feature map results in a feature map that incorporates attention:

[0075] y i =λO i +x i

[0076] Table 1 specifically gives the convolution kernel size, stride and other parameter information of each convolution layer and self-attention layer.

[0077] Table 1 Generator model parameter structure

[0078]

[0079] A multi-convolution discriminator model is constructed to judge the authenticity of original samples and synthetic samples; the multi-convolution discriminator model constructed in this embodiment is composed of four stacked convolutional layers, and the probability of the output sample being true is normalized by the Sigmoid function in the last layer of the network. The structure and processing flow of each layer are now described in detail.

[0080] The multi-convolution discriminator model structure is as follows Figure 2 As shown in the figure, it contains the input layer Input Layer, whose sources include data samples generated by the generator and original data samples. As well as four convolutional layers (Conv-2D 1, Conv-2D 2, Conv-2D 3 and Conv-2D 4), batch normalization technology is used to accelerate the convergence speed during deep network training and improve training stability. LeakyReLU is used as the activation function to introduce nonlinear features. Conv-2D 1 is mainly responsible for extracting basic features such as texture and edge of the input data; the convolutional layer Conv-2D 2 further extracts complex features such as shape information in a larger range based on the basic features extracted by the first layer; after completing the basic feature extraction of the first two layers, Conv-2D 3 focuses on more complex and abstract feature information, such as the features of eyes and noses in facial recognition, and the model begins to understand certain specific content in the image; the last layer of convolution Conv-2D 4 integrates all the extracted feature information to form a comprehensive understanding of the input data and judge its true or false.

[0081] Table 2 gives the convolution kernel size, stride and other parameter information of each layer of the multi-convolution discriminator model.

[0082] Table 2 Multi-convolution discriminator model parameter structure

[0083]

[0084] A loss function is designed. Under the guidance of the loss function, the generator model and the multi-convolution discriminator model are alternately optimized and adversarially trained using the training data set to finally reach a performance balance. When the performance of the generator model and the multi-convolution discriminator model reaches a dynamic balance, the trained generator model is saved. The loss function designed in this embodiment includes: misjudgment loss, adversarial loss and hinge loss. Among them, the misjudgment loss is used to guide the generator model to train in the direction of synthetic adversarial samples; the adversarial loss is used to maintain a dynamic balance between the performance of the generator and the discriminator; the hinge loss is used to limit the size of the adversarial perturbation output by the generator model.

[0085] The loss function design and parameter setting during training are now explained in detail.

[0086] The loss function includes the misclassification loss L of the supervised generator adv , hinge loss L that constrains the perturbation size hinge, and the adversarial loss L of the entire GAN GAN , :

[0087] L=L adv +αL GAN +βL hinge

[0088] Among them, α and β are hyperparameters used to control the importance of different types of losses in the framework. The GAN model focuses on multiple optimization objectives during training. GAN Encourage the data distribution generated by the generator to be similar to the original data distribution; hinge loss L hinge Limit the size of the noise and stabilize the training of GAN; misjudgment loss L adv Make the generator generate in the direction of counteracting disturbance.

[0089] The specific adversarial loss is expressed as:

[0090] L adv =E x λ f (x+G(x),t)

[0091] Among them, f is the target attack model, t is the true label of the input data x, and λ f It reflects the recognition ability of the target attack model f for synthetic samples, which is specifically implemented using the cross entropy loss function.

[0092] In order to obtain adversarial samples that are close to the original samples, the hinge loss of the norm is introduced during training to impose the following restrictions on the perturbation size:

[0093] L hinge =E x max(0,||G(x)||2-c)

[0094] The constant c is the optimized boundary of the perturbation, and a greater loss is imposed on pixels that are too far from the boundary. At different stages of training, a dynamic balance between the performance of the generator and the discriminator must be maintained. If the discriminator is too powerful, it is difficult for the generator to deceive it and it will not be able to produce sufficiently realistic samples; if the generator is too powerful, it will not provide effective and sufficient incentives for the training of the discriminator. Their adversarial loss can be expressed as:

[0095] L GAN =E x logD(x)+E x log(1-D(x+G(x)))

[0096] The entire training process uses the Adam optimizer, the learning rate is set to 0.001, and the learning rate decay strategy is adopted. After 50 epochs and 80 epochs, the learning rate is set to 0.0001 and 0.00001 respectively. The batch size of all models is uniformly set to 64, the maximum number of iterations is set to 100, and the training is terminated when the performance on the validation set does not improve within 10 consecutive epochs. The α in the loss function is set to 5, and the β is set to 1 to stabilize the model training and control the proportion of the hinge loss. The parameter c of the perturbed hinge loss is set to 0.1 when minimizing the L2 norm.

[0097] Use the trained generator model to generate adversarial perturbations based on the original samples, output the adversarial perturbations through the forward propagation of the model, and then superimpose them with the original samples to obtain adversarial samples. The specific explanation is as follows:

[0098] First, select the original samples that can be correctly classified in a non-adversarial environment from the target network as a starting point. Next, load the pre-trained generator model, which is adversarially trained to produce tiny, imperceptible perturbations based on the original samples, which are enough to mislead the target network into making an incorrect judgment. The selected original samples are input into the generator model, and targeted adversarial perturbations are output.

[0099] Subsequently, the adversarial perturbation is superimposed on the original sample to generate the final adversarial sample. During the superposition process, the perturbation needs to be restricted to a certain extent to ensure that the adversarial sample is still within the valid data range. After obtaining the adversarial sample, it is input into the target classification network for verification to test whether the network can correctly identify it. If the target network is successfully misled, it means that the attack is successful and the performance of the generator model reaches the expected effect.

[0100] Finally, the vulnerability of the target model to adversarial attacks is evaluated based on the test results, and the design and optimization of security protection measures for deep learning models are further guided to enhance the robustness of the network.

Claims

1. A method for generating adversarial samples based on a self-attention mechanism, characterized by: The following steps are involved: A generator model is constructed, the generator model comprising an encoder and a decoder; the encoder comprises a first input layer, unit one, unit two, unit three and unit four which are connected in sequence; unit one is composed of a first convolutional layer, a first batch normalization layer and a first Leaky Relu layer, unit two is composed of a second convolutional layer, a second batch normalization layer and a second Leaky Relu layer, unit three is composed of a third convolutional layer, a third batch normalization layer and a third Leaky Relu layer, and unit four is composed of a fourth convolutional layer, a first self-attention layer, a fourth batch normalization layer and a fourth Leaky Relu layer; the output of unit one is connected to the output of unit three through a residual connection module; the decoder comprises a fifth unit, a sixth unit, a seventh unit and a eighth unit which are connected in sequence; unit five is composed of a fifth convolutional layer, a second self-attention layer, a fifth batch normalization layer and a fifth Leaky Relu layer, unit five is composed of a first deconvolutional layer, a sixth batch normalization layer and a sixth Leaky Relu layer, unit six is ​​composed of a second deconvolutional layer, a seventh batch normalization layer and a seventh Leaky Relu layer The Relu layer constitutes unit seven, and the third deconvolution layer, the seventh batch normalization layer and the seventh LeakyRelu layer constitute unit seven; Constructing a multi-convolution discriminator model, the multi-convolution discriminator model comprising a second input layer, a sixth convolution layer, a seventh convolution layer, an eighth convolution layer and a ninth convolution layer connected in sequence; the second input layer is used to input the original data sample and the adversarial sample generated by the generator model; Designing a loss function, wherein the loss function is composed of a misjudgment loss function, an adversarial loss function, and a hinge loss function; the misjudgment loss function is used to guide the generator model to train in the direction of adversarial samples, the adversarial loss function is used to maintain a dynamic balance between the performance of the generator and the discriminator, and the hinge loss function is used to limit the adversarial perturbation size output by the generator model; Under the guidance of the loss function, the training data set is used to alternately optimize the generator model and the multi-convolution discriminator model, and adversarial training is performed. After the performance of the final generator model and the multi-convolution discriminator model reaches a dynamic balance, the trained generator model is saved; The original sample is input into the trained generator model to generate adversarial perturbations, and the generated adversarial perturbations are superimposed on the original sample to obtain adversarial samples.

2. The method for generating adversarial samples based on the self-attention mechanism according to claim 1, characterized in that: The mapping process from the convolution feature map output by the convolution layer to the self-attention feature map output by the self-attention layer is expressed as: The convolution feature map output by the convolution layer is X = (x1, x2, x3, ..., x n ), X∈R C×N , where C and N are the number of channels and feature positions of the input feature map respectively; First, a convolution kernel of size 1x1 is used to linearly transform the values ​​of the C channels of each pixel, and the image features are transformed into two feature spaces f and g respectively, where f(x) = W f x,g(x)=W g x, transpose the feature operation output of the i-th position and multiply it with the feature space output of the j-th position, and then normalize it to get the attention weight between the two positions, which is specifically expressed as: In the formula, β j,i Indicates the degree of dependence of the model on the i-th position in the process of synthesizing the j-th region of the image under the self-attention framework; s ij Represents the weight between the i-th position and the j-th position in the image; After the above operation, we get the attention map, which is multiplied by the feature map in the feature space h, and then passed through the weight matrix W v The final output is O = (O1, O2, ..., O j ,...,O N ),in: Where W h and W v is the weight matrix obtained by 1x1 convolution kernel operation, v represents the weight matrix of x i Using the weight matrix W v The transformation operation performed, h(x i ) represents x i Through the weight matrix W h The transformed value; Finally, O j Multiplying by a learnable scalar λ and superimposing the original input feature map, we get the feature map that incorporates attention: y i =λO i +x i 。 3. The method for generating adversarial samples based on the self-attention mechanism according to claim 1, characterized in that: The misjudgment loss function is expressed as: L adv =E x λ f (x+G(x),t) Among them, f is the target attack model, t is the true label of the input data x, and λ f It reflects the recognition ability of the target attack model f on the synthetic samples, E x It represents the expected value of the input data x, and G(x) represents the adversarial perturbation generated by the generator model.

4. The method for generating adversarial samples based on the self-attention mechanism according to claim 1, characterized in that: The adversarial loss function is expressed as: L GAN =E x logD(x)+E x log(1-D(x+G(x))) Among them, E x represents the expected value of the input data x, G(x) represents the adversarial perturbation generated by the generator model, and D(x) represents the probability that the discriminator model judges that the sample is true.

5. The method for generating adversarial samples based on the self-attention mechanism according to claim 1, characterized in that: The hinge loss function is expressed as: L hinge =E x max(0,||G(x)||2-c) Among them, the constant c is the optimization boundary of the perturbation, G(x) represents the adversarial perturbation generated by the generator model, and ||·||2 represents the l2 norm of the adversarial perturbation.

6. A system for generating adversarial samples based on a self-attention mechanism, characterized in that: include: The trained generator model is used to generate adversarial perturbations of the original samples; The adversarial sample generation module is used to superimpose the generated adversarial perturbation with the original sample to obtain the adversarial sample; The trained generator model is obtained by following the steps below: A generator model is constructed, the generator model comprising an encoder and a decoder; the encoder comprises a first input layer, unit one, unit two, unit three and unit four which are connected in sequence; unit one is composed of a first convolutional layer, a first batch normalization layer and a first Leaky Relu layer, unit two is composed of a second convolutional layer, a second batch normalization layer and a second Leaky Relu layer, unit three is composed of a third convolutional layer, a third batch normalization layer and a third Leaky Relu layer, and unit four is composed of a fourth convolutional layer, a first self-attention layer, a fourth batch normalization layer and a fourth Leaky Relu layer; the output of unit one is connected to the output of unit three through a residual connection module; the decoder comprises a fifth unit, a sixth unit, a seventh unit and a eighth unit which are connected in sequence; unit five is composed of a fifth convolutional layer, a second self-attention layer, a fifth batch normalization layer and a fifth Leaky Relu layer, unit five is composed of a first deconvolutional layer, a sixth batch normalization layer and a sixth Leaky Relu layer, unit six is ​​composed of a second deconvolutional layer, a seventh batch normalization layer and a seventh Leaky Relu layer The Relu layer constitutes unit seven, and the third deconvolution layer, the seventh batch normalization layer and the seventh LeakyRelu layer constitute unit seven; Constructing a multi-convolution discriminator model, the multi-convolution discriminator model comprising a second input layer, a sixth convolution layer, a seventh convolution layer, an eighth convolution layer and a ninth convolution layer connected in sequence; the second input layer is used to input the original data sample and the adversarial sample generated by the generator model; Designing a loss function, wherein the loss function is composed of a misjudgment loss function, an adversarial loss function, and a hinge loss function; the misjudgment loss function is used to guide the generator model to train in the direction of adversarial samples, the adversarial loss function is used to maintain a dynamic balance between the performance of the generator and the discriminator, and the hinge loss function is used to limit the adversarial perturbation size output by the generator model; Under the guidance of the loss function, the training data set is used to alternately optimize the generator model and the multi-convolution discriminator model, and conduct adversarial training. Finally, when the performance of the generator model and the multi-convolution discriminator model reaches a dynamic balance, the trained generator model is obtained.

7. The adversarial sample generation system based on the self-attention mechanism according to claim 6, characterized in that: The mapping process from the convolution feature map output by the convolution layer to the self-attention feature map output by the self-attention layer is expressed as: The convolution feature map output by the convolution layer is X = (x1, x2, x3, ..., x n ), X∈R C×N , where C and N are the number of channels and feature positions of the input feature map respectively; First, a convolution kernel of size 1x1 is used to linearly transform the values ​​of the C channels of each pixel, and the image features are transformed into two feature spaces f and g respectively, where f(x) = W f x,g(x)=W g x, transpose the feature operation output of the i-th position and multiply it with the feature space output of the j-th position, and then normalize it to get the attention weight between the two positions, which is specifically expressed as: In the formula, β j,i Indicates the degree of dependence of the model on the i-th position in the process of synthesizing the j-th region of the image under the self-attention framework; s ij Represents the weight between the i-th position and the j-th position in the image; After the above operation, we get the attention map, which is multiplied by the feature map in the feature space h, and then passed through the weight matrix W v The final output is O = (O1, O2, ..., O j ,...,O N ),in: Where W h and W v is the weight matrix obtained by 1x1 convolution kernel operation, v represents the weight matrix of x i Using the weight matrix W v The transformation operation performed, h(x i ) represents x i Through the weight matrix W h The transformed value; Finally, O j Multiplying by a learnable scalar λ and superimposing the original input feature map, we get the feature map that incorporates attention: y i =λO i +x i 。 8. The adversarial sample generation system based on the self-attention mechanism according to claim 6, characterized in that: The misjudgment loss function is expressed as: L adv =E x λ f (x+G(x),t) Among them, f is the target attack model, t is the true label of the input data x, and λ f It reflects the recognition ability of the target attack model f on the synthetic samples, E x It represents the expected value of the input data x, and G(x) represents the adversarial perturbation generated by the generator model.

9. The adversarial sample generation system based on the self-attention mechanism according to claim 6, characterized in that: The adversarial loss function is expressed as: L GAN =E x logD(x)+E x log(1-D(x+G(x))) Among them, E x It represents the expected value of the input data x, G(x) represents the adversarial perturbation generated by the generator model, and D(x) represents the probability that the discriminator model judges that the sample is true.

10. The adversarial sample generation system based on the self-attention mechanism according to claim 6, characterized in that: The hinge loss function is expressed as: L hinge =E x max(0,||G(x)||2-c) Among them, the constant c is the optimization boundary of the perturbation, G(x) represents the adversarial perturbation generated by the generator model, and ||·||2 represents the l2 norm of the adversarial perturbation.

Citation Information

Patent Citations

  • An image copy detection method based on generative adversarial networks

    CN109543674A

  • Adversarial sample generation method based on generative adversarial network

    CN110334806A

  • Image processing method and system and computer storage medium

    CN112085677A