An adversarial sample generation method based on gradient sampling mask matrix
By generating a masking matrix to mask the encoder and decoder inputs of the self-attention architecture model, the problem of adversarial example overfitting in the self-attention architecture object detection model is solved, enabling effective attacks across model architectures, reducing the cost of black-box attacks, and improving the transferability of adversarial examples and the robustness of the model.
Patent Information
- Application Number
- CN202410222223.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-28
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2044-02-28
AI Technical Summary
Existing adversarial attack generation methods based on self-attention architecture target detection models result in adversarial examples overfitting to the self-attention architecture, failing to effectively transfer across model architectures, and increasing the cost of black-box attacks.
A gradient sampling masking matrix-based approach is adopted to mask the encoder and decoder inputs of the self-attention architecture model by generating a masking matrix, thereby preventing overfitting of adversarial examples and improving the generalization and transferability of adversarial examples. The specific steps include generating the masking matrix and iteratively optimizing it by combining gradient values.
It achieves good attack performance on both self-attention architecture and convolutional architecture object detection models, reduces the cost of black-box attacks, and improves the transferability of adversarial examples and the robustness of the model.
Smart Images

Figure CN118038022B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer vision, specifically to the field of adversarial machine learning, and to a method for generating adversarial examples based on gradient sampling masking matrices. Background Technology
[0002] In recent years, with the continuous advancement of deep learning technology and hardware computing power, computer vision has made groundbreaking progress, demonstrating near-human or even surpassing performance in many tasks. Object detection, as one of the tasks in computer vision, has been widely applied in autonomous driving, intelligent monitoring, and medical diagnosis. However, the field of object detection still faces many unresolved problems and security vulnerabilities, the most prominent of which is the adversarial example problem. Adversarial examples are security vulnerabilities in deep learning models. Attackers can add subtle noise to the model's input, causing it to produce incorrect inputs. Furthermore, adversarial examples are highly covert, making them difficult for humans to detect. Mainstream object detection models are divided into two types: those based on convolutional neural networks and those based on self-attention networks. Extensive research has been conducted to address the attack and defense issues of these models, promoting the development of security and reliability in object detection.
[0003] In black-box attacks, attackers cannot know the specific structure of the target model. To improve the transferability of adversarial examples, attackers commonly employ ensemble modeling, combining multiple models as the source model to enhance the generalization of adversarial examples and thus increase the success rate of black-box attacks. However, with the development of object detection tasks, especially the architectural innovation of self-attention architecture models, various object detection models with different structures have been proposed. Integrating models with various structures will rapidly increase the cost of black-box attacks, and adversarial examples generated by existing adversarial attack methods cannot be transferred between heterogeneous models.
[0004] Therefore, it is necessary to use only a self-attention architecture object detection model as the source model to generate adversarial examples, which can realize black-box attacks across model architectures. It has good transferability on both self-attention architecture-based and convolutional architecture-based object detection models, reducing the cost of black-box attacks, so as to test the robustness of object detection. Summary of the Invention
[0005] How to effectively attack convolutional-based target detection models with adversarial examples generated on self-attention architecture target detection models, and improve the transferability of adversarial examples, is the technical problem to be solved by this invention.
[0006] Existing adversarial attack generation methods based on self-attention architecture object detection models over-exploit the information of the self-attention architecture, leading to overfitting of adversarial examples. To avoid this overfitting, a masking matrix is generated for each encoder and decoder input of the self-attention architecture model, incorporating the idea of dropout. This discards some feature information from the input, thereby improving the generalization and transferability of adversarial examples. The key to achieving this effect lies in determining which features to discard, i.e., how to generate the masking matrix. Therefore, during backpropagation, the gradients of each encoder and decoder input are retained, and a masking matrix is generated based on the gradient values for use in the next iteration. This method is named Gradient Sampling Mask Attack (GSMA).
[0007] like Figure 1 As shown, the specific steps of the adversarial example generation method based on gradient sampling masking matrix are as follows: Step 1: Using a self-attention architecture object detection model as the source model F, input sample images. The feature extraction network f is used to extract features from the input image. ; The output of the model in the first iteration is: ; Step 2: Use perturbation threshold of norm The loss function is defined as follows for backpropagation: ; Step 3: During the backpropagation process, retain each input. absolute value of gradient , respectively Calculate the average of all elements in the equation. ; Step 4: with and The probability values used for classification distribution are used to generate the masking matrix after one sampling. ; Since the occlusion matrix is generated by sampling, its value is not the same in each iteration; in the occlusion matrix In the generated masking matrix, locations with larger absolute gradient values have a higher probability of being 0, while locations with smaller absolute gradient values have a higher probability of being 1. and Combined to obtain The input to the encoder and decoder is expressed as follows: ; Step 5: Through the feedforward network Get output The model, after incorporating the shading matrix, can be expressed as: ; Step 6: Obtain the results of this iteration and generate the occlusion matrix for the next iteration. ; Step 6.1: Obtain the gradient value ,in As the attenuation factor, Represents the gradient value during backpropagation; Step 6.2: Obtain adversarial examples Where α represents the step size for each update, The function truncates pixels in adversarial samples that exceed the threshold ∈, where sign represents the sign function; Step 6.3: Obtain the occlusion matrix ; Step 7: Analyze the adversarial examples from this iteration. and gradient value and occlusion matrix As input for the next iteration; Step 8: Repeat steps 4 to 7 for T iterations; obtain the adversarial example after the last iteration. .
[0008] The beneficial effects of the method described in this invention are that it exhibits better attack performance in black-box attacks on both convolutional and self-attention architecture-based object detection models. Specifically, by using a self-attention architecture object detection model as the source model and combining the GSMA method with existing methods, the success rate of existing methods in attacking black-box convolutional architecture object detection models can be improved, further reducing the mAP of black-box models. GSMA, by masking part of the output of each encoder and decoder in the self-attention architecture model, realizes adversarial examples generated only on a single model, enabling cross-model architecture attacks on convolutional architecture-based object detection models, effectively reducing the cost of black-box attacks. Attached Figure Description
[0009] Figure 1 This is a flowchart of the adversarial example generation method based on gradient sampling masking matrix described in this invention; Figure 2 This is the Faster R-CNN detection result and gradient heatmap described in this invention. Detailed Implementation
[0010] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0011] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0012] This invention uses only one self-attention architecture object detection model as the source model to generate adversarial examples. Specifically, it retains the gradients of each encoder and decoder input and generates a masking matrix based on the gradient values for use in the next iteration. This prevents adversarial examples from overfitting the self-attention architecture object detection model, thereby achieving black-box attacks across model architectures. It has good transferability on both self-attention architecture-based and convolutional architecture-based object detection models, reducing the cost of black-box attacks and enabling testing of the robustness of object detection.
[0013] Parameter settings: The model has 6 encoder layers and 6 decoder layers; the input image size is adjusted to 800×800; pixel values are normalized; all attack methods are employed. Norm constraints, threshold Maximum number of iterations T=50, attack step size The target model is Faster R-CNN. BIM, MI-FGSM, DI-FGSM, and TI-FGSM are selected as baseline attack methods, and DSEA is combined to enhance the attack effect on self-attention architectures. The specific process is as follows: Step 1: Using a self-attention architecture object detection model as the source model F, input sample images. The feature extraction network f is used to extract features from the input image. ; Step 2: Use The perturbation threshold of the norm is defined as follows: The loss function is defined as follows for backpropagation: .
[0014] Step 3: During the backpropagation process, retain each input. absolute value of gradient , respectively Calculate the average of all elements in the equation. ; Step 4: with and The probability values used for classification distribution are used to generate the masking matrix after one sampling. ; Since the occlusion matrix is generated by sampling, its value is not the same in each iteration; in the occlusion matrix In the generated masking matrix, locations with larger absolute gradient values have a higher probability of being 0, while locations with smaller absolute gradient values have a higher probability of being 1. and Combined to obtain The input to the encoder and decoder is expressed as follows: ; Step 5: Through the feedforward network Get output The model, after incorporating the shading matrix, can be expressed as: ; S6: Obtain the results of this iteration and generate the occlusion matrix for the next iteration. ; Step 6.1: Obtain the gradient value ,in As the attenuation factor, This represents the gradient value during backpropagation; Step 6.2: Obtain adversarial examples Where α represents the step size for each update, The function truncates pixels in adversarial samples that exceed the threshold ∈, where sign represents the sign function; Step 6.3: Obtain the occlusion matrix ; Step 7: Analyze the adversarial examples from this iteration. and gradient value and occlusion matrix As input for the next iteration; The detection results and gradient heatmaps on Faster R-CNN are presented for clean samples, adversarial samples generated by four attack methods, adversarial samples generated by combining the DSEA method, and adversarial samples generated by combining the GSMA method. (See attached image.) Figure 2 As shown in the images in the first and third columns, under the same confidence threshold setting, existing methods, combined with the adversarial examples generated by GSMA, can hide more objects, making them unrecognizable by the Faster R-CNN model. (See attached image) Figure 2As shown in the first column of images, Faster R-CNN can identify people and horses using adversarial examples generated by DI-FGSM. However, adversarial examples generated by DIFGSM+DSEA actually enable Faster R-CNN to identify more objects, including people, horses, and vehicles. But adversarial examples generated by GSMA only allow Faster R-CNN to identify a horse. This demonstrates that the GSMA method effectively reduces the confidence level of objects, making them unrecognizable by convolutional-based object detection models.
[0015] As attached Figure 2 The gradient heatmaps in columns two and four show that the red areas represent the regions the model focuses on. In existing methods and adversarial examples generated by the DSEA method, the red areas in the gradient heatmaps are mainly concentrated on the objects within the predicted bounding boxes, indicating that the model still focuses on the main objects in the predicted boxes. However, in adversarial examples generated by the GSMA method, the red areas in the gradient heatmaps are more dispersed and more concentrated in the background region, indicating that the model is no longer able to focus on the correct object regions, is affected by the noise of the adversarial examples, and is unable to capture the features of the objects. (See attached image) Figure 2 The gradient heatmaps in the second and third rows show adversarial examples generated by the MI-FGSM and MI-FGSM+DSEA methods. The red areas in the gradient heatmaps are concentrated within the objects in the prediction boxes, indicating that the model correctly identifies the features of people and horses, resulting in no change in the prediction results. (See attached image.) Figure 2 As shown in the gradient heatmap in the fourth row, the adversarial example generated after combining the GSMA method shows that the red areas of the gradient heatmap are scattered around the objects in the predicted bounding box. The model focuses more on the background, thus only recognizing the horse. This indicates that the GSMA method can effectively interfere with convolutional architecture-based object detection models, preventing them from correctly recognizing image features and leading to reduced recognition accuracy.
[0016] Test results show that the GSMA method proposed in this invention has better attack performance in black-box attacks on object detection models based on convolutional and self-attention architectures. It enables adversarial examples generated only on a single model to attack convolutional object detection models across different model architectures, effectively reducing the cost of black-box attacks.
[0017] It should be noted that this embodiment uses 6 encoder layers and 6 decoder layers. This does not mean that it can only be used with 6 encoder layers and 6 decoder layers. It is just an example for detailed explanation. It is applicable to n encoder layers and n decoder layers, where n is greater than 2.
[0018] The innovation of this invention lies in sampling the gradient of the model to mask part of the input of each encoder and decoder in the self-attention architecture model, preventing overfitting of adversarial examples and improving the transferability of adversarial examples to heterogeneous object detection models. The GSMA method proposed in this invention exhibits better attack performance in black-box attacks on object detection models based on both convolutional and self-attention architectures. Specifically, by using a self-attention architecture object detection model as the source model and combining the GSMA method with existing methods, the success rate of existing methods in attacking black-box convolutional architecture object detection models can be improved, further reducing the mAP of black-box models. By masking part of the output of each encoder and decoder in the self-attention architecture model, GSMA enables adversarial examples generated only on a single model, allowing cross-model architecture attacks on convolutional architecture-based object detection models, effectively reducing the cost of black-box attacks.
[0019] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely preferred examples and are not intended to limit the invention. Various changes and modifications can be made to the invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the present invention as claimed. The scope of protection of the present invention is defined by the appended claims and their equivalents.
Claims
1. An adversarial example generation method based on gradient sampling masking matrix, which is used for robustness testing of target detection models under legal conditions, characterized in that: The specific steps of the adversarial example generation method are as follows: Step 1: Using a self-attention architecture object detection model as the source model F, input sample images. The feature extraction network f is used to extract features from the input image. ; The output of the model in the first iteration is: ; Step 2: Use perturbation threshold of norm The loss function is defined as follows for backpropagation: ; Step 3: During the backpropagation process, retain each input. absolute value of gradient , respectively Calculate the average of all elements in the equation. ; Step 4: with and The probability values used for classification distribution are used to generate the masking matrix after one sampling. ; Since the occlusion matrix is generated by sampling, its value is not the same in each iteration; in the occlusion matrix In the generated masking matrix, locations with larger absolute gradient values have a higher probability of being 0, while locations with smaller absolute gradient values have a higher probability of being 1. and Combined to obtain The input to the encoder and decoder is expressed as follows: ; Step 5: Through the feedforward network Get output The model, after incorporating the shading matrix, can be expressed as: ; Step 6: Obtain the results of this iteration and generate the occlusion matrix for the next iteration. ; Step 7: Analyze the adversarial examples from this iteration. and gradient value and occlusion matrix As input for the next iteration; Step 8: Repeat steps 4 to 7 for T iterations; obtain the adversarial example after the last iteration. .
2. The adversarial example generation method based on gradient sampling masking matrix as described in claim 1, characterized in that: In step 6, the occlusion matrix is obtained. The specific steps are as follows: Obtain gradient values ,in As the attenuation factor, Represents the gradient value during backpropagation; Obtain adversarial examples Where α represents the step size for each update, The function truncates pixels in adversarial samples that exceed the threshold ∈, where sign represents the sign function; Obtain the occlusion matrix .
